11local config = require (" java-deps.config" )
2- local symbols = require (" java-deps.symbols" )
3- local folding = require (" java-deps.folding" )
4- local t_utils = require (" java-deps.utils.table" )
5- local ui = require (" java-deps.ui" )
2+ local data_node = require (" java-deps.views.data_node" )
63local M = {}
7- --- @param result DataNode[]
8- --- @param depth integer
9- --- @return table
10- local function parse_result (result , depth )
11- local ret = nil
12-
13- for index , value in pairs (result ) do
14- local level = depth or 1
15- -- whether this node is the last in its group
16- local isLast = index == # result
17-
18- local node = {
19- kind = value .kind ,
20- depth = level ,
21- parent = parent ,
22- }
23- if ret == nil then
24- ret = {}
25- end
26-
27- table.insert (ret , node )
28-
29- local children = nil
30- if value .children ~= nil then
31- -- copy by value because we dont want it messing with the hir table
32- local child_hir = t_utils .array_copy (hir )
33- table.insert (child_hir , isLast )
34- children = parse_result (value ._childrenNodes , level + 1 , child_hir , node )
35- end
364
37- node .children = children
5+ local function str_to_table (str )
6+ local t = {}
7+ for i = 1 , # str do
8+ t [i ] = str :sub (i , i )
389 end
39- return ret
10+ return t
4011end
4112
42- M .sort_result = function (result )
43- table.sort (result , function (a , b )
44- if a .kind == b .kind then
45- return a .name < b .name
46- end
47- return a .kind < b .kind
48- end )
49- return result
50- end
51-
52- function M .parse (response , depth , hierarchy , parent )
53- local sorted = M .sort_result (response )
54- return parse_result (sorted , depth , hierarchy , parent )
55- end
56-
57- function M .flatten (outline_items , ret )
58- ret = ret or {}
59- for _ , value in ipairs (outline_items ) do
60- table.insert (ret , value )
61- value .line_in_outline = # ret
62- if value .children ~= nil and not folding .is_folded (value ) then
63- M .flatten (value .children , ret )
64- end
13+ local function table_to_str (t )
14+ local ret = " "
15+ for _ , value in ipairs (t ) do
16+ ret = ret .. tostring (value )
6517 end
6618 return ret
6719end
6820
21+ local guides = {
22+ markers = {
23+ bottom = " └" ,
24+ middle = " ├" ,
25+ vertical = " │" ,
26+ horizontal = " ─" ,
27+ },
28+ }
29+ --- @param flattened_outline_items TreeItem
30+ --- @return table
31+ --- @return table
6932function M .get_lines (flattened_outline_items )
7033 local lines = {}
7134 local hl_info = {}
7235
7336 for node_line , node in ipairs (flattened_outline_items ) do
7437 local depth = node .depth
75- local marker_space = ( config .options .fold_markers and 1 ) or 0
38+ local marker_space = config .options .fold_markers and 1 or 0
7639
77- local line = t_utils . str_to_table (string.rep (" " , depth + marker_space ))
40+ local line = str_to_table (string.rep (" " , depth + marker_space ))
7841 local running_length = 1
7942
8043 local function add_guide_hl (from , to )
@@ -96,8 +59,8 @@ function M.get_lines(flattened_outline_items)
9659 -- else add a middle marker
9760 elseif index == # line then
9861 -- add fold markers
99- if config .options .fold_markers and folding . is_foldable (node ) then
100- if folding .is_folded (node ) then
62+ if config .options .fold_markers and data_node . is_folded (node ) then
63+ if data_node .is_folded (node ) then
10164 line [index ] = config .options .fold_markers [1 ]
10265 else
10366 line [index ] = config .options .fold_markers [2 ]
@@ -108,21 +71,21 @@ function M.get_lines(flattened_outline_items)
10871 -- the root level has no vertical markers
10972 elseif depth > 1 then
11073 if node .isLast then
111- line [index ] = ui .markers .bottom
112- add_guide_hl (running_length , running_length + vim .fn .strlen (ui .markers .bottom ) - 1 )
74+ line [index ] = guides .markers .bottom
75+ add_guide_hl (running_length , running_length + vim .fn .strlen (guides .markers .bottom ) - 1 )
11376 else
114- line [index ] = ui .markers .middle
115- add_guide_hl (running_length , running_length + vim .fn .strlen (ui .markers .middle ) - 1 )
77+ line [index ] = guides .markers .middle
78+ add_guide_hl (running_length , running_length + vim .fn .strlen (guides .markers .middle ) - 1 )
11679 end
11780 end
11881 -- else if the parent was not the last in its group, add a
11982 -- vertical marker because there are items under us and we need
12083 -- to point to those
12184 elseif not node .hierarchy [index ] and depth > 1 then
122- line [index + marker_space ] = ui .markers .vertical
85+ line [index + marker_space ] = guides .markers .vertical
12386 add_guide_hl (
12487 running_length - 1 + 2 * marker_space ,
125- running_length + vim .fn .strlen (ui .markers .vertical ) - 1 + 2 * marker_space
88+ running_length + vim .fn .strlen (guides .markers .vertical ) - 1 + 2 * marker_space
12689 )
12790 end
12891 end
@@ -134,13 +97,14 @@ function M.get_lines(flattened_outline_items)
13497
13598 local final_prefix = line
13699
137- local string_prefix = t_utils . table_to_str (final_prefix )
100+ local string_prefix = table_to_str (final_prefix )
138101
139- table.insert (lines , string_prefix .. node .icon .. " " .. node .name )
102+ table.insert (lines , string_prefix .. node .icon .. " " .. node .label )
140103
141104 local hl_start = # string_prefix
142105 local hl_end = # string_prefix + # node .icon
143- local hl_type = config .options .symbols [symbols .kinds [node .kind ]].hl
106+ local hl = config .options .symbols [node .kind ]
107+ local hl_type = hl and hl .hl or " @lsp.type.class"
144108 table.insert (hl_info , { node_line , hl_start , hl_end , hl_type })
145109
146110 node .prefix_length = # string_prefix + # node .icon + 1
@@ -152,9 +116,7 @@ function M.get_details(flattened_outline_items)
152116 local lines = {}
153117 for _ , value in ipairs (flattened_outline_items ) do
154118 local detail
155- if symbols .type_kind (value ) == symbols .NodeKind .JAR then
156- detail = value .path
157- end
119+ -- TODO
158120 table.insert (lines , detail or " " )
159121 end
160122 return lines
0 commit comments