Skip to content

Add per-file LSP activation rules allowpaths, blockpaths #1380

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions autoload/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,24 @@ function! lsp#get_allowed_servers(...) abort
endfor
endif

if !l:blocked && !empty(@%)
let l:curpath = fnamemodify(@%, ':p')
for l:pattern in get(l:server_info, 'blockpaths', [])
if l:pattern == '*' || match(l:curpath, l:pattern) != -1
let l:blocked = 1
break
endif
endfor
let l:allowed = !has_key(l:server_info, 'allowpaths')
for l:pattern in get(l:server_info, 'allowpaths', [])
if l:pattern == '*' || match(l:curpath, l:pattern) != -1
let l:allowed = 1
break
endif
endfor
let l:blocked = l:blocked || !l:allowed
endif

if l:blocked
continue
endif
Expand Down
26 changes: 26 additions & 0 deletions doc/vim-lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,8 @@ one parameter which is a vim |dict| and is referred to as |vim-lsp-server_info|
\ 'cmd': {server_info->['server-exectuable']},
\ 'allowlist': ['filetype to allowlist'],
\ 'blocklist': ['filetype to blocklist'],
\ 'allowpaths': ['regexp for allowed files'],
\ 'blockpaths': ['regexp for blocked files'],
\ 'config': {},
\ 'workspace_config': {'param': {'enabled': v:true}},
\ 'languageId': {server_info->'python'},
Expand All @@ -1112,6 +1114,8 @@ The vim |dict| containing information about the server.
'cmd': {server_info->['server_executable']},
'allowlist': ['filetype'],
'blocklist': ['filetype'],
'allowpaths': ['regexp'],
'blockpaths': ['regexp'],
'config': {},
'workspace_config': {},
'languageId': {server_info->'filetype'},
Expand Down Expand Up @@ -1184,6 +1188,28 @@ The vim |dict| containing information about the server.
'allowlist': ['*']
'blocklist': ['javascript', 'typescript']
<
* allowpaths:
optional
String array of |regexp| patterns for absolute file paths that should have
the language server enabled. allowpaths are consulted only when file
is enabled by the allowlist and blocklist rules for its filetype.

Example: >
'allowpaths': ['^/home/user/Code/']
<
'*' is treated as matching every file.

* blockpaths:
optional
String array of |regexp| patterns for absolute file paths that should not
run the language server. The blockpaths rule has priority when both
allowpaths and blockpaths match active file.

Example: >
'blockpaths': ['^/home/user/Code/project1/']
<
'*' is treated as matching every file.

* workspace_config:
optional vim |dict|
Used to pass workspace configuration to the server after
Expand Down