Skip to content

Add boilerplate for pull-model diagnostics #743

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 1 commit into from
May 4, 2023
Merged

Add boilerplate for pull-model diagnostics #743

merged 1 commit into from
May 4, 2023

Conversation

tristanlabelle
Copy link
Contributor

@tristanlabelle tristanlabelle commented May 3, 2023

Adds the capabilities, options and registration structs for pull-model diagnostics. I kept SwiftLanguageServer.initializeSync not reporting support for pull request diagnostics yet, so change currently has no impact.

Related to #500

How tested

  • Locally added the snippet to report support for pull request diagnostics in SwiftLanguageServer.initializeSync, then built, ran locally in VS Code and confirmed that I could get a dummy diagnostic shown in VS Code.
  • Then removed the feature reporting snippet (the state of the code in this PR), rebuilt, reran in VS Code, and confirmed that publishDiagnostics still work.

(sourcekit-lsp tests currently don't build on Windows and I don't have a mac machine handy)

@tristanlabelle
Copy link
Contributor Author

@ahoppen You mentioned that support for pull diagnostic requests already exists in sourcekit. Any pointers on how to get to that data from the dummy SwiftLanguageServer.documentDiagnostic function?

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

LGTM. I really wonder how I missed all of this when updating the definitions to LSP 3.17 🤔

dict["workspaceDiagnostics"] = .bool(diagnosticOptions.workspaceDiagnostics)
if let workDoneProgress = diagnosticOptions.workDoneProgress {
dict["workDoneProgress"] = .bool(workDoneProgress)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think you also need to encode documentSelector (from TextDocumentRegistrationOptions in the LSP spec) and id (from StaticRegistrationOptions in the LSP spec) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I couldn't get to this before the PR got merged. I will address it in my next PR when implementing the feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

documentSelector is already added to the dict by textDocumentRegistrationOptions.encodeIntoLSPAny(dict: &dict) at least.

Copy link
Member

Choose a reason for hiding this comment

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

Whoops, and I apparently approved and merged the PR, forgotting that I still had a comment. If you could create a follow-up PR, that would be great.

@ahoppen
Copy link
Member

ahoppen commented May 3, 2023

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented May 3, 2023

The main entry point where the diagnostic request is being handled in sourcekitd is here:

https://github.com/apple/swift/blob/0bdb39f51e54e959c44f3c0fea377d7d64155a51/tools/SourceKit/tools/sourcekitd/lib/Service/Requests.cpp#L1783-L1805

https://github.com/apple/swift/blob/main/test/SourceKit/Diagnostics/diags.swift has some examples of how the diagnostics request can be invoked using sourcekitd-test. You can see the raw sourcekitd request by running the test using lit with the -a option, which will print the output. In case you don’t want to do this yourself, this is what it produces for me.

{
  key.request: source.request.diagnostics,
  key.compilerargs: [
    "-module-cache-path",
    "/Users/alex/src/mbuild/Release+Asserts/swift-macosx-arm64/swift-test-results/arm64-apple-macosx10.13/clang-module-cache",
    "/Users/alex/src/swift/test/SourceKit/Diagnostics/diags.swift"
  ],
  key.sourcefile: "/Users/alex/src/swift/test/SourceKit/Diagnostics/diags.swift",
  key.primary_file: "/Users/alex/src/swift/test/SourceKit/Diagnostics/diags.swift"
}

And an example of how to send a request to sourcekitd can be found here:

https://github.com/apple/sourcekit-lsp/blob/e84b7b2b83ad4368926ca59a97c5c7484789267e/Sources/SourceKitLSP/Swift/CursorInfo.swift#L91-L106

I hope this gives you enough pointers to get started. Let me know if you need more help.

@ahoppen ahoppen merged commit 0946a78 into swiftlang:main May 4, 2023
@tristanlabelle tristanlabelle deleted the pull-diagnostics-boilerplate branch June 2, 2023 17:33
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