mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
Fix error loading "text" syntax for hover (#4574)
rust-analyzer sometimes returns a hover result with language being
"text", but there's no syntax/text.vim, so this would fail with:
Error detected while processing function <SNR>150_VimOutputCallback[6]..<lambda>8[1]..ale#lsp#HandleMessage[30]..ale#hover#HandleLSPResponse[42]..ale#floating_preview#Show[13]..<SNR>161_VimShow:
line 13:
E484: Cannot open file syntax/text.vim
Only including the file when it actually exists fixes this.
This commit is contained in:
@@ -70,6 +70,18 @@ function! s:ConvertLanguageName(language) abort
|
||||
return a:language
|
||||
endfunction
|
||||
|
||||
" Cache syntax file (non-)existence to avoid calling globpath repeatedly.
|
||||
let s:syntax_file_exists_cache = {}
|
||||
|
||||
function! s:SyntaxFileExists(syntax_file) abort
|
||||
if !has_key(s:syntax_file_exists_cache, a:syntax_file)
|
||||
let s:syntax_file_exists_cache[a:syntax_file] =
|
||||
\ !empty(globpath(&runtimepath, a:syntax_file))
|
||||
endif
|
||||
|
||||
return s:syntax_file_exists_cache[a:syntax_file]
|
||||
endfunction
|
||||
|
||||
function! ale#hover#ParseLSPResult(contents) abort
|
||||
let l:includes = {}
|
||||
let l:highlights = []
|
||||
@@ -160,10 +172,11 @@ function! ale#hover#ParseLSPResult(contents) abort
|
||||
let l:language = s:ConvertLanguageName(l:language)
|
||||
|
||||
if !empty(l:language)
|
||||
let l:includes[l:language] = printf(
|
||||
\ 'syntax/%s.vim',
|
||||
\ l:language,
|
||||
\)
|
||||
let l:syntax_file = printf('syntax/%s.vim', l:language)
|
||||
|
||||
if s:SyntaxFileExists(l:syntax_file)
|
||||
let l:includes[l:language] = l:syntax_file
|
||||
endif
|
||||
|
||||
let l:start = len(l:lines) + 1
|
||||
let l:end = l:start + len(l:marked_lines)
|
||||
|
||||
Reference in New Issue
Block a user