[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>
This commit is contained in:
Oliver Albertini 2024-02-21 18:10:32 -08:00 committed by GitHub
parent 6fd9f3c54f
commit 506d392f6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -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, '')

View File

@ -12,6 +12,22 @@ Execute(Invalid results should be handled):
AssertEqual [[], []], ale#hover#ParseLSPResult({'kind': 'x', 'value': 'xxx'})
Execute(A string with a code fence should be handled):
AssertEqual
\ [
\ [
\ ],
\ [
\ 'def foo():',
\ ' pass',
\ ],
\ ],
\ ale#hover#ParseLSPResult(join([
\ '```',
\ 'def foo():',
\ ' pass',
\ '```',
\ ], "\n"))
AssertEqual
\ [
\ [