Skip to content

Commit 0282b22

Browse files
committed
Add support to specifiy server name to send the correct initializationOptions
1 parent 1ff4321 commit 0282b22

8 files changed

+506
-52
lines changed

Diff for: Cargo.lock

+71
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ thiserror = "1.0.20"
4242
lazy_static = "1.4.0"
4343
tracing = { version = "0.1", features = ["log", "log-always"] }
4444
tracing-log = "0.1.1"
45+
46+
[dev-dependencies]
47+
tempfile = "3.1.0"

Diff for: doc/LanguageClient.txt

+74-10
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,64 @@ To use the language server with Vim's formatting operator |gq|, set 'formatexpr'
7575

7676
2.1 g:LanguageClient_serverCommands *g:LanguageClient_serverCommands*
7777

78-
String to list map. Defines commands to start language server for specific
79-
filetype. For example: >
78+
Dictionary to specify the servers to be used for each filetype. The keys are
79+
strings representing the filetypes and the values are either
80+
1 - a list of strings that form a command
81+
2 - a dictionary with keys name, command and initializationOptions, where:
82+
- name: is the name of the server, which should match the root node of the
83+
configuration options specified in the settings.json file for this server
84+
- command: is the same list of strings in option 1
85+
- initializationOptions: is an optional dictionary with options to be passed
86+
to the server. The values to be set here are highly dependent on each
87+
server so you should see the documentation for each server to find out
88+
what to configure in here (if anything). The options set in
89+
initializationOptions are merged with the default settings for each
90+
language server and with the workspace settings defined by the user in
91+
the files specified in the variable `LanguageClient_settingsPath'. The
92+
order in which these settings are merged is first the defualt settings,
93+
then the server settings configured in this section and lastly the
94+
contents of the files in the `LanguageClient_settingsPath` variable in
95+
the order in which they were listed.
96+
97+
For example: >
8098
8199
let g:LanguageClient_serverCommands = {
82100
\ 'rust': ['rustup', 'run', 'stable', 'rls'],
83-
\ }
84-
85-
In the example above, 'run', 'stable', and 'rls' are arguments to the
86-
'rustup' command line tool.
87-
88-
Or tcp connection string to the server, >
101+
\ 'go': {
102+
\ 'name': 'gopls',
103+
\ 'command': ['gopls'],
104+
\ 'initializationOptions': {
105+
\ 'usePlaceholders': v:true,
106+
\ 'codelens': {
107+
\ 'generate': v:true,
108+
\ 'test': v:true,
109+
\ },
110+
\ },
111+
\ },
112+
\}
113+
114+
In the configuration for the rust filetype above, 'run', 'stable', and 'rls'
115+
are arguments to the 'rustup' command line tool. And in the configuration for
116+
the go filetype the server is configured to run the command `gopls` with no
117+
additional arguments, and with the initialization options set in the
118+
`initializationOptions` key.
119+
120+
You can also use a tcp connection to the server, for example: >
89121
let g:LanguageClient_serverCommands = {
90122
\ 'javascript': ['tcp://127.0.0.1:2089'],
91123
\ }
92124
93125
Note: environmental variables are not supported except home directory alias `~`.
94126

95127
Default: {}
96-
Valid Option: Map<String, List<String> | String>
128+
129+
130+
131+
Valid Option: Map<String, List<String> | {
132+
name: String
133+
command: List<String>
134+
initializationOptions?: Map<String, Any>
135+
}>
97136

98137
2.2 g:LanguageClient_diagnosticsDisplay *g:LanguageClient_diagnosticsDisplay*
99138

@@ -231,9 +270,34 @@ path this is relative to the workspace directory. If several paths are
231270
provided, then the corresponding settings are merged with precedence going to
232271
the last file.
233272

273+
The initialization options found in the files in this config are combined with
274+
the initialization options specified in the server command, if any. The former
275+
taking precedence over the latter.
276+
277+
Note that the key under which the initialization options for each server lives
278+
matches the key under which the server expects it's configuration. This is
279+
important for servers that can request configuration via a
280+
`workspace/configuration` request.
281+
282+
Previously, the initialization options lived under a `initializationOptions`
283+
key, which worked, but made answering that `workspace/configuration` request
284+
hard, since we couldn't really get the correct path to the setting the server
285+
requested. Since version 0.1.161 of this plugin, that key has been deprecated
286+
and you'll see a message saying that you should move off of it if your settings
287+
file includes an `initializationOptions` key.
288+
234289
Example settings file content: >
235290
{
236-
"rust.clippy_preference": "on"
291+
"gopls": {
292+
"usePlaceholders": true,
293+
"local": "github.com/my/pkg",
294+
},
295+
"rust-analyzer": {
296+
"inlayHints": {
297+
"enable": true,
298+
"chainingHints": true
299+
},
300+
},
237301
}
238302
239303
Default: ".vim/settings.json"

Diff for: src/language_client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub struct LanguageClient {
2121
}
2222

2323
impl LanguageClient {
24-
pub fn new(version: String, state: State) -> Self {
24+
pub fn new(version: impl Into<String>, state: State) -> Self {
2525
LanguageClient {
26-
version,
26+
version: version.into(),
2727
state_mutex: Arc::new(Mutex::new(state)),
2828
clients_mutex: Arc::new(Mutex::new(HashMap::new())),
2929
}

0 commit comments

Comments
 (0)