[go: up one dir, main page]

Skip to content
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

Request ID validation #571

Closed
julien opened this issue Nov 10, 2024 · 2 comments · Fixed by #572
Closed

Request ID validation #571

julien opened this issue Nov 10, 2024 · 2 comments · Fixed by #572

Comments

@julien
Copy link
Contributor
julien commented Nov 10, 2024

When using zls, an error is thrown here. The reason is because zls is not sending a string that contains digits as can be seen here as an example.

The specification says that the request's ID can be a number or a string, but, as fat as I can see it doesn't say that this ID must contain digits (but it would make sense).

I came up with this "workaround":

diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim
index 7304b00..1d4b0ed 100644
--- a/autoload/lsp/lspserver.vim
+++ b/autoload/lsp/lspserver.vim
@@ -326,11 +326,9 @@ enddef

 # send a response message to the server
 def SendResponse(lspserver: dict<any>, request: dict<any>, result: any, error: dict<any>)
-  if (request.id->type() == v:t_string
-       && (request.id->trim() =~ '[^[:digit:]]\+'
-           || request.id->trim()->empty()))
+  if (request.id->type() == v:t_string && request.id->trim()->empty())
     || (request.id->type() != v:t_string && request.id->type() != v:t_number)
-    util.ErrMsg('request.id of response to LSP server is not a correct number')
+    util.ErrMsg('request.id of response to LSP server must be a number or a string')
     return
   endif
   var resp: dict<any> = lspserver.createResponse(

What are your thoughts?

@yegappan
Copy link
Owner

Does this change work for you? The Vim channel feature supports using only integers as request identifiers and doesn't currently support a string as an identifier. But this only applies to the ch_sendexpr() and ch_evalexpr() functions. It may not apply in this case though. If this works for you, can you create a PR with this change?

@julien
Copy link
Contributor Author
julien commented Nov 10, 2024

Does this change work for you?

Yes it does. I've tested with zls, rust-analyzer and gopls and didn't experience any issue.

The Vim channel feature supports using only integers as request identifiers and doesn't currently support a string as an identifier. But this only applies to the ch_sendexpr() and ch_evalexpr() functions.

Thanks for explaining, now I understand why we are checking for digits in the request's ID.

I've submitted the patch in #572.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants