Skip to content

Add notification to inform SourceKit-LSP about the currently active document #1989

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
Feb 24, 2025

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Feb 19, 2025

SourceKit-LSP prepares the currently active file for editor functionality and currently infers the currently active document from whichever received the last TextDocumentRequest.

If an editor is capable of doing so, it should be able to report the document that the user currently has focused so that SourceKit-LSP does not have to infer this information from other requests.

Also clean up some handling code for experimental capabilities.

@ahoppen
Copy link
Member Author

ahoppen commented Feb 19, 2025

@swift-ci Please test

@@ -725,15 +727,16 @@ extension SourceKitLSPServer: QueueBasedMessageHandler {

logger.log("Received request \(id): \(params.forLogging)")

if let textDocumentRequest = params as? any TextDocumentRequest {
if self.capabilityRegistry?.clientHasExperimentalCapability(DidChangeActiveDocumentNotification.method) ?? false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be the reverse (ie. only infer the active document if the client doesn't support this notification)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, whoops. That’s also why the tests are failing 😉

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

LGTM modulo Ben's comment

@ahoppen ahoppen force-pushed the didchangactivedocument branch from 3875111 to 2a2e1fe Compare February 19, 2025 23:14
@ahoppen
Copy link
Member Author

ahoppen commented Feb 19, 2025

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 19, 2025

@swift-ci Please test Windows

…ocument

SourceKit-LSP prepares the currently active file for editor functionality and currently infers the currently active document from whichever received the last `TextDocumentRequest`.

If an editor is capable of doing so, it should be able to report the document that the user currently has focused so that SourceKit-LSP does not have to infer this information from other requests.

Also clean up some handling code for experimental capabilities.
@ahoppen ahoppen force-pushed the didchangactivedocument branch from 2a2e1fe to 4d00c90 Compare February 20, 2025 20:29
@ahoppen
Copy link
Member Author

ahoppen commented Feb 20, 2025

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 20, 2025

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Feb 22, 2025

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 1d1f1fb into swiftlang:main Feb 24, 2025
3 checks passed
@ahoppen ahoppen deleted the didchangactivedocument branch February 24, 2025 05:27
plemarquand added a commit to plemarquand/vscode-swift that referenced this pull request Feb 24, 2025
`sourcekit-lsp` recently added an LSP extension method to notify the
server of the active documnent, so it doesn't need to infer it from
information in other requests. This capability was added in
swiftlang/sourcekit-lsp#1989.
plemarquand added a commit to plemarquand/vscode-swift that referenced this pull request Feb 24, 2025
`sourcekit-lsp` recently added an LSP extension method to notify the
server of the active documnent, so it doesn't need to infer it from
information in other requests. This capability was added in
swiftlang/sourcekit-lsp#1989.
plemarquand added a commit to swiftlang/vscode-swift that referenced this pull request Mar 17, 2025
`sourcekit-lsp` recently added an LSP extension method to notify the
server of the active documnent, so it doesn't need to infer it from
information in other requests. This capability was added in
swiftlang/sourcekit-lsp#1989.

Co-authored-by: Alex Hoppen <[email protected]>
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.

3 participants