]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Fix : Better ft detection for preview widow on hover reply
authorIndelog <maxime@indelog.fr>
Fri, 19 Nov 2021 09:37:53 +0000 (10:37 +0100)
committerIndelog <maxime@indelog.fr>
Fri, 19 Nov 2021 09:37:53 +0000 (10:37 +0100)
Avoid ` E715: Dictionary required` if lsp server does not provide the
kind of reply.

autoload/handlers.vim

index 7a9126a92fe43e635ba259ef13debdd99d10ddcb..6c2adaf0389d86739607b69ce5755d87eed04524 100644 (file)
@@ -335,8 +335,15 @@ def s:processHoverReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>):
       wincmd P
       setlocal buftype=nofile
       setlocal bufhidden=delete
-      if !reply.result.contents.kind->empty()
-          exe 'setlocal ft=' .. reply.result.contents.kind
+      # If lsp server provide kind of hover reply and this kind is in syntaxs
+      # syported by vim, use it for file type of preview window. Else use
+      # type text by default.
+      if reply.result.contents->has_key('kind')
+\          && !reply.result.contents.kind->empty()
+\          && getcompletion('', 'filetype')->index(reply.result.content.kind) > -1
+        exe 'setlocal ft=' .. reply.result.contents.kind
+      else
+        set setlocal ft=text
       endif
       deletebufline(bufnr(), 1,  getbufinfo(bufnr())[0].linecount)
       append(0, hoverText)