Restore original LSP diagnostic message before forwarding to server#2238
Open
NSExceptional wants to merge 1 commit into
Open
Restore original LSP diagnostic message before forwarding to server#2238NSExceptional wants to merge 1 commit into
NSExceptional wants to merge 1 commit into
Conversation
DiagnosticsManager mutates incoming LSP diagnostic messages for display (capitalizing the first letter, stripping the clangd `(fix available)` suffix). The mutated message is the one stored in the DiagnosticCollection and the one VS Code later puts into `context.diagnostics` when sending textDocument/codeAction. clangd matches diagnostics in `context.diagnostics` against its fix-it cache by `(range, message)` (see ClangdLSPServer.h `struct DiagKey`). A mutated message means the lookup misses and no quickfix is returned — visible to users as missing "Add method implementation" code actions for `-Wincomplete-implementation` warnings on Objective-C files. Stash the pre-mutation message on the diagnostic and add a `provideCodeActions` middleware that restores it before forwarding to the server. Display-side behavior is unchanged. Fixes the user-visible symptom in swiftlang/sourcekit-lsp#2186 for Objective-C quickfixes routed through clangd.
8ae6500 to
432b765
Compare
Member
|
Thank you for putting this up! My first thought is that this is a fairly complicated solution that involves mutating VS Code's diagnostic objects. Especially considering that the extension probably shouldn't even be modifying the diagnostics coming back from the compiler/LSP in the first place. Can you raise a corresponding issue with clear steps to reproduce (or ideally a sample project)? I'd like to take a closer look at this. The |
Author
|
@matthewbastien Done! Let me know if you need anything else! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DiagnosticsManagercapitalizes and strips(fix available)from incoming LSP diagnostic messages for display. That mutated message is stored in theDiagnosticCollectionand is the one VS Code subsequently puts intocontext.diagnosticsontextDocument/codeActionrequests.context.diagnosticsagainst its fix-it cache by(range, message)(ClangdLSPServer.h—struct DiagKey). A mutated message means the lookup misses and no quickfix comes back.provideCodeActionsmiddleware that restores it before forwarding. Display-side behavior is unchanged.This is the user-visible symptom in swiftlang/sourcekit-lsp#2186 (no "Add method implementation" quickfix for
-Wincomplete-implementationwarnings on Objective-C files). With this patch, the existing clangd fix-it round-trips through vscode-swift end-to-end.Repro before this PR
Project with an
@interfacedeclaring methods and an@implementationthat doesn't define all of them:Foo.h: declares-bravo:and+charlieFoo.m:@implementation Foo(alpha only)clangd publishes two
-Wincomplete-implementationwarnings. Cursor onFooin@implementation Foo, hit Cmd+. → no code actions appear. With the fix, the menu shows:- (void)bravo:(NSString *)s {…"+ (NSInteger)charlie {…"The clangd FIXME at
ClangdLSPServer.h:246-249notes that long-term clangd should switch to usingDiagnostic.data. That's being addressed separately; this PR is the immediate fix on the client side.Test plan
tsc --noEmitcleaneslintcleannpm run compilecleanDiagnosticsManager.test.ts(stashes original, no-op when nothing was mutated)Yes, I authored this with my $200 Claude plan, I hope that's okay — it is the only way I can find the time to contribute features and bug fixes to the projects I love