microsoft / microsoft/vscode-languageserver-node
Allow asWorkspaceEdit to be overridden
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.8k
- Forks
- 404
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 14
Description
I implemented the Rust extension described in #724 / https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#snippet-textedit to support snippets in Code Actions. However, in the client I'm unable to access the new insertTextFormat field on TextEdit. Initially I implemented a hack that just looked for snippet placeholders in the edit body, but users have found if they have $0 (etc.) in their code, some refactors will not work correctly.
In https://github.com/microsoft/language-server-protocol/issues/724#issuecomment-800970546, @dbaeumer said we can use middleware to use our own asWorkspaceEdit, however as far as I can tell, this can't be done in middleware because the middleware has to call next(), which sends the request to the server and deserialises and converts the response (so it appears to be too late to access the raw data before the insertTextFormat field is lost).
I think what we really want to do is replace protocol2CodeConverter.asCodeActionResult. We can already replace some functions on protocol2CodeConverter (eg. via clientOptions.uriConverters) but as far as I can tell, we can't replace this (because _p2c is private, and only has a public getter, and is constructed in the constructor only allowing URI converters to be changed).
@dbaeumer if there's not already a way to do this, would you accept a PR that allowed the whole of protocol2CodeConverter/code2ProtocolConverter to be provided to the constructor?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with protocol2CodeConverter.asCodeActionResult and the client constructor, then trace how _p2c and code2ProtocolConverter are created and exposed. Review the middleware and uriConverters paths described in the issue. Done means callers can provide or override the converters early enough to preserve fields such as insertTextFormat in Code Action results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100