Skip to content

Commit d060e87

Browse files
committed
cleanup
1 parent b1a1b3f commit d060e87

File tree

4 files changed

+41
-30
lines changed

4 files changed

+41
-30
lines changed

script/core/hover/label.lua

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,33 @@ local files = require 'files'
1111
local guide = require 'parser.guide'
1212

1313
local function asFunction(source, oop)
14-
local name
15-
name, oop = buildName(source, oop)
14+
if oop == nil then
15+
oop = guide.isOOP(source, oop)
16+
end
17+
local name = buildName(source, oop)
1618
local arg = buildArg(source, oop)
1719
local rtn = buildReturn(source)
1820
local lines = {}
19-
lines[1] = ('%s%s %s(%s)'):format(
20-
vm.isAsync(source) and 'async ' or '',
21-
oop and 'method' or 'function',
22-
name or '', arg
21+
lines[1] = string.format('%s%s %s(%s)'
22+
, vm.isAsync(source) and 'async ' or ''
23+
, oop and 'method' or 'function'
24+
, name or ''
25+
, arg
2326
)
2427
lines[2] = rtn
2528
return table.concat(lines, '\n')
2629
end
2730

28-
local function asDocFunction(source)
29-
local name = buildName(source)
30-
local arg = buildArg(source)
31-
local rtn = buildReturn(source)
31+
local function asDocFunction(source, oop)
32+
local name = buildName(source, oop)
33+
local arg = buildArg(source, oop)
34+
local rtn = buildReturn(source)
3235
local lines = {}
33-
lines[1] = ('function %s(%s)'):format(name or '', arg)
36+
lines[1] = string.format('%s%s %s(%s)'
37+
, ''
38+
, oop and 'method' or 'function'
39+
, name or ''
40+
, arg)
3441
lines[2] = rtn
3542
return table.concat(lines, '\n')
3643
end
@@ -211,7 +218,7 @@ return function (source, oop)
211218
or source.type == 'integer' then
212219
return asNumber(source)
213220
elseif source.type == 'doc.type.function' then
214-
return asDocFunction(source)
221+
return asDocFunction(source, oop)
215222
elseif source.type == 'doc.type.name' then
216223
return asDocTypeName(source)
217224
elseif source.type == 'doc.field.name' then

script/core/hover/name.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ local function asDocField(source)
6666
end
6767

6868
function buildName(source, oop)
69-
if oop == nil then
70-
oop = source.type == 'setmethod'
71-
or source.type == 'getmethod'
72-
or nil
73-
end
7469
if source.type == 'local' then
7570
return asLocal(source) or '', oop
7671
end

script/parser/guide.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,5 +1160,17 @@ function m.isInString(ast, position)
11601160
end)
11611161
end
11621162

1163+
function m.isOOP(source, oop)
1164+
if source.type == 'setmethod'
1165+
or source.type == 'getmethod' then
1166+
return true
1167+
end
1168+
if source.type == 'method'
1169+
or source.type == 'field'
1170+
or source.type == 'function' then
1171+
return m.isOOP(source.parent)
1172+
end
1173+
return false
1174+
end
11631175

11641176
return m

test/crossfile/hover.lua

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,17 @@ end
4141
function TEST(expect)
4242
files.removeAll()
4343

44-
local targetScript, targetList = catch(expect[1].content, '?')
45-
local targetUri = furi.encode(expect[1].path)
46-
47-
local sourceScript, sourceList = catch(expect[2].content, '?')
48-
local sourceUri = furi.encode(expect[2].path)
49-
50-
files.setText(targetUri, targetScript)
51-
files.setText(sourceUri, sourceScript)
52-
53-
if targetList['?'] then
54-
local targetPos = (targetList['?'][1][1] + targetList['?'][1][2]) // 2
55-
core.byUri(targetUri, targetPos)
44+
local sourcePos, sourceUri
45+
for _, file in ipairs(expect) do
46+
local script, list = catch(file.content, '?')
47+
local uri = furi.encode(file.path)
48+
files.setText(uri, script)
49+
if list['?'] then
50+
sourceUri = uri
51+
sourcePos = (list['?'][1][1] + list['?'][1][2]) // 2
52+
end
5653
end
57-
local sourcePos = (sourceList['?'][1][1] + sourceList['?'][1][2]) // 2
54+
5855
local hover = core.byUri(sourceUri, sourcePos)
5956
assert(hover)
6057
hover = tostring(hover):gsub('\r\n', '\n')

0 commit comments

Comments
 (0)