aboutsummaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2020-02-16 00:03:47 +0900
committerYasuhiro Matsumoto <mattn.jp@gmail.com>2020-02-16 00:03:58 +0900
commit22866c9702670753fe791e39878a3e7d6698bdf4 (patch)
tree8c8e0049fdbe6b622bed209f665f4efa29534831 /autoload
parent4b3bfa6762854cd2a7b4b3ab350e44dffbaa205c (diff)
downloadvim-lsp-settings-22866c9702670753fe791e39878a3e7d6698bdf4.tar.gz
vim-lsp-settings-22866c9702670753fe791e39878a3e7d6698bdf4.tar.bz2
vim-lsp-settings-22866c9702670753fe791e39878a3e7d6698bdf4.zip
Edit local settings.json
Diffstat (limited to 'autoload')
-rw-r--r--autoload/lsp_settings.vim28
-rw-r--r--autoload/lsp_settings/profile.vim30
2 files changed, 41 insertions, 17 deletions
diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim
index 67c630e..d9a6a5b 100644
--- a/autoload/lsp_settings.vim
+++ b/autoload/lsp_settings.vim
@@ -168,8 +168,14 @@ function! lsp_settings#exec_path(cmd) abort
return ''
endfunction
-function! lsp_settings#root_uri(pattern) abort
- let l:dir = lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), a:pattern)
+function! lsp_settings#root_path(...) abort
+ let l:patterns = get(a:000, 0, [])
+ return lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), extend(l:patterns, g:lsp_settings_root_markers))
+endfunction
+
+function! lsp_settings#root_uri(...) abort
+ let l:patterns = get(a:000, 0, [])
+ let l:dir = lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), extend(l:patterns, g:lsp_settings_root_markers))
if empty(l:dir)
return lsp#utils#get_default_root_uri()
endif
@@ -358,18 +364,7 @@ function! s:vim_lsp_load_or_suggest(ft) abort
return
endif
- try
- let l:root = lsp#utils#find_nearest_parent_directory('.', '.vim-lsp-settings')
- if !empty(l:root) && filereadable(l:root . '/settings.json')
- let l:settings = json_decode(join(readfile(l:root . '/settings.json'), "\n"))
- if has_key(g:, 'lsp_settings')
- call lsp_settings#utils#merge(g:lsp_settings, l:settings)
- else
- let g:lsp_settings = l:settings
- endif
- endif
- catch
- endtry
+ call lsp_settings#profile#load_local()
if get(g:, 'lsp_loaded', 0)
for l:server in s:settings[a:ft]
@@ -438,6 +433,8 @@ function! s:vim_lsp_load_or_suggest(ft) abort
endif
endfor
+ delcommand LspRegisterServer
+
if l:disabled == 0 && l:found ==# 0
if a:ft !=# '_'
call s:vim_lsp_settings_suggest(a:ft)
@@ -451,9 +448,6 @@ function! s:vim_lsp_load_or_suggest(ft) abort
endif
endif
- if exists(':LspRegisterServer') !=# 2
- delcommand LspRegisterServer
- endif
endfunction
function! lsp_settings#clear() abort
diff --git a/autoload/lsp_settings/profile.vim b/autoload/lsp_settings/profile.vim
new file mode 100644
index 0000000..b8e93c8
--- /dev/null
+++ b/autoload/lsp_settings/profile.vim
@@ -0,0 +1,30 @@
+function! lsp_settings#profile#load_local() abort
+ try
+ let l:root = lsp#utils#find_nearest_parent_directory('.', '.vim-lsp-settings')
+ if !empty(l:root) && filereadable(l:root . '/settings.json')
+ let l:settings = json_decode(join(readfile(l:root . '/settings.json'), "\n"))
+ if has_key(g:, 'lsp_settings')
+ call lsp_settings#utils#merge(g:lsp_settings, l:settings)
+ else
+ let g:lsp_settings = l:settings
+ endif
+ endif
+ catch
+ endtry
+endfunction
+
+function! lsp_settings#profile#edit_local() abort
+ let l:root = lsp_settings#root_path(['.vim-lsp-settings'])
+ if !isdirectory(l:root)
+ return
+ endif
+ let l:root .= '/.vim-lsp-settings'
+ if !isdirectory(l:root)
+ call mkdir(l:root)
+ endif
+ exe 'new' l:root . '/settings.json'
+ if !filereadable(l:root . '/settings.json')
+ call setline(1, ['{', "\t", '}'])
+ call cursor([2, 2])
+ endif
+endfunction