diff options
-rw-r--r-- | autoload/lsp_settings.vim | 6 | ||||
-rw-r--r-- | autoload/lsp_settings/utils.vim | 6 | ||||
-rw-r--r-- | test/lsp_settings.vimspec | 29 |
3 files changed, 39 insertions, 2 deletions
diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim index 08d1d64..867c1ff 100644 --- a/autoload/lsp_settings.vim +++ b/autoload/lsp_settings.vim @@ -10,7 +10,11 @@ call remove(s:settings, '$schema') let s:ftmap = {} function! lsp_settings#servers_dir() abort - return get(g:, 'lsp_settings_servers_dir', s:servers_dir) + let l:path = fnamemodify(get(g:, 'lsp_settings_servers_dir', s:servers_dir), ':p') + if has('win32') + let l:path = substitute(l:path, '/', '\', 'g') + endif + return substitute(l:path, '[\/]$', '', '') endfunction function! lsp_settings#executable(cmd) abort diff --git a/autoload/lsp_settings/utils.vim b/autoload/lsp_settings/utils.vim index d342388..96feb0a 100644 --- a/autoload/lsp_settings/utils.vim +++ b/autoload/lsp_settings/utils.vim @@ -24,5 +24,9 @@ function! lsp_settings#utils#first_one(lines) abort if empty(a:lines) return '' endif - return fnamemodify(split(a:lines, "\n")[0], ':p') + let l:path = fnamemodify(split(a:lines, "\n")[0], ':p') + if has('win32') + let l:path = substitute(l:path, '/', '\', 'g') + endif + return l:path endfunction diff --git a/test/lsp_settings.vimspec b/test/lsp_settings.vimspec index cff06a7..30995f6 100644 --- a/test/lsp_settings.vimspec +++ b/test/lsp_settings.vimspec @@ -52,4 +52,33 @@ Describe lsp_settings endtry End End + + Describe lsp_settings#exec_path + It should return full-path to the command + if has('win32') + Assert Equals(empty(lsp_settings#exec_path('cmd')), 0) + else + Assert Equals(empty(lsp_settings#exec_path('sh')), 0) + endif + End + + It should return 1 when command is executable in server/foo-bar/foo-bar + let l:servers_dir = lsp_settings#servers_dir() + + try + call delete(l:servers_dir . '/foo-bar', 'rf') + call mkdir(l:servers_dir . '/foo-bar', 'p') + if has('win32') + call writefile(['@echo off', 'echo foo-bar'], l:servers_dir . '/foo-bar/foo-bar.cmd') + Assert Equals(lsp_settings#exec_path('foo-bar'), l:servers_dir . '\foo-bar\foo-bar.cmd') + else + call writefile(['#!/bin/sh', 'echo foo-bar'], l:servers_dir . '/foo-bar/foo-bar') + call setfperm(l:servers_dir . '/foo-bar/foo-bar', 'rwxr-xr-x') + Assert Equals(lsp_settings#exec_path('foo-bar'), l:servers_dir . '/foo-bar/foo-bar') + endif + finally + call delete(l:servers_dir . '/foo-bar', 'rf') + endtry + End + End End |