Skip to content

Commit d8759ca

Browse files
committed
hover supports detail level
1 parent 8d3a4c8 commit d8759ca

File tree

8 files changed

+35
-25
lines changed

8 files changed

+35
-25
lines changed

script/cli/doc/export.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ end
197197

198198
export.makeDocObject['function'] = function(source, obj, has_seen)
199199
obj.args = export.documentObject(source.args, has_seen)
200-
obj.view = getLabel(source, source.parent.type == 'setmethod')
200+
obj.view = getLabel(source, source.parent.type == 'setmethod', 1)
201201
local _, _, max = vm.countReturnsOfFunction(source)
202202
if max > 0 then obj.returns = {} end
203203
for i = 1, max do

script/core/completion/completion.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ end
277277
---@async
278278
local function buildDesc(source)
279279
local desc = markdown()
280-
local hover = getHover.get(source)
280+
local hover = getHover.get(source, 1)
281281
desc:add('md', hover)
282282
desc:splitLine()
283283
desc:add('lua', getSnip(source))

script/core/hover/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local guide = require 'parser.guide'
99
local wssymbol = require 'core.workspace-symbol'
1010

1111
---@async
12-
local function getHover(source)
12+
local function getHover(source, level)
1313
local md = markdown()
1414
local defMark = {}
1515
local labelMark = {}
@@ -32,7 +32,7 @@ local function getHover(source)
3232
defMark[def] = true
3333

3434
if checkLable then
35-
local label = getLabel(def, oop)
35+
local label = getLabel(def, oop, level)
3636
if not labelMark[tostring(label)] then
3737
labelMark[tostring(label)] = true
3838
md:add('lua', label)
@@ -126,7 +126,7 @@ local accept = {
126126
}
127127

128128
---@async
129-
local function getHoverByUri(uri, position)
129+
local function getHoverByUri(uri, position, level)
130130
local ast = files.getState(uri)
131131
if not ast then
132132
return nil

script/core/hover/label.lua

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ local function asDocTypeName(source)
4242
end
4343

4444
---@async
45-
local function asValue(source, title)
45+
---@param level integer
46+
local function asValue(source, title, level)
4647
local name = buildName(source, false) or ''
4748
local ifr = vm.getInfer(source)
4849
local type = ifr:view(guide.getUri(source))
4950
local literal = ifr:viewLiterals()
50-
local cont = buildTable(source)
51+
local cont = buildTable(source, level)
5152
local pack = {}
5253
pack[#pack+1] = title
5354
pack[#pack+1] = name .. ':'
@@ -73,7 +74,8 @@ local function asValue(source, title)
7374
end
7475

7576
---@async
76-
local function asLocal(source)
77+
---@param level integer
78+
local function asLocal(source, level)
7779
local node
7880
if source.type == 'local'
7981
or source.type == 'self' then
@@ -82,20 +84,21 @@ local function asLocal(source)
8284
node = source.node
8385
end
8486
if node.type == 'self' then
85-
return asValue(source, '(self)')
87+
return asValue(source, '(self)', level)
8688
end
8789
if node.parent.type == 'funcargs' then
88-
return asValue(source, '(parameter)')
90+
return asValue(source, '(parameter)', level)
8991
elseif guide.getParentFunction(source) ~= guide.getParentFunction(node) then
90-
return asValue(source, '(upvalue)')
92+
return asValue(source, '(upvalue)', level)
9193
else
92-
return asValue(source, 'local')
94+
return asValue(source, 'local', level)
9395
end
9496
end
9597

9698
---@async
97-
local function asGlobal(source)
98-
return asValue(source, '(global)')
99+
---@param level integer
100+
local function asGlobal(source, level)
101+
return asValue(source, '(global)', level)
99102
end
100103

101104
local function isGlobalField(source)
@@ -126,11 +129,12 @@ local function isGlobalField(source)
126129
end
127130

128131
---@async
129-
local function asField(source)
132+
---@param level integer
133+
local function asField(source, level)
130134
if isGlobalField(source) then
131-
return asGlobal(source)
135+
return asGlobal(source, level)
132136
end
133-
return asValue(source, '(field)')
137+
return asValue(source, '(field)', level)
134138
end
135139

136140
local function asDocFieldName(source)
@@ -192,26 +196,27 @@ local function asNumber(source)
192196
end
193197

194198
---@async
195-
return function (source, oop)
199+
---@param level integer
200+
return function (source, oop, level)
196201
if source.type == 'function'
197202
or source.type == 'doc.type.function' then
198203
return asFunction(source, oop)
199204
elseif source.type == 'local'
200205
or source.type == 'self'
201206
or source.type == 'getlocal'
202207
or source.type == 'setlocal' then
203-
return asLocal(source)
208+
return asLocal(source, level)
204209
elseif source.type == 'setglobal'
205210
or source.type == 'getglobal' then
206-
return asGlobal(source)
211+
return asGlobal(source, level)
207212
elseif source.type == 'getfield'
208213
or source.type == 'setfield'
209214
or source.type == 'getmethod'
210215
or source.type == 'setmethod'
211216
or source.type == 'tablefield'
212217
or source.type == 'field'
213218
or source.type == 'method' then
214-
return asField(source)
219+
return asField(source, level)
215220
elseif source.type == 'string' then
216221
return asString(source)
217222
elseif source.type == 'number'

script/core/hover/table.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,18 @@ local function getNodeMap(uri, fields, keyMap)
159159
end
160160

161161
---@async
162+
---@param level integer
162163
---@return string?
163-
return function (source)
164+
return function (source, level)
165+
if level <= 0 then
166+
return nil
167+
end
164168
local uri = guide.getUri(source)
165169
local maxFields = config.get(uri, 'Lua.hover.previewFields')
166170
if maxFields <= 0 then
167171
return nil
168172
end
173+
maxFields = maxFields * level
169174

170175
local node = vm.compileNode(source)
171176
for n in node:eachObject() do

script/core/signature.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ end
4343

4444
---@async
4545
local function makeOneSignature(source, oop, index)
46-
local label = hoverLabel(source, oop)
46+
local label = hoverLabel(source, oop, 0)
4747
if not label then
4848
return nil
4949
end

script/provider/provider.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ m.register 'textDocument/hover' {
362362
return nil
363363
end
364364
local pos = converter.unpackPosition(state, params.position)
365-
local hover, source = core.byUri(uri, pos)
365+
local hover, source = core.byUri(uri, pos, 1)
366366
if not hover or not source then
367367
return nil
368368
end

test/crossfile/hover.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function TEST(expect)
5757
end
5858
end
5959

60-
local hover = core.byUri(sourceUri, sourcePos)
60+
local hover = core.byUri(sourceUri, sourcePos, 1)
6161
assert(hover)
6262
local content = tostring(hover):gsub('\r\n', '\n')
6363
assert(eq(content, expect.hover))

0 commit comments

Comments
 (0)