aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorFolke Lemaitre <folke.lemaitre@gmail.com>2021-05-21 19:16:50 +0200
committerFolke Lemaitre <folke.lemaitre@gmail.com>2021-05-21 19:16:50 +0200
commit262645b3257f428caca511d69f8439ee1ba22636 (patch)
treeb316aa9f005186b0df6d2b26b080422da4636b7a /runtime/lua/vim/lsp/util.lua
parent07f54201c787ecb730d949bad1fed9db61e2a62a (diff)
downloadrneovim-262645b3257f428caca511d69f8439ee1ba22636.tar.gz
rneovim-262645b3257f428caca511d69f8439ee1ba22636.tar.bz2
rneovim-262645b3257f428caca511d69f8439ee1ba22636.zip
fix(lsp): preview_location options and syntax fallback
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 83aa6747d2..863dc63c7f 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -951,7 +951,7 @@ end
---
--@param location a single `Location` or `LocationLink`
--@returns (bufnr,winnr) buffer and window number of floating window or nil
-function M.preview_location(location)
+function M.preview_location(location, opts)
-- location may be LocationLink or Location (more useful for the former)
local uri = location.targetUri or location.uri
if uri == nil then return end
@@ -962,7 +962,13 @@ function M.preview_location(location)
local range = location.targetRange or location.range
local contents = api.nvim_buf_get_lines(bufnr, range.start.line, range["end"].line+1, false)
local syntax = api.nvim_buf_get_option(bufnr, 'syntax')
- return M.open_floating_preview(contents, syntax)
+ if syntax == "" then
+ -- When no syntax is set, we use filetype as fallback. This might not result
+ -- in a valid syntax definition. See also ft detection in fancy_floating_win.
+ -- An empty syntax is more common now with TreeSitter, since TS disables syntax.
+ syntax = api.nvim_buf_get_option(bufnr, 'filetype')
+ end
+ return M.open_floating_preview(contents, syntax, opts)
end
--@private