Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ by setting the rust-analyzer
<summary>
<b>View syntax tree</b>
</summary>

Requires rust-analyzer >= 2025-01-20.

```vim
:RustLsp syntaxTree
Expand Down
11 changes: 9 additions & 2 deletions lua/rustaceanvim/commands/syntax_tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local M = {}
---@type integer | nil
local latest_buf_id = nil

---@param result string
local function parse_lines(result)
local ret = {}

Expand All @@ -15,7 +16,13 @@ local function parse_lines(result)
return ret
end

local function handler(_, result)
local function handler(err, result)
err = vim.tbl_get(err or {}, 'message')
if err or result == nil then
err = 'rust-analyzer: ' .. (err or 'rust-analyzer/viewSyntaxTree failed [unknown error]')
vim.notify(err, vim.log.levels.ERROR)
return
end
ui.delete_buf(latest_buf_id)
latest_buf_id = vim.api.nvim_create_buf(false, true)
ui.split(true, latest_buf_id)
Expand All @@ -31,7 +38,7 @@ function M.syntax_tree()
return
end
local params = vim.lsp.util.make_range_params(0, clients[1].offset_encoding or 'utf-8')
ra.buf_request(0, 'rust-analyzer/syntaxTree', params, handler)
ra.buf_request(0, 'rust-analyzer/viewSyntaxTree', params, handler)
end

return M.syntax_tree