From 9e4a2c45165a6ba8160999513e256077173ef6d6 Mon Sep 17 00:00:00 2001 From: aaronsms Date: Thu, 29 Jul 2021 17:04:03 +0800 Subject: fix: change peekDefinition method location --- lua/lsp/keybinds.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/lsp/keybinds.lua') diff --git a/lua/lsp/keybinds.lua b/lua/lsp/keybinds.lua index 5722dab7..820ebce9 100644 --- a/lua/lsp/keybinds.lua +++ b/lua/lsp/keybinds.lua @@ -13,7 +13,7 @@ function M.setup() { noremap = true, silent = true } ) - vim.cmd "nnoremap gp lua require'lsp.utils'.PeekDefinition()" + vim.cmd "nnoremap gp lua require'lsp.service'.PeekDefinition()" vim.cmd "nnoremap K :lua vim.lsp.buf.hover()" vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})" vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})" -- cgit v1.2.3 From 9d89929d9bb47d1f78c2d3945b761da2f24a5643 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 31 Jul 2021 06:06:08 +0200 Subject: Enable querying lang-server formatting capabilities (#1078) --- lua/lsp/keybinds.lua | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'lua/lsp/keybinds.lua') diff --git a/lua/lsp/keybinds.lua b/lua/lsp/keybinds.lua index 820ebce9..cc0d4ec9 100644 --- a/lua/lsp/keybinds.lua +++ b/lua/lsp/keybinds.lua @@ -1,5 +1,70 @@ local M = {} +-- Taken from https://www.reddit.com/r/neovim/comments/gyb077/nvimlsp_peek_defination_javascript_ttserver/ +function M.preview_location(location, context, before_context) + -- location may be LocationLink or Location (more useful for the former) + context = context or 15 + before_context = before_context or 0 + local uri = location.targetUri or location.uri + if uri == nil then + return + end + local bufnr = vim.uri_to_bufnr(uri) + if not vim.api.nvim_buf_is_loaded(bufnr) then + vim.fn.bufload(bufnr) + end + + local range = location.targetRange or location.range + local contents = vim.api.nvim_buf_get_lines( + bufnr, + range.start.line - before_context, + range["end"].line + 1 + context, + false + ) + local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") + return vim.lsp.util.open_floating_preview(contents, filetype, { border = lvim.lsp.popup_border }) +end + +function M.preview_location_callback(_, method, result) + local context = 15 + if result == nil or vim.tbl_isempty(result) then + print("No location found: " .. method) + return nil + end + if vim.tbl_islist(result) then + M.floating_buf, M.floating_win = M.preview_location(result[1], context) + else + M.floating_buf, M.floating_win = M.preview_location(result, context) + end +end + +function M.PeekDefinition() + if vim.tbl_contains(vim.api.nvim_list_wins(), M.floating_win) then + vim.api.nvim_set_current_win(M.floating_win) + else + local params = vim.lsp.util.make_position_params() + return vim.lsp.buf_request(0, "textDocument/definition", params, M.preview_location_callback) + end +end + +function M.PeekTypeDefinition() + if vim.tbl_contains(vim.api.nvim_list_wins(), M.floating_win) then + vim.api.nvim_set_current_win(M.floating_win) + else + local params = vim.lsp.util.make_position_params() + return vim.lsp.buf_request(0, "textDocument/typeDefinition", params, M.preview_location_callback) + end +end + +function M.PeekImplementation() + if vim.tbl_contains(vim.api.nvim_list_wins(), M.floating_win) then + vim.api.nvim_set_current_win(M.floating_win) + else + local params = vim.lsp.util.make_position_params() + return vim.lsp.buf_request(0, "textDocument/implementation", params, M.preview_location_callback) + end +end + function M.setup() if lvim.lsp.default_keybinds then vim.cmd "nnoremap gd lua vim.lsp.buf.definition()" @@ -13,7 +78,7 @@ function M.setup() { noremap = true, silent = true } ) - vim.cmd "nnoremap gp lua require'lsp.service'.PeekDefinition()" + vim.cmd "nnoremap gp lua require'lsp.keybinds'.PeekDefinition()" vim.cmd "nnoremap K :lua vim.lsp.buf.hover()" vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})" vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})" -- cgit v1.2.3 From cf16a2e826774e89d1bfe5812b6f73c3dd049db2 Mon Sep 17 00:00:00 2001 From: Geet Sethi <65440103+sethigeet@users.noreply.github.com> Date: Sat, 31 Jul 2021 19:14:08 +0530 Subject: Add the better peek functions (#1172) --- lua/lsp/keybinds.lua | 67 +--------------------------------------------------- 1 file changed, 1 insertion(+), 66 deletions(-) (limited to 'lua/lsp/keybinds.lua') diff --git a/lua/lsp/keybinds.lua b/lua/lsp/keybinds.lua index cc0d4ec9..21f29994 100644 --- a/lua/lsp/keybinds.lua +++ b/lua/lsp/keybinds.lua @@ -1,70 +1,5 @@ local M = {} --- Taken from https://www.reddit.com/r/neovim/comments/gyb077/nvimlsp_peek_defination_javascript_ttserver/ -function M.preview_location(location, context, before_context) - -- location may be LocationLink or Location (more useful for the former) - context = context or 15 - before_context = before_context or 0 - local uri = location.targetUri or location.uri - if uri == nil then - return - end - local bufnr = vim.uri_to_bufnr(uri) - if not vim.api.nvim_buf_is_loaded(bufnr) then - vim.fn.bufload(bufnr) - end - - local range = location.targetRange or location.range - local contents = vim.api.nvim_buf_get_lines( - bufnr, - range.start.line - before_context, - range["end"].line + 1 + context, - false - ) - local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") - return vim.lsp.util.open_floating_preview(contents, filetype, { border = lvim.lsp.popup_border }) -end - -function M.preview_location_callback(_, method, result) - local context = 15 - if result == nil or vim.tbl_isempty(result) then - print("No location found: " .. method) - return nil - end - if vim.tbl_islist(result) then - M.floating_buf, M.floating_win = M.preview_location(result[1], context) - else - M.floating_buf, M.floating_win = M.preview_location(result, context) - end -end - -function M.PeekDefinition() - if vim.tbl_contains(vim.api.nvim_list_wins(), M.floating_win) then - vim.api.nvim_set_current_win(M.floating_win) - else - local params = vim.lsp.util.make_position_params() - return vim.lsp.buf_request(0, "textDocument/definition", params, M.preview_location_callback) - end -end - -function M.PeekTypeDefinition() - if vim.tbl_contains(vim.api.nvim_list_wins(), M.floating_win) then - vim.api.nvim_set_current_win(M.floating_win) - else - local params = vim.lsp.util.make_position_params() - return vim.lsp.buf_request(0, "textDocument/typeDefinition", params, M.preview_location_callback) - end -end - -function M.PeekImplementation() - if vim.tbl_contains(vim.api.nvim_list_wins(), M.floating_win) then - vim.api.nvim_set_current_win(M.floating_win) - else - local params = vim.lsp.util.make_position_params() - return vim.lsp.buf_request(0, "textDocument/implementation", params, M.preview_location_callback) - end -end - function M.setup() if lvim.lsp.default_keybinds then vim.cmd "nnoremap gd lua vim.lsp.buf.definition()" @@ -78,7 +13,7 @@ function M.setup() { noremap = true, silent = true } ) - vim.cmd "nnoremap gp lua require'lsp.keybinds'.PeekDefinition()" + vim.cmd "nnoremap gp lua require'lsp.peek'.Peek('definition')" vim.cmd "nnoremap K :lua vim.lsp.buf.hover()" vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})" vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})" -- cgit v1.2.3 From fe5daa722fb75ad85c24936cbb645018bb9d655b Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sat, 31 Jul 2021 16:12:29 +0200 Subject: [Feature] Expose lsp config (#1156) --- lua/lsp/keybinds.lua | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 lua/lsp/keybinds.lua (limited to 'lua/lsp/keybinds.lua') diff --git a/lua/lsp/keybinds.lua b/lua/lsp/keybinds.lua deleted file mode 100644 index 21f29994..00000000 --- a/lua/lsp/keybinds.lua +++ /dev/null @@ -1,27 +0,0 @@ -local M = {} - -function M.setup() - if lvim.lsp.default_keybinds then - vim.cmd "nnoremap gd lua vim.lsp.buf.definition()" - vim.cmd "nnoremap gD lua vim.lsp.buf.declaration()" - vim.cmd "nnoremap gr lua vim.lsp.buf.references()" - vim.cmd "nnoremap gi lua vim.lsp.buf.implementation()" - vim.api.nvim_set_keymap( - "n", - "gl", - 'lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = "single" })', - { noremap = true, silent = true } - ) - - vim.cmd "nnoremap gp lua require'lsp.peek'.Peek('definition')" - vim.cmd "nnoremap K :lua vim.lsp.buf.hover()" - vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})" - vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})" - -- vim.cmd "nnoremap gs lua vim.lsp.buf.signature_help()" - -- scroll down hover doc or scroll in definition preview - -- scroll up hover doc - -- vim.cmd 'command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()' - end -end - -return M -- cgit v1.2.3