@@ -8,35 +8,23 @@ local M = {}
8
8
--- @alias Loc integer[] a location in a buffer {row , col }, 0-indexed
9
9
--- @alias LocRange { start : Loc , [ " end" ] : Loc } a range consisting of two loc
10
10
11
- --- @class SymbolExtra
11
+ --- @class neotree. SymbolExtra
12
12
--- @field bufnr integer the buffer containing the symbols ,
13
- --- @field kind string the kind of each symbol
13
+ --- @field kind neotree.LspKindDisplay the kind of each symbol
14
14
--- @field selection_range LocRange the symbol ' s location
15
15
--- @field position Loc start of symbol ' s definition
16
16
--- @field end_position Loc start of symbol ' s definition
17
17
18
- --- @class SymbolNode see
18
+ --- @class neotree. SymbolNode see
19
19
--- @field id string
20
20
--- @field name string name of symbol
21
21
--- @field path string buffer path - should all be the same
22
22
--- @field type " root" | " symbol"
23
- --- @field children SymbolNode[]
24
- --- @field extra SymbolExtra additional info
25
-
26
- --- @alias LspLoc { line : integer , character : integer }
27
- --- @alias LspRange { start : LspLoc , [ " end" ] : LspLoc }
28
- --- @class LspRespNode
29
- --- @field name string
30
- --- @field detail string ?
31
- --- @field kind integer
32
- --- @field tags any
33
- --- @field deprecated boolean ?
34
- --- @field range LspRange
35
- --- @field selectionRange LspRange
36
- --- @field children LspRespNode[]
37
-
38
- --- Parse the LspRange
39
- --- @param range LspRange the LspRange object to parse
23
+ --- @field children neotree.SymbolNode[]
24
+ --- @field extra neotree.SymbolExtra additional info
25
+
26
+ --- Parse the lsp.Range
27
+ --- @param range lsp.Range the lsp.Range object to parse
40
28
--- @return LocRange range the parsed range
41
29
local parse_range = function (range )
42
30
return {
95
83
--- Parse the LSP response into a tree. Each node on the tree follows
96
84
--- the same structure as a NuiTree node, with the extra field
97
85
--- containing additional information.
98
- --- @param resp_node LspRespNode the LSP response node
86
+ --- @param resp_node lsp.DocumentSymbol | lsp.SymbolInformation the LSP response node
99
87
--- @param id string the id of the current node
100
- --- @return SymbolNode symb_node the parsed tree
88
+ --- @return neotree. SymbolNode symb_node the parsed tree
101
89
local function parse_resp (resp_node , id , state , parent_search_path )
102
90
-- parse all children
103
91
local children = {}
@@ -107,29 +95,37 @@ local function parse_resp(resp_node, id, state, parent_search_path)
107
95
table.insert (children , child_node )
108
96
end
109
97
110
- -- parse current node
111
- local preview_range = parse_range (resp_node .range )
112
- local symb_node = {
98
+ --- @type neotree.SymbolNode
99
+ local symbol_node = {
113
100
id = id ,
114
101
name = resp_node .name ,
115
102
type = " symbol" ,
116
103
path = state .path ,
117
104
children = children ,
105
+ --- @diagnostic disable-next-line : missing-fields
118
106
extra = {
119
107
bufnr = state .lsp_bufnr ,
120
108
kind = kinds .get_kind (resp_node .kind ),
121
- selection_range = parse_range (resp_node .selectionRange ),
122
109
search_path = search_path ,
123
110
-- detail = resp_node.detail,
124
- position = preview_range .start ,
125
- end_position = preview_range [" end" ],
126
111
},
127
112
}
128
- return symb_node
113
+ local preview_range = resp_node .range
114
+ if preview_range then
115
+ --- @cast resp_node lsp.DocumentSymbol
116
+ symbol_node .extra .selection_range = parse_range (resp_node .selectionRange )
117
+ else
118
+ --- @cast resp_node lsp.SymbolInformation
119
+ preview_range = resp_node .location .range
120
+ symbol_node .extra .selection_range = parse_range (preview_range )
121
+ end
122
+ symbol_node .extra .position = preview_range .start
123
+ symbol_node .extra .end_position = preview_range [" end" ]
124
+ return symbol_node
129
125
end
130
126
131
127
--- Callback function for lsp request
132
- --- @param lsp_resp LspRespRaw the response of the lsp client
128
+ --- @param lsp_resp neotree. LspRespRaw the response of the lsp client
133
129
--- @param state table the state of the source
134
130
local on_lsp_resp = function (lsp_resp , state )
135
131
if lsp_resp == nil or type (lsp_resp ) ~= " table" then
0 commit comments