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

workspace/configuration doesn't work for servers which don't send serverInfo #1235

Open
lantw44 opened this issue Oct 2, 2021 · 0 comments

Comments

@lantw44
Copy link

lantw44 commented Oct 2, 2021

Describe the bug

If the server doesn't provide serverInfo in InitializeResult, the plugin will send an empty array instead of the initializationOptions set by the user when the server requests workspace/configuration.

Environment

  • Vim 8.2.3450
  • Plugin version 1cb8bb5 (current dev branch)
  • Plugin's binary version 0.1.161
  • Relevant vimrc settings:
let g:LanguageClient_serverCommands = {
\   'yaml': {
\       'name': 'yaml',
\       'command': ['/path/to/yaml-language-server', '--stdio'],
\       'initializationOptions': {
\           'completion': v:true,
\           'hover': v:true,
\           'validate': v:true,
\           'format': {
\               'enable': v:true,
\               'singleQuote': v:true,
\               'bracketSpacing': v:true,
\           },
\       },
\   },
\}

To Reproduce

  • Use Vim to edit a YAML file with single-quoted strings. For example:
a: '123'
  • Execute call LanguageClient#textDocument_formatting()

Current behavior

Single quotes are changed to double quotes.

Expected behavior

Single quotes should not be changed. I have asked the plugin to tell the language server that I want single quotes, so the language server should not change it to double quotes.

Additional context

I am not sure if this is a correct patch, but at least it allows me to pass options to the YAML language server.

diff --git a/src/language_client.rs b/src/language_client.rs
index 0204c7c..e9bdcc9 100644
--- a/src/language_client.rs
+++ b/src/language_client.rs
@@ -973,11 +973,12 @@ impl LanguageClient {
             let server_name = initialize_result
                 .server_info
                 .as_ref()
-                .map(|info| info.name.clone());
-            if let (Some(name), Some(options)) = (server_name, initialization_options) {
+                .map(|info| info.name.clone())
+                .unwrap_or(command.name());
+            if let Some(options) = initialization_options {
                 state.initialization_options = state
                     .initialization_options
-                    .combine(&json!({ name: options }));
+                    .combine(&json!({ server_name: options }));
             }
 
             let capabilities: ServerCapabilities = initialize_result.capabilities.clone();
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

No branches or pull requests

1 participant