Skip to content

Expose non-primary spans from diagnostic#659

Draft
stefanvanburen wants to merge 2 commits intomainfrom
svanburen/diagnostic-non-primary-spans
Draft

Expose non-primary spans from diagnostic#659
stefanvanburen wants to merge 2 commits intomainfrom
svanburen/diagnostic-non-primary-spans

Conversation

@stefanvanburen
Copy link
Member

We currently don't have a way to access non-primary spans from a diagnostic. This adds a NonPrimary API that returns the slice of non-primary spans from the diagnostic.

This can be used by the LSP to populate the protocol.Diagnostic's RelatedInformation field that references the other spans relating to this diagnostic.

No particular love for this name; I thought about Secondary but that didn't seem right either. Open to suggestions.

We currently don't have a way to access non-primary spans from
a diagnostic. This adds a `NonPrimary` API that returns the slice of
non-primary spans from the diagnostic.

This can be used by the LSP to populate the [protocol.Diagnostic][1]'s
RelatedInformation field that references the other spans relating to
this diagnostic.

No particular love for this name; I thought about `Secondary` but that
didn't seem right either. Open to suggestions.

[1]: https://pkg.go.dev/go.lsp.dev/protocol#Diagnostic
stefanvanburen added a commit to bufbuild/buf that referenced this pull request Jan 30, 2026
Also removes the diagnostic.Data from the new diagnostics, which AFAICS
is unused; we can save ourselves the json marshaling.

As a part of this, added a first pass at adding tests for diagnostics
- we don't currently have any. These are a bit different because we
haven't implemented [PullDiagnostics][1] (we can add this, but we'd need
a custom implementation, or wait until [go.lsp.dev upgrades to
3.17][2]). Instead, we intercept the notifications from the
server. Lastly, since we don't actually want the tests to wait around,
adds synctest and only runs the tests on Go 1.25 for now (1.26 should be
released next month and we'll be able to upgrade to 1.25 as our
minimum).

This is in preparation to eventually landing relatedInformation (other
spans) in diagnostics, from bufbuild/protocompile#659.

[1]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics
[2]: go-language-server/protocol#52
stefanvanburen added a commit to bufbuild/buf that referenced this pull request Jan 30, 2026
Also removes the diagnostic.Data from the new diagnostics, which AFAICS
is unused; we can save ourselves the json marshaling.

As a part of this, added a first pass at adding tests for diagnostics
- we don't currently have any. These are a bit different because we
haven't implemented [PullDiagnostics][1] (we can add this, but we'd need
a custom implementation, or wait until [go.lsp.dev upgrades to
3.17][2]). Instead, we intercept the notifications from the
server. Lastly, since we don't actually want the tests to wait around,
adds synctest and only runs the tests on Go 1.25 for now (1.26 should be
released next month and we'll be able to upgrade to 1.25 as our
minimum).

This is in preparation to eventually landing relatedInformation (other
spans) in diagnostics, from bufbuild/protocompile#659.

[1]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics
[2]: go-language-server/protocol#52
stefanvanburen added a commit to bufbuild/buf that referenced this pull request Jan 30, 2026
Also removes the diagnostic.Data from the new diagnostics, which AFAICS
is unused; we can save ourselves the json marshaling.

As a part of this, added a first pass at adding tests for diagnostics;
we don't currently have any. These are a bit different because we
haven't implemented [PullDiagnostics][1] (we can add this, but we'd need
a custom implementation, or wait until [go.lsp.dev upgrades to
3.17][2]). Instead, we intercept the notifications from the
server. Lastly, since we don't actually want the tests to wait around,
adds synctest and only runs the tests on Go 1.25 for now (1.26 should be
released next month and we'll be able to upgrade to 1.25 as our
minimum).

This is in preparation to eventually landing relatedInformation (other
spans) in diagnostics, from bufbuild/protocompile#659.

Also pulls in the latest protocompile@main to bring in the new
deprecated tag.

[1]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics
[2]: go-language-server/protocol#52
@stefanvanburen
Copy link
Member Author

Looking at the usage of this and I don't think this is quite the API we want; ideally we'd get the entire snippet, not just the span, so that when we're adding RelatedInformation we can populate the Message field.

e.g., with deprecated, we want both "%s" is deprecated and "deprecated here" messages, at their individual spans.

report.Message("`%s` is deprecated", e.name),
report.Snippet(e.ref),
report.Snippetf(e.cause, "deprecated here"),

stefanvanburen added a commit to bufbuild/buf that referenced this pull request Jan 30, 2026
Not quite right; we need the message here for the related spans.

Ref: bufbuild/protocompile#659
@stefanvanburen stefanvanburen marked this pull request as draft February 3, 2026 16:18
@stefanvanburen
Copy link
Member Author

parking this for now as a reference; chatted with @doriable and I think what would make more sense is to expose the proto representation of the report (although it looks like this is already done; we may just need to change our usage upstream to use that).

stefanvanburen added a commit to bufbuild/buf that referenced this pull request Feb 3, 2026
Also removes the diagnostic.Data from the new diagnostics, which AFAICS
is unused; we can save ourselves the json marshaling.

As a part of this, added a first pass at adding tests for diagnostics;
we don't currently have any. These are a bit different because we
haven't implemented [PullDiagnostics][1] (we can add this, but we'd need
a custom implementation, or wait until [go.lsp.dev upgrades to
3.17][2]). Instead, we intercept the notifications from the
server. Lastly, since we don't actually want the tests to wait around,
adds synctest and only runs the tests on Go 1.25 for now (1.26 should be
released next month and we'll be able to upgrade to 1.25 as our
minimum).

This is in preparation to eventually landing relatedInformation (other
spans) in diagnostics, from bufbuild/protocompile#659.

Also pulls in the latest protocompile@main to bring in the new
deprecated tag.

[1]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics
[2]: go-language-server/protocol#52
@stefanvanburen
Copy link
Member Author

expose the proto representation of the report (although it looks like this is already done

ah, yeah, not exposed because it's in an internal package, and ToProto just returns a proto.Message.

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.

2 participants