Skip to content

Get declaration diagnostics in LSP #1000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2025
Merged

Get declaration diagnostics in LSP #1000

merged 3 commits into from
Jun 5, 2025

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented May 30, 2025

The server also has to ask for these if enabled.

Arguably, these should just get moved into semantic diagnostics, but...

(Maybe this is too buggy/slow to expose in the editor at the moment?

@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 21:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors how diagnostics are aggregated in the LSP endpoint and adds support for declaration diagnostics when emitDeclarations is enabled.

  • Consolidates syntactic, semantic, suggestion, and optional declaration diagnostics into a unified helper.
  • Introduces toLSPDiagnostics to flatten multiple diagnostic slices.
  • Adds a conditional branch to include declaration diagnostics based on server options.
Comments suppressed due to low confidence (1)

internal/ls/diagnostics.go:22

  • New behavior for declaration diagnostics is gated by emitDeclarations. Consider adding or updating tests to cover both enabled and disabled states to ensure correct inclusion/exclusion.
if program.Options().GetEmitDeclarations() {

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, these should just get moved into semantic diagnostics, but...

Eh, they're calculated in a separate pass (basically by doing the emit), so having them separate can be nice for callers that don't really care about them (or are already doing emit and can just pull the diagnostics from the emit step). There's no error category distinction in the editor really, though, you're right.

@jakebailey
Copy link
Member Author

Do we think declaration diagnostics are stable enough to merge this, or should we wait until more of the module / module specifier code is in?

@andrewbranch
Copy link
Member

#1051 pretty much finishes it out

@jakebailey jakebailey requested a review from weswigham June 4, 2025 23:25
@jakebailey jakebailey enabled auto-merge June 4, 2025 23:32
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, program no longer has a diagnostic caching layer itself, so GetDeclarationDiagnostics will actually fully recalculate them on every call. Not sure if that needs to be cached somewhere or not.

@jakebailey jakebailey added this pull request to the merge queue Jun 4, 2025
Merged via the queue into main with commit c830924 Jun 5, 2025
23 checks passed
@jakebailey jakebailey deleted the jabaile/lsp-decl-diags branch June 5, 2025 00:05
@jakebailey
Copy link
Member Author

That's true but I think all callers all call once so it might be okay for now. I'll look into doing caching after

@jakebailey
Copy link
Member Author

Sent: #1058

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants