You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let LS detect workspace root after first file opened
Only set workspace root once the first file of that file type is opened;
otherwise the workspace root often is $HOME (say when using Gvim, or
opening a file in a Git repo) and the LS scans too many files
Partially resolves [0]
as ideally this workspace root would automatically change with the CWD,
in particular after loading a session (:h mksession)
Links:
[0]: #512
After installing the plugin using the above steps, add the following line to
17
-
your $HOME/.vimrc file:
17
+
your `$HOME/.vimrc` file:
18
18
19
19
```viml
20
20
packadd lsp
@@ -55,41 +55,55 @@ To use the plugin features with a particular file type(s), you need to first reg
55
55
The LSP servers are registered using the `LspAddServer()` function. This function accepts a list of LSP servers.
56
56
57
57
To register a LSP server, add the following lines to your .vimrc file (use only the LSP servers that you need from the below list). If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, the steps are described later in this section.
# Only set Workspace Root once the first file of that file type is openend
97
+
# otherwise often defaults to $HOME and scans too many files
98
+
augroup LspSetup
99
+
autocmd!
100
+
augroup END
101
+
for i in range(len(g:lspServers))
102
+
for ft in g:lspServers[i].filetype
103
+
# echoerr 'autocmd LspSetup FileType' ft 'call LspAddServer([g:lspServers[' .. i .. ']]) | autocmd! LspSetup FileType' ft
104
+
exe 'autocmd LspSetup FileType' ft 'autocmd BufWinEnter <buffer> call LspAddServer([g:lspServers[' .. i .. ']]) | autocmd! LspSetup FileType' ft
105
+
endfor
106
+
endfor
93
107
```
94
108
95
109
The above lines register the language servers for C/C++, Javascript/Typescript, Go and Rust file types. Refer to the [Wiki](https://github.com/yegappan/lsp/wiki) page for various language server specific configuration.
@@ -110,6 +124,7 @@ The `LspAddServer()` function accepts a list of LSP servers with the above infor
110
124
111
125
Some of the LSP plugin features can be enabled or disabled by using the `LspOptionsSet()` function, detailed in `:help lsp-options`.
112
126
Here is an example of configuration with default values:
127
+
113
128
```viml
114
129
call LspOptionsSet(#{
115
130
\ aleSupport: v:false,
@@ -159,17 +174,25 @@ call LspOptionsSet(#{
159
174
```
160
175
161
176
If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, then you need to use the LspSetup User autocmd to initialize the LSP server and to set the LSP server options. For example:
177
+
162
178
```viml
163
179
let lspOpts = #{autoHighlightDiags: v:true}
164
180
autocmd User LspSetup call LspOptionsSet(lspOpts)
165
181
166
-
let lspServers = [#{
182
+
let g:lspServers = [#{
167
183
\ name: 'clang',
168
184
\ filetype: ['c', 'cpp'],
169
185
\ path: '/usr/local/bin/clangd',
170
186
\ args: ['--background-index']
171
187
\ }]
172
-
autocmd User LspSetup call LspAddServer(lspServers)
188
+
augroup LspSetup
189
+
autocmd!
190
+
augroup END
191
+
for i in range(len(g:lspServers))
192
+
for ft in g:lspServers[i].filetype
193
+
exe 'autocmd LspSetup FileType' ft 'autocmd BufWinEnter <buffer> call LspAddServer([g:lspServers[' .. i .. ']]) | autocmd! LspSetup FileType' ft
0 commit comments