Skip to content

Commit 100efff

Browse files
authored
fix: broken syntaxTree command (#713)
1 parent b1faa06 commit 100efff

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ by setting the rust-analyzer
651651
<summary>
652652
<b>View syntax tree</b>
653653
</summary>
654+
655+
Requires rust-analyzer >= 2025-01-20.
654656

655657
```vim
656658
:RustLsp syntaxTree

lua/rustaceanvim/commands/syntax_tree.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local M = {}
55
---@type integer | nil
66
local latest_buf_id = nil
77

8+
---@param result string
89
local function parse_lines(result)
910
local ret = {}
1011

@@ -15,7 +16,13 @@ local function parse_lines(result)
1516
return ret
1617
end
1718

18-
local function handler(_, result)
19+
local function handler(err, result)
20+
err = vim.tbl_get(err or {}, 'message')
21+
if err or result == nil then
22+
err = 'rust-analyzer: ' .. (err or 'rust-analyzer/viewSyntaxTree failed [unknown error]')
23+
vim.notify(err, vim.log.levels.ERROR)
24+
return
25+
end
1926
ui.delete_buf(latest_buf_id)
2027
latest_buf_id = vim.api.nvim_create_buf(false, true)
2128
ui.split(true, latest_buf_id)
@@ -31,7 +38,7 @@ function M.syntax_tree()
3138
return
3239
end
3340
local params = vim.lsp.util.make_range_params(0, clients[1].offset_encoding or 'utf-8')
34-
ra.buf_request(0, 'rust-analyzer/syntaxTree', params, handler)
41+
ra.buf_request(0, 'rust-analyzer/viewSyntaxTree', params, handler)
3542
end
3643

3744
return M.syntax_tree

0 commit comments

Comments
 (0)