Skip to content
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

feat(lsp): add related_information to vim.Diagnostic #28640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tom-anders
Copy link
Contributor

@tom-anders tom-anders commented May 4, 2024

Basically a simplified version of #19649 (comment)

Looking to get some initial feedback here. Instead of just appending to the message, we might instead want to store the related info in the vim.Diagnostic struct, and then instead extend the logic in vim.diagnostic.open_float()...?

This PR:
Screenshot_2024-05-04_21-20-17
vscode:
Screenshot_2024-05-04_21-22-00

EDIT: PR now only adds the related_information field to the toplevel of vim.Diagnostic (see discussion below). We could then decide in a follow-up PR if and how we should display this to the user.

runtime/lua/vim/lsp/diagnostic.lua Outdated Show resolved Hide resolved
runtime/lua/vim/lsp/diagnostic.lua Outdated Show resolved Hide resolved
@mfussenegger mfussenegger added this to the 0.11 milestone May 4, 2024
@github-actions github-actions bot requested a review from gpanders May 4, 2024 20:59
@mfussenegger
Copy link
Member

I think instead of extending the message this should go into the structure, otherwise users can't customise this. (And I'd wager there's a bunch who don't want this in the message).

There are also actions where we send the diagnostic back to the server and I think for the server to be able to re-associate the payloads with their internal state the diagnostic mustn't change.

@tom-anders tom-anders changed the title feat(lsp): add relatedInformation to diagnostics message feat(lsp): add relatedInformation to vim.Diagnostic May 7, 2024
@tom-anders
Copy link
Contributor Author

I think instead of extending the message this should go into the structure, otherwise users can't customise this. (And I'd wager there's a bunch who don't want this in the message).

There are also actions where we send the diagnostic back to the server and I think for the server to be able to re-associate the payloads with their internal state the diagnostic mustn't change.

Sounds fair - I changed the PR so that now it only adds the relatedInformation field to the toplevel of vim.Diagnostic. We could then decide in a follow-up PR if and how we should display this to the user.

If this looks good, I'll add a test to diagnostic_spec.lua that covers this new field.

@gpanders
Copy link
Member

gpanders commented May 7, 2024

vim.Diagnostic is not an "LSP diagnostic" though, and we try very hard to avoid imposing LSP specific concepts into the (generic) diagnostic structure. In this case it is probably fine since the "related information" seems pretty generic (could be used by non-LSP diagnostic producers).

If this does need to be in the top level structure it should follow the standard naming conventions (related_information, not relatedInformation). The latter style indicates that it is a field that maps directly to some LSP concept.

@tom-anders
Copy link
Contributor Author

vim.Diagnostic is not an "LSP diagnostic" though, and we try very hard to avoid imposing LSP specific concepts into the (generic) diagnostic structure. In this case it is probably fine since the "related information" seems pretty generic (could be used by non-LSP diagnostic producers).

If this does need to be in the top level structure it should follow the standard naming conventions (related_information, not relatedInformation). The latter style indicates that it is a field that maps directly to some LSP concept.

Yeah to me this seems general enough (I could imagine something like overseer.nvim make use of this). Thanks for the hint related to naming conventions, fixed!

@tom-anders tom-anders changed the title feat(lsp): add relatedInformation to vim.Diagnostic feat(lsp): add related_information to vim.Diagnostic May 7, 2024
@tom-anders tom-anders force-pushed the diagnosticRelatedInfo branch 2 times, most recently from 27a1070 to 402b07d Compare May 8, 2024 20:42
runtime/lua/vim/lsp/diagnostic.lua Outdated Show resolved Hide resolved
runtime/lua/vim/lsp/diagnostic.lua Outdated Show resolved Hide resolved
runtime/lua/vim/lsp/diagnostic.lua Outdated Show resolved Hide resolved
@tom-anders tom-anders force-pushed the diagnosticRelatedInfo branch 2 times, most recently from 71690ab to a02d006 Compare May 10, 2024 06:57
@tom-anders
Copy link
Contributor Author

Thanks for the review! I extended the tests in lsp/diagnostic_spec.lua now.

@tom-anders tom-anders force-pushed the diagnosticRelatedInfo branch 3 times, most recently from 6c5f2ce to 5860c5a Compare May 10, 2024 07:53
--- Related message and location for a diagnostic.
--- This can be used to point to code locations that cause or are related to
--- a diagnostic, e.g when duplicating a symbol in a scope.
--- @class vim.DiagnosticRelatedInformation
Copy link
Member

Choose a reason for hiding this comment

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

How about having a namescope, like vim.diagnostic.RelatedInformation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, done

For now this just adds the field to the toplevel Diagnostic structure
and fills it with the corresponding struct from LSP.
We can decide in a follow-up if and how we should display these to the
user.
Comment on lines +274 to +275
• Add `vim.Diagnostic.related_information` field and fill it with
`lsp.DiagnosticRelatedInformation[]`. Deprecate
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
• Add `vim.Diagnostic.related_information` field and fill it with
`lsp.DiagnosticRelatedInformation[]`. Deprecate
• Add `vim.Diagnostic.related_information` field and fill it with
`vim.diagnostic.RelatedInformation[]`. Deprecate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally wrote lsp.DiagnosticRelatedInformation here though, to highlight the new logic I added in lsp/diagnostic.lua

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

Successfully merging this pull request may close these issues.

None yet

4 participants