-
Notifications
You must be signed in to change notification settings - Fork 328
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
Allow asWorkspaceEdit to be overridden #1000
Comments
In general, yes, but it depends a little bit on the impact of that export (e.g. what else we would need to export). Another idea would be to change the middleware so that the result can be captured before conversion. I know that others have asked for this as well. But it would be quite some work. |
@dbaeumer are you thinking of just adding these functions to the middleware, something like being able to do: const middleware = {
asWorkspaceEdit: (
item: ls.WorkspaceEdit | undefined | null,
token: code.CancellationToken | undefined,
original: (item: ls.WorkspaceEdit | undefined | null, token?: code.CancellationToken) => Promise<code.WorkspaceEdit | undefined>,
): Promise<code.WorkspaceEdit | undefined> => {
return original(item, token);
}
} Then delegating calls to If it's not an easy thing to do, do you know whether it's possible to do something like this in the meantime (I understand if I update the client I may need to change this etc.): const p2c = (client as any)._p2c;
const originalAsWorkspaceEdit = p2c.asWorkspaceEdit as Function;
function newAsWorkspaceEdit(...args: any[]) {
console.log("running!"); // this is never called 😞
return originalAsWorkspaceEdit.apply(p2c, args);
}
p2c.asWorkspaceEdit = newAsWorkspaceEdit;
console.log(p2c.asWorkspaceEdit === newAsWorkspaceEdit); // true This prints |
Actually no. The problem with the middleware with each middleware function is that it can't intercept the result of the request before we convert it. It would be cool if we could do that in general. Might be at some point useful for other requests as well. |
I guess I was thinking my If it's not that simple, do you know why my attempt to replace |
@DanTup the |
@dbaeumer understood. Do you know why my attempt to replace |
@DanTup as said above it would work. However, adding this would make it API (otherwise you can't override it) and this introduces a concept I don't want to keep. As said, I would rather let you exchange the converter. |
@dbaeumer sorry, I wasn't very clear. I understand your position on an official API, but I was trying to implement a workaround inside my extension code in the meantime to fix the bug. I was trying to overwrite the method (unofficially) like this: const p2c = (client as any)._p2c;
const originalAsWorkspaceEdit = p2c.asWorkspaceEdit as Function;
function newAsWorkspaceEdit(...args: any[]) {
console.log("running!"); // this is never called 😞
return originalAsWorkspaceEdit.apply(p2c, args);
}
p2c.asWorkspaceEdit = newAsWorkspaceEdit;
console.log(p2c.asWorkspaceEdit === newAsWorkspaceEdit); // true It seems like |
nm, I figured this out... The original call is to So, it'll definitely be messier this way, but it might give me a fix for now if it's not clear what the official solution to this will be yet. Thanks! |
Great you figured it out. And sorry for misunderstanding your question at the beginning. |
np! The workaround is definitely quite hacky and could be fragile across LSP Client updates, but I've added tests for it and will change it if/when there's a more formal way to do it. Thanks! |
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 onTextEdit
. 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 microsoft/language-server-protocol#724 (comment), @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 callnext()
, 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 theinsertTextFormat
field is lost).I think what we really want to do is replace
protocol2CodeConverter.asCodeActionResult
. We can already replace some functions onprotocol2CodeConverter
(eg. viaclientOptions.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?The text was updated successfully, but these errors were encountered: