From d2f20950df0fd69c57adeb1b5bf9c081a050106f Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Sun, 3 Oct 2021 13:52:21 +0200 Subject: [PATCH] Add suport for type on code selection. This adds in initial support, but this issue in Metals should be merged in first: https://github.com/scalameta/metals/pull/3178. Closes #228 --- doc/metals.txt | 11 +++++++++++ lua/metals.lua | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/doc/metals.txt b/doc/metals.txt index bb17cf5..704dc2e 100644 --- a/doc/metals.txt +++ b/doc/metals.txt @@ -818,6 +818,17 @@ toggle_setting({setting}) lua require("metals").toggle_setting("showImplicitArguments") < + *type_of_range()* +type_of_range() Use to get the type of the selected range. NOTE that + the mapping for this requires an `` before the + actual mapping to ensure that the last correct range + is used. + + Example usage: > + + api.nvim_set_keymap("v", "K", [[lua require("metals").type_of_range()]]) + +< ================================================================================ METALS TVP MODULE *metals-tvp-module* diff --git a/lua/metals.lua b/lua/metals.lua index 98114c7..482a5c3 100644 --- a/lua/metals.lua +++ b/lua/metals.lua @@ -370,6 +370,10 @@ M.show_javap_verbose = function() )) end +M.type_of_range = function() + vim.lsp.buf_request(0, "textDocument/hover", vim.lsp.util.make_given_range_params()) +end + -- Since we want metals to be the entrypoint for everything, just for ensure that it's -- easy to set anything for users, we simply include them in here and then expose them. M.bare_config = setup.bare_config