Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Add hoverRange capability #44

Merged
merged 1 commit into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ RustOpenCargo
RustParentModule
RustJoinLines
RustHoverActions
RustHoverRange
RustMoveItemDown
RustMoveItemUp
RustStartStandaloneServerForBuffer
Expand Down Expand Up @@ -225,6 +226,14 @@ Note: To activate hover actions, run the command twice (or your hover keymap if
require'rust-tools.hover_actions'.hover_actions()
```

### Hover Range
Note: Requires rust-analyzer version after 2021-08-02. Shows the type in visual mode when hovering.
```lua
-- Command:
-- RustHoverRange
require'rust-tools.hover_range'.hover_range()
```

### Open Cargo.toml
![open cargo](https://github.com/simrat39/rust-tools-demos/raw/master/open_cargo_toml.gif)
```lua
Expand Down
3 changes: 2 additions & 1 deletion lua/rust-tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local function setupCommands()
end
},
RustHoverActions = {require('rust-tools.hover_actions').hover_actions},
RustHoverRange = {require('rust-tools.hover_range').hover_range},
RustMoveItemDown = {
function() require('rust-tools.move_item').move_item() end
},
Expand Down Expand Up @@ -73,7 +74,7 @@ local function setup_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true

-- send actions with hover request
capabilities.experimental = {hoverActions = true}
capabilities.experimental = {hoverActions = true, hoverRange = true}

-- enable auto-import
capabilities.textDocument.completion.completionItem.resolveSupport =
Expand Down
27 changes: 27 additions & 0 deletions lua/rust-tools/hover_range.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local M = {}

local function get_opts()
local params = vim.lsp.util.make_range_params()
-- set start and end of selection
local start_m = vim.api.nvim_buf_get_mark(0, "<")
local end_m = vim.api.nvim_buf_get_mark(0, ">")
params.range.start = {
character = start_m[2],
line = start_m[1]-1, -- vim starts counting at 1, but lsp at 0
}
params.range["end"] = {
character = end_m[2],
line = end_m[1]-1, -- vim starts counting at 1, but lsp at 0
}
params.position = params.range
params.range = nil
--print(vim.inspect(params))

return params
end

function M.hover_range()
vim.lsp.buf_request(0, "textDocument/hover", get_opts())
end

return M