-
Notifications
You must be signed in to change notification settings - Fork 74
Showing Macro Expansion #564
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
Showing Macro Expansion #564
Comments
As you have seen I've already added an issue for sourcekit-lsp. I've had a look through the VSCode APIs and so far haven't found an easy way to display extra content inside an TextEditor window. I'll need to investigate further. |
I found this discussion in the cpp-tools repo, where macro expansions look like so: |
As an aside there is already a code action "Inline Macro" which will expand the macro into your file. You can use that plus Ctrl+Z to view the macro and revert |
Thanks! I tried that but no code action showed up :( Are there specific version requirements (for Swift or even VSCode) for this to work? |
Probably best to install Xcode beta 3. Beta 2 version of sourcekit-lsp had issues. |
------------------------------------------------------------------------------- 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 )
------------------------------------------------------------------------------- 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 )
------------------------------------------------------------------------------- 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 )
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
Without seeing what code macros generate, it's hard to understand macro-related errors. For example, a macro might try to access a variable "_count" but forget the underscore prefix: "count". Being able to see the macro expansion would make it easy to identify the problem, which is critical for developing macros.
Describe the solution you'd like
An Xcode-like action could be shown when opening the context menu (when right clicking) on a macro. Then, after finding the expansion, the extension could be shown below the code using the macro (similar to inlay hints). Otherwise, a pop up showing expanded code could appear (similar to when inspecting documentation).
Describe alternatives you've considered
The alternative is to use a compiler flag to see macro expansions. That lacks specificity, as all macro expansions are shown. Even if the compiler gains the ability to only show the expansion of one macro, typing that macro's name or source location into the command line can hamper productivity. Instead, it's much more convenient to click on the macro, right in the editor, and be shown its expansion.
Additional context
Related SourceKit LSP issue swiftlang/sourcekit-lsp#755
The text was updated successfully, but these errors were encountered: