-
Notifications
You must be signed in to change notification settings - Fork 59
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
Handle PeekDocumentsRequest
to show documents from sourcekit-lsp (like, Macro Expansions) in a "peeked" editor
#945
Handle PeekDocumentsRequest
to show documents from sourcekit-lsp (like, Macro Expansions) in a "peeked" editor
#945
Conversation
This looks great! I tried it out and expanded swift-testing's This fixes #564 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lokesh-tr this all looks good. Shocking how little code it is on the VSCode side. As Alex said in the call let's not make this macro specific and call it PeekDocument or something similar.
If we could somehow work out how to display multiple peek views this would be even better.
PeekMacroRequest
to show macro expansions in a peeked editor 🚥PeekDocumentsRequest
from sourcekit-lsp to show documents (macro expansions in particular) in a "peeked" editor
PeekDocumentsRequest
from sourcekit-lsp to show documents (macro expansions in particular) in a "peeked" editor PeekDocumentsRequest
to show documents from sourcekit-lsp (like, Macro Expansions) in a "peeked" editor
Thanks @plemarquand for testing this out. 😄 |
This is due to the fact that we didn't try to create a custom scheme and handle the fetching of documents through the scheme, etc. And, I had finished the major heavy lifting works in sourcekit-lsp side already.
I have just now pushed the code to the PR (swiftlang/sourcekit-lsp#1479) with all the necessary updates as we discussed in the call. Let's see how the review goes.
I wish that's possible. I am still trying to research on this and find a solution, but so far, no clue. |
@adam-fowler I guess this PR is now ready for review. I will squash the commits, once we pass the review stage. |
333b2d9
to
50ffdcd
Compare
------------------------------------------------------------------------------- This implements an LSP Extension `PeekDocumentsRequest` to let `ExpandMacroCommand` to open the macro expansions in a "peeked" editor window. For this to work, the client has to pass "workspace/peekDocuments" enabled to `ClientCapabilities.experimental` and the client should handle the `PeekDocumentsRequest` and show the expansions in a "peeked" editor window. PR to support the above capability in the "Swift for VS Code" Extension: swiftlang/vscode-swift#945 The "Swift for VS Code" extension cannot send the client capability, so it instead passes the same through `initializationOptions` in the `InitializeRequest`. For editors which doesn't support this capability, `sourcekit-lsp` sends a `ShowDocumentRequest`. The `ShowDocumentRequest` is updated to show all the macro expansions in a single generated file. Moreover, its folder structure is updated to use hex string of MD5 hash of concatenation of buffer names of expansions. Fixes swiftlang/vscode-swift#564 Fixes swiftlang#1498 ( rdar://130207754 )
2c60285
to
4007fd7
Compare
------------------------------------------------------------------------------- This implements an LSP Extension `PeekDocumentsRequest` to let `ExpandMacroCommand` to open the macro expansions in a "peeked" editor window. For this to work, the client has to pass "workspace/peekDocuments" enabled to `ClientCapabilities.experimental` and the client should handle the `PeekDocumentsRequest` and show the expansions in a "peeked" editor window. PR to support the above capability in the "Swift for VS Code" Extension: swiftlang/vscode-swift#945 The "Swift for VS Code" extension cannot send the client capability, so it instead passes the same through `initializationOptions` in the `InitializeRequest`. For editors which doesn't support this capability, `sourcekit-lsp` sends a `ShowDocumentRequest`. The `ShowDocumentRequest` is updated to show all the macro expansions in a single generated file. Moreover, its folder structure is updated to use hex string of MD5 hash of concatenation of buffer names of expansions. Fixes swiftlang/vscode-swift#564 Fixes swiftlang#1498 ( rdar://130207754 )
@adam-fowler The PR in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor changes, but everything else looks good
------------------------------------------------------------------------------- This implements an LSP Extension `PeekDocumentsRequest` to let `ExpandMacroCommand` to open the macro expansions in a "peeked" editor window. For this to work, the client has to pass "workspace/peekDocuments" enabled to `ClientCapabilities.experimental` and the client should handle the `PeekDocumentsRequest` and show the expansions in a "peeked" editor window. PR to support the above capability in the "Swift for VS Code" Extension: swiftlang/vscode-swift#945 The "Swift for VS Code" extension cannot send the client capability, so it instead passes the same through `initializationOptions` in the `InitializeRequest`. For editors which doesn't support this capability, `sourcekit-lsp` sends a `ShowDocumentRequest`. The `ShowDocumentRequest` is updated to show all the macro expansions in a single generated file. Moreover, its folder structure is updated to use hex string of MD5 hash of concatenation of buffer names of expansions. Fixes swiftlang/vscode-swift#564 Fixes swiftlang#1498 ( rdar://130207754 )
4007fd7
to
8c2aab9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are good
This PR utilises the following PR in sourcekit-lsp: swiftlang/sourcekit-lsp#1479
This takes a custom
PeekDocumentsRequest
and opens a peek window to display each given document. In the current state, this request is being used byExpandMacroCommand
in sourcekit-lsp to display Macro Expansions.To check out this functionality, build the
main
branch ofsourcekit-lsp
. Then, configure your "swift.sourcekit-lsp.serverPath" to the built sourcekit-lsp. (This step will not be necessary once this build of sourcekit-lsp is packaged with Swift itself given that you use the latest Swift Toolchain)Since the macro expansions feature is behind an experimental feature flag, configure your swift extension settings as follows:
(The above step will not be necessary when showing macro expansions comes to a mature stage in the sourcekit-lsp side and thus will be out of its experimental feature flag)
The "Expand Macro" will be available as a Code Action when the cursor sits on a Macro annotation, and selecting the code action will trigger the
ExpandMacroCommand
->PeekDocumentsRequest
, and thus shows the Macro Expansions inside a "peeked" editor.Note for extension / plugin developers of other editor ecosystems:
If you are an extension developer wanting to implement this custom functionality in your own editor, set the experimental client capability
workspace/peekDocuments
totrue
, in order to makesourcekit-lsp
to send thePeekDocumentsRequest
. From there, you can handle the request and display the documents in any way as you wish, as long as it is "inline" to the editor (or) "peeks" the documents inside the editor.Fixes #564
Expansion of Swift Macros in Visual Studio Code - Google Summer Of Code 2024
@lokesh-tr @ahoppen @adam-fowler