Expose non-primary spans from diagnostic#659
Conversation
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
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
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
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
|
Looking at the usage of this and I don't think this is quite the API we want; ideally we'd get the entire e.g., with deprecated, we want both protocompile/experimental/ir/lower_deprecated.go Lines 128 to 130 in 4035e3e |
Not quite right; we need the message here for the related spans. Ref: bufbuild/protocompile#659
|
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). |
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
ah, yeah, not exposed because it's in an internal package, and |
We currently don't have a way to access non-primary spans from a diagnostic. This adds a
NonPrimaryAPI 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
Secondarybut that didn't seem right either. Open to suggestions.