-
Notifications
You must be signed in to change notification settings - Fork 54
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 client-side support for macro expansions #621
Conversation
The third todo in your list is going to be the stumbling block. I've looked into finding a better way to present macros a while back and didn't find an easy solution. You mention rust-analyser in the related sourcekit-lsp PR. Do you know what they do to present macros? |
That's not really a great solution |
I agree, haven't dug in too deep what APIs VSCode exposes in this regard, but I think it would be really cool if we could use an "inline editor" for this, which incidentally would also approximate Xcode's macro expansion UI: I think GitLens does or used to do something similar. We might still have to register a virtual document provider, but that should probably be doable. Edit: This presentation style seems to be called "Peeked editors" and there's an open upstream issue on exposing an API for creating custom peek widgets: Since we only need to display, perhaps there is a still a way to present such an editor with the existing APIs. Another proposed API that might be of interest (which would require us to implement a custom view though): |
The peeked editor approach seems to work well and looks nice too (check the PR description for a screenshot). |
That looks great, thank you! |
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.
It looks very nice. I didn't know about "editor.action.peekLocations"
In SourceKit-LSP you could add a CodeAction for macros to call the command you've setup here.
// old expansions will be closed correctly, but perhaps there's | ||
// a more elegant solution to this? | ||
const scheme = "swift-macro-expansion"; | ||
const provider = vscode.workspace.registerTextDocumentContentProvider(scheme, { |
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 will need to manage the text document content providers slightly better. Currently you just keep creating them, without cleaning up the unused ones. Adding them to the workspaceContext subscriptions means they get removed when the workspace is closed, but not before then.
Closing this in favour of #945 |
This implements basic client-side support for the
sourcekit-lsp/macroExpansion
request introduced inThe expansion is presented using an in-memory text document in a peeked editor:
To do
sourcekit-lsp/macroExpansion
)swift.expandMacro
)