Closed rharish101 closed 5 years ago
@rharish101 one of the requirements for language servers is that they must be provided a project root path. Unfortunately sometimes it is not easy to determine such path within ALE so some heuristics are used instead.
For bash-language-server the project root is set to the closest folder that contains a .git directory. See ale_linters#sh#language_server#GetProjectRoot(buffer) method for more details. This means that this language server will only work on git tracked projects.
For texlab is strange since the ale_linters#tex#texlab#GetProjectRoot(buffer)
method always returns an empty string. This effectively disables this language server for all files. Maybe the author of texlab support may provide more information.
Thanks a lot for pointing this out. I now defined a new linter (through ale#linter#Define
) using a custom function for finding the project root, as follows:
function! BashLangServProjRoot(buffer)
let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')
let l:curr_dir = fnamemodify(bufname(a:buffer), ':h')
return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : l:curr_dir
endfunction
call ale#linter#Define('sh', {
\ 'name': 'bashls',
\ 'lsp': 'stdio',
\ 'executable': function('ale_linters#sh#language_server#GetExecutable'),
\ 'command': function('ale_linters#sh#language_server#GetCommand'),
\ 'project_root': function('BashLangServProjRoot'),
\})
Is this method recommended for use? I would like your advice on using this in my vimrc. If it's fine, then I'll use this for texlab too.
That would work as a temporary fix for you so feel free to do so. The correct way would be to fix the FindRoot() methods of these linter so no configuration is required for them to work.
You can also use g:ale_lsp_root variable to override the current root.
Duplicate #2699 Related #2501
The project root functions are working as expected. You can specify the project root with ale_lsp_root
if the default project root detection doesn't work. Someone might be able to find a way to detect more project roots for Bash scripts, but I don't know what you'd look for.
Information
VIM version
Operating System: Arch Linux, with zsh as the default shell
What went wrong
I have installed bash-language-server and texlab through the Arch Linux package. However, ALE does not start them when opening a
.sh
file or a.tex
file (as seen through ALE's command history, and evidenced by the lack of completion), even when:ALEInfo
reports that it has enabledlanguage_server
as a linter for thesh
filetype andtexlab
for thetex
filetype.Reproducing the bug
.sh
file or.tex
file:ALEInfo
For bash:
For tex: