Skip to content

Commit 8ade7ce

Browse files
committed
update
1 parent b7959f8 commit 8ade7ce

3 files changed

Lines changed: 118 additions & 41 deletions

File tree

lua/java-deps/debog.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local M = {}
2+
local logfile = vim.fn.stdpath("cache") .. "/java—deps.log"
3+
local write_log = function(msg)
4+
local file = io.open(logfile, "a")
5+
if file then
6+
file:write(msg .. "\n")
7+
file:close()
8+
end
9+
end
10+
11+
M.debug = function(msg)
12+
if type(msg) == "table" then
13+
msg = vim.inspect(msg)
14+
end
15+
write_log(msg)
16+
end
17+
18+
return M

lua/java-deps/java/jdtls.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ end
3333

3434
---@return INodeData[]
3535
M.getPackageData = function(params)
36-
local excludePatterns = {}
36+
local excludePatterns = nil
3737
local err, resp = lsp_command.execute_command({
3838
command = lsp_command.JAVA_GETPACKAGEDATA,
3939
arguments = params,
@@ -43,18 +43,18 @@ M.getPackageData = function(params)
4343
return {}
4444
end
4545
---@type INodeData[]
46-
local nodeData = resp and resp or {}
46+
local nodeDatas = resp and resp or {}
4747
-- Filter out non java resources
4848
if true then
49-
nodeData = vim.tbl_filter(function(data)
49+
nodeDatas = vim.tbl_filter(function(data)
5050
return data.kind ~= NodeKind.Folder and data.kind ~= NodeKind.File
51-
end, nodeData)
51+
end, nodeDatas)
5252
end
5353

54-
if excludePatterns and #nodeData > 0 then
54+
if excludePatterns and #nodeDatas > 0 then
5555
local uriOfChildren = vim.tbl_map(function(node)
5656
return node.uri
57-
end, nodeData)
57+
end, nodeDatas)
5858

5959
local urisToExclude = {}
6060
for _, pattern in pairs(excludePatterns) do
@@ -68,15 +68,15 @@ M.getPackageData = function(params)
6868
end
6969
end
7070
if #urisToExclude > 0 then
71-
nodeData = vim.tbl_filter(function(node)
71+
nodeDatas = vim.tbl_filter(function(node)
7272
if not node.uri then
7373
return true
7474
end
7575
return not vim.tbl_contains(urisToExclude, node.uri)
76-
end, nodeData)
76+
end, nodeDatas)
7777
end
7878
end
79-
return nodeData
79+
return nodeDatas
8080
end
8181

8282
---@return INodeData[]

lua/java-deps/views/data_node.lua

Lines changed: 91 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local ExplorerNode = require("java-deps.views.explorer_node").ExplorerNode
44
local hieararchicalPackageNodeData = require("java-deps.java.hieararchicalPackageNodeData")
55

66
local M = {}
7+
M.isHierarchicalView = true
78

89
M.K_TYPE_KIND = "TypeKind"
910
M.NATURE_ID = "NatureId"
@@ -87,6 +88,41 @@ function DataNode:new(nodeData, parent, project, rootNode)
8788
return data
8889
end
8990

91+
---@return DataNode[]
92+
function DataNode:createHierarchicalPackageRootNode()
93+
local result = {}
94+
local packageData = {}
95+
if self._nodeData.children then
96+
for _, child in ipairs(self._nodeData.children) do
97+
if child.kind == NodeKind.Package then
98+
table.insert(packageData, child)
99+
else
100+
table.insert(result, M.createNode(child, self, self._project, self))
101+
end
102+
end
103+
if #packageData > 0 then
104+
local data = hieararchicalPackageNodeData.createHierarchicalNodeDataByPackageList(packageData)
105+
if data and data.children then
106+
for _, child in ipairs(data.children) do
107+
table.insert(result, M.createNode(child, self, self._project, self))
108+
end
109+
end
110+
end
111+
end
112+
return result
113+
end
114+
115+
---@return DataNode[]
116+
function DataNode:createHierarchicalPackageNode()
117+
local result = {}
118+
if self._nodeData.children then
119+
for _, child in ipairs(self._nodeData.children) do
120+
table.insert(result, M.createNode(child, self, self._project, self._rootNode))
121+
end
122+
end
123+
return result
124+
end
125+
90126
function DataNode:createChildNodeList()
91127
local kind = self:kind()
92128
if kind == NodeKind.Workspace then
@@ -106,10 +142,17 @@ function DataNode:createChildNodeList()
106142
table.insert(result, M.createNode(child, self, self, nil))
107143
end
108144
end
145+
109146
if #packageData > 0 then
110-
local data = hieararchicalPackageNodeData.createHierarchicalNodeDataByPackageList(packageData)
111-
if data and data.children then
112-
for _, child in ipairs(data.children) do
147+
if M.isHierarchicalView then
148+
local data = hieararchicalPackageNodeData.createHierarchicalNodeDataByPackageList(packageData)
149+
if data and data.children then
150+
for _, child in ipairs(data.children) do
151+
table.insert(result, M.createNode(child, self, self, self))
152+
end
153+
end
154+
else
155+
for _, child in ipairs(packageData) do
113156
table.insert(result, M.createNode(child, self, self, self))
114157
end
115158
end
@@ -125,21 +168,29 @@ function DataNode:createChildNodeList()
125168
end
126169
return result
127170
elseif kind == NodeKind.PackageRoot then
128-
local result = {}
129-
if self._nodeData.children then
130-
for _, child in ipairs(self._nodeData.children) do
131-
table.insert(result, M.createNode(child, self, self._project, self))
171+
if M.isHierarchicalView then
172+
return self:createHierarchicalPackageRootNode()
173+
else
174+
local result = {}
175+
if self._nodeData.children then
176+
for _, child in ipairs(self._nodeData.children) do
177+
table.insert(result, M.createNode(child, self, self._project, self))
178+
end
132179
end
180+
return result
133181
end
134-
return result
135182
elseif kind == NodeKind.Package then
136-
local result = {}
137-
if self._nodeData.children then
138-
for _, child in ipairs(self._nodeData.children) do
139-
table.insert(result, M.createNode(child, self, self._project, self._rootNode))
183+
if M.isHierarchicalView then
184+
return self:createHierarchicalPackageNode()
185+
else
186+
local result = {}
187+
if self._nodeData.children then
188+
for _, child in ipairs(self._nodeData.children) do
189+
table.insert(result, M.createNode(child, self, self._project, self._rootNode))
190+
end
140191
end
192+
return result
141193
end
142-
return result
143194
elseif kind == NodeKind.Folder then
144195
local result = {}
145196
if self._nodeData.children then
@@ -154,7 +205,6 @@ function DataNode:createChildNodeList()
154205
return nil
155206
end
156207
end
157-
158208
function DataNode:loadData()
159209
local kind = self:kind()
160210
if kind == NodeKind.Workspace then
@@ -176,7 +226,7 @@ function DataNode:loadData()
176226
projectUri = self._project._nodeData.uri,
177227
rootPath = self._nodeData.path,
178228
handlerIdentifier = self._nodeData.handlerIdentifier,
179-
isHierarchicalView = true,
229+
isHierarchicalView = M.isHierarchicalView,
180230
})
181231
elseif kind == NodeKind.Package then
182232
return jdtls.getPackageData({
@@ -284,21 +334,26 @@ function DataNode:revealPaths(paths)
284334
table.remove(paths, 1)
285335
end
286336
return (childNode and #paths > 0) and childNode:revealPaths(paths) or childNode
287-
elseif kind == NodeKind.PackageRoot and self._hierarchicalPackageRootNode then
288-
local hierarchicalNodeData = paths[1]
289-
---@type DataNode[]
290-
local children = self:getChildren()
291-
---@type DataNode[]?
292-
local childNode = vim.tbl_filter(function(child)
293-
return vim.startswith(hierarchicalNodeData.name, child._nodeData.name .. ".")
294-
or hierarchicalNodeData.name == child._nodeData.name
295-
end, children)
296-
---@type DataNode?
297-
childNode = (childNode and #childNode > 0) and childNode[1] or nil
298-
if childNode and not childNode._hierarchicalPackageNode then
299-
table.remove(paths, 1)
337+
elseif kind == NodeKind.PackageRoot then
338+
if self._hierarchicalPackageRootNode then
339+
local hierarchicalNodeData = paths[1]
340+
341+
---@type DataNode[]
342+
local children = self:getChildren()
343+
---@type DataNode[]?
344+
local childNode = vim.tbl_filter(function(child)
345+
return vim.startswith(hierarchicalNodeData.name, child._nodeData.name .. ".")
346+
or hierarchicalNodeData.name == child._nodeData.name
347+
end, children)
348+
---@type DataNode?
349+
childNode = (childNode and #childNode > 0) and childNode[1] or nil
350+
if childNode and not childNode._hierarchicalPackageNode then
351+
table.remove(paths, 1)
352+
end
353+
return (childNode and #paths > 0) and childNode:revealPaths(paths) or childNode
354+
else
355+
return self:baseRevealPaths(paths)
300356
end
301-
return (childNode and #paths > 0) and childNode:revealPaths(paths) or childNode
302357
elseif kind == NodeKind.Package and self._hierarchicalPackageNode then
303358
local hierarchicalNodeData = paths[1]
304359
if hierarchicalNodeData.name == self._nodeData.name then
@@ -313,7 +368,7 @@ function DataNode:revealPaths(paths)
313368
or hierarchicalNodeData.name == child._nodeData.name
314369
end, children)
315370
---@type DataNode?
316-
childNode = childNode and #childNode > 0 and childNode[1] or nil
371+
childNode = (childNode and #childNode > 0) and childNode[1] or nil
317372
return (childNode and #paths > 0) and childNode:revealPaths(paths) or nil
318373
end
319374
else
@@ -386,15 +441,19 @@ M.createNode = function(nodeData, parent, project, rootNode)
386441
return nil
387442
end
388443
local data = DataNode:new(nodeData, parent, project, rootNode)
389-
data._hierarchicalPackageRootNode = true
444+
if M.isHierarchicalView then
445+
data._hierarchicalPackageRootNode = true
446+
end
390447
return data
391448
elseif nodeData.kind == NodeKind.Package then
392449
if not parent or not project or not rootNode then
393450
vim.notify("Package node must have parent, project and root node", vim.log.levels.ERROR)
394451
return nil
395452
end
396453
local data = DataNode:new(nodeData, parent, project, rootNode)
397-
data._hierarchicalPackageNode = true
454+
if M.isHierarchicalView then
455+
data._hierarchicalPackageNode = true
456+
end
398457
return data
399458
elseif nodeData.kind == NodeKind.PrimaryType then
400459
if nodeData.metaData and nodeData.metaData[M.K_TYPE_KIND] then

0 commit comments

Comments
 (0)