diff options
author | Oliver Albertini <oliverralbertini@users.noreply.github.com> | 2024-02-21 18:10:32 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-22 11:10:32 +0900 |
commit | 506d392f6a72a2a494f9575c087e2f518811a534 (patch) | |
tree | 90fe2018a1634aa2c70544e0b4792a94dc9849f7 | |
parent | 6fd9f3c54f80cec8be364594246daf9ac41cbe3e (diff) | |
download | ale-506d392f6a72a2a494f9575c087e2f518811a534.zip |
[hover] ParseLSPResult sets language 'text' for missing spec (#4699)
I have an LSP that is returning markdown code blocks on Hover with no
language specified, e.g.
````
```
Foobar
```
````
As a result, you get "```" in the message line which is not that useful.
I made the regex to catch the first code fence accept empty language as
well, and if it's empty, we set it to "text".
This makes it so that LSPs that return no language still produce legible
restuls on the message line.
Co-authored-by: Oliver Ruben Albertini <ora@fb.com>
-rw-r--r-- | autoload/ale/hover.vim | 4 | ||||
-rw-r--r-- | test/test_hover_parsing.vader | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/autoload/ale/hover.vim b/autoload/ale/hover.vim index 1202e08e..a42766eb 100644 --- a/autoload/ale/hover.vim +++ b/autoload/ale/hover.vim @@ -117,10 +117,10 @@ function! ale#hover#ParseLSPResult(contents) abort for l:line in split(l:item, "\n") if l:fence_language is v:null " Look for the start of a code fence. (```python, etc.) - let l:match = matchlist(l:line, '^``` *\([^ ]\+\) *$') + let l:match = matchlist(l:line, '^``` *\([^ ]\+\)\? *$') if !empty(l:match) - let l:fence_language = l:match[1] + let l:fence_language = len(l:match) > 1 ? l:match[1] : 'text' if !empty(l:marked_list) call add(l:fence_lines, '') diff --git a/test/test_hover_parsing.vader b/test/test_hover_parsing.vader index 81db1da3..b9e56de8 100644 --- a/test/test_hover_parsing.vader +++ b/test/test_hover_parsing.vader @@ -15,6 +15,22 @@ Execute(A string with a code fence should be handled): AssertEqual \ [ \ [ + \ ], + \ [ + \ 'def foo():', + \ ' pass', + \ ], + \ ], + \ ale#hover#ParseLSPResult(join([ + \ '```', + \ 'def foo():', + \ ' pass', + \ '```', + \ ], "\n")) + + AssertEqual + \ [ + \ [ \ 'unlet! b:current_syntax', \ 'syntax include @ALE_hover_python syntax/python.vim', \ 'syntax region ALE_hover_1 start=/\%1l/ end=/\%3l/ contains=@ALE_hover_python', |