소스 검색

fix(peek): print error if lsp is unable to get file contents (#2379)

* fix(peek): print error if lsp is unable to get file contents

* fix(peek): replace print with vim.notify
Abouzar Parvan 3 년 전
부모
커밋
cf96211cf5
1개의 변경된 파일9개의 추가작업 그리고 4개의 파일을 삭제
  1. 9 4
      lua/lvim/lsp/peek.lua

+ 9 - 4
lua/lvim/lsp/peek.lua

@@ -32,6 +32,10 @@ local function create_floating_file(location, opts)
     math.min(range["end"].line + 1 + (opts.context or 10), range.start.line + (opts.max_height or 15)), -- Don't let the window be more that 15 lines long(height)
     false
   )
+  if next(contents) == nil then
+    vim.notify("peek: Unable to get contents of the file!", vim.log.levels.WARN)
+    return
+  end
   local width, height = vim.lsp.util._make_floating_popup_size(contents, opts)
   local if_nil = vim.F.if_nil
   opts = vim.lsp.util.make_floating_popup_options(if_nil(width, 30), if_nil(height, 10), opts)
@@ -82,7 +86,7 @@ function M.open_file()
   local filepath = vim.fn.expand "%:."
 
   if not filepath then
-    print "peek: Unable to open the file!"
+    vim.notify("peek: Unable to open the file!", vim.log.levels.ERROR)
     return
   end
 
@@ -115,7 +119,7 @@ function M.Peek(what)
   if vim.tbl_contains(vim.api.nvim_list_wins(), M.floating_win) then
     local success_1, _ = pcall(vim.api.nvim_set_current_win, M.floating_win)
     if not success_1 then
-      print "peek: You cannot edit the current file in a preview!"
+      vim.notify("peek: You cannot edit the current file in a preview!", vim.log.levels.ERROR)
       return
     end
 
@@ -135,8 +139,9 @@ function M.Peek(what)
     local preview_callback = preview_location_callback_new_signature
     local success, _ = pcall(vim.lsp.buf_request, 0, "textDocument/" .. what, params, preview_callback)
     if not success then
-      print(
-        'peek: Error calling LSP method "textDocument/' .. what .. '". The current language lsp might not support it.'
+      vim.notify(
+        'peek: Error calling LSP method "textDocument/' .. what .. '". The current language lsp might not support it.',
+        vim.log.levels.ERROR
       )
     end
   end