microsoft/vscode-languageserver-node

Allow asWorkspaceEdit to be overridden

Offen

#1.000 geöffnet am 13.06.2022

 (11 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (397 Forks)auto 404
feature-requesthelp wanted

Repository-Metriken

Stars
 (1.776 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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