-
Notifications
You must be signed in to change notification settings - Fork 325
Add LSP extension to show Macro Expansions (or any document) in a "peeked" editor (and some minor quality improvements) #1479
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
Add LSP extension to show Macro Expansions (or any document) in a "peeked" editor (and some minor quality improvements) #1479
Conversation
be4204c to
8529f4e
Compare
@attached Macro Expansions 🚥
e5c84c1 to
35f821e
Compare
@attached Macro Expansions 🚥@attached Macro Expansions
ahoppen
left a comment
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.
Nice. I only have a few suggestions to simplify the test
35f821e to
4e9bcf6
Compare
|
@ahoppen I have also updated the PR to fix the bug where it fails to perform |
4e9bcf6 to
6237f58
Compare
|
The last commit which I made breaks the test cases and is also a proof-of-concept implementation of the feature which will be implemented in a full-fledged manner. Edit: Now, the test cases all pass and it's implemented in a full-fledged manner Here's the accompanying PR swiftlang/vscode-swift#945 in the VS Code Swift Extension Repository. |
@attached Macro Expansions@attached Macro Expansions 🚥
6237f58 to
2e14de9
Compare
@attached Macro Expansions 🚥 |
@ahoppen I have updated everything as per last call, I will squash the commits as soon as this passes the review stage. |
ahoppen
left a comment
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.
Wohooo 🚀
Sources/LanguageServerProtocol/Requests/PeekDocumentsRequest.swift
Outdated
Show resolved
Hide resolved
|
@ahoppen Let me know if there's anything else needed to be fixed, I shall proceed to squash the commits if they are all good. I have also updated the vscode-swift PR to incorporate the new changes. |
Sources/LanguageServerProtocol/Requests/PeekDocumentsRequest.swift
Outdated
Show resolved
Hide resolved
91a53c7 to
a9f2c7e
Compare
|
@ahoppen I have addressed your comments, let me know if there are any other concerns. I have also squashed the commits. I guess its ready to 🚢 |
ahoppen
left a comment
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.
Let’s see what CI has to say 🚀
|
@swift-ci Please test |
|
@ahoppen trigger Test windows ? |
|
@swift-ci Please test Windows |
|
@ahoppen All the test cases pass. But, seems like a merge conflict happened in between. But the conflicting file Edit: I rebased it anyways |
------------------------------------------------------------------------------- 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 )
Head branch was pushed to by a user without write access
a9f2c7e to
0221475
Compare
|
@swift-ci Please test |
|
@swift-ci Please test Windows |
Intro:
Note: This Feature is Experimental 🧪. You have to first enable this feature by passing
--experimental-feature show-macro-expansionstosourcekit-lspThe previous PR (#1436) lays the foundation for adding LSP support to show Macro Expansions of any kind. This PR brings better macro expansion functionality to all editors and some custom functionality through LSP extension for VS Code (, which other editors can also utilise by custom request handling.)
If you are interested in bringing the custom functionality to your own editor, I highly recommend going through the PR below:
Accompanying PR in "Swift for VS Code" Extension": swiftlang/vscode-swift#945
About this pull request:
This implements an LSP Extension
PeekDocumentsRequestto letExpandMacroCommandto open the macro expansions in a "peeked" editor window. For this to work, the client has to pass "workspace/peekDocuments" enabled toClientCapabilities.experimentaland the client should handle thePeekDocumentsRequestand 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
initializationOptionsin theInitializeRequest.For editors which doesn't support this capability,
sourcekit-lspsends aShowDocumentRequest.The
ShowDocumentRequestis 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.This PR also does a lot of quality improvements.
List of all changes:
changes the shown Line and Column numbers to be One-based indexing instead of Zero-based indexing, so that users can match the macro expansions' line and column numbers with their editor's line and column numbers.
adds a test case for
@attachedMacro Expansion, thereby assures LSP support for@attachedMacro Expansions.fixes a bug where
ShowDocumentRequestfails due to invalidselectionmakes
ShowDocumentRequestto use only a single file to display all the expansionsimplements a general
PeekDocumentsRequestthat can be used to make the editor to open files in a peeked editorif the client sets the experimental client capability
peekDocuments(or alternatively, in theinitializationOptions), then theExpandMacroCommandsends aPeekDocumentsRequestinstead of aShowDocumentRequest. (Accompanying PR in vscode-swift extension: HandlePeekDocumentsRequestto show documents from sourcekit-lsp (like, Macro Expansions) in a "peeked" editor vscode-swift#945)Fixes Showing Macro Expansion vscode-swift#564
updated all
ExecuteCommandTestsappropriatelyFixes Don’t return edits from
ExecuteCommandRequest#1498 (rdar://130207754)Added Documentation wherever necessary
updates folder structure to utilise MD5 hash for
ShowDocumentRequestgenerated macro expansionsReferences:
Previous PR which laid the foundation: #1436
Accompanying PR in the Swift Extension for VS Code repository: swiftlang/vscode-swift#945
Expansion of Swift Macros in Visual Studio Code - Google Summer Of Code 2024
@lokesh-tr @ahoppen @adam-fowler