summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-12-06 20:02:08 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-12-06 20:02:08 +0800
commitd060e870a5d24e3e575459a0e02d229d9234109a (patch)
treeb04b4913015fc2c1888afe386d23a8e061eb53ca
parentb1a1b3f46771ac5461182a8156452517c280b153 (diff)
downloadlua-language-server-d060e870a5d24e3e575459a0e02d229d9234109a.zip
cleanup
-rw-r--r--script/core/hover/label.lua31
-rw-r--r--script/core/hover/name.lua5
-rw-r--r--script/parser/guide.lua12
-rw-r--r--test/crossfile/hover.lua23
4 files changed, 41 insertions, 30 deletions
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index 0bb4fe89..8531ebb9 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -11,26 +11,33 @@ local files = require 'files'
local guide = require 'parser.guide'
local function asFunction(source, oop)
- local name
- name, oop = buildName(source, oop)
+ if oop == nil then
+ oop = guide.isOOP(source, oop)
+ end
+ local name = buildName(source, oop)
local arg = buildArg(source, oop)
local rtn = buildReturn(source)
local lines = {}
- lines[1] = ('%s%s %s(%s)'):format(
- vm.isAsync(source) and 'async ' or '',
- oop and 'method' or 'function',
- name or '', arg
+ lines[1] = string.format('%s%s %s(%s)'
+ , vm.isAsync(source) and 'async ' or ''
+ , oop and 'method' or 'function'
+ , name or ''
+ , arg
)
lines[2] = rtn
return table.concat(lines, '\n')
end
-local function asDocFunction(source)
- local name = buildName(source)
- local arg = buildArg(source)
- local rtn = buildReturn(source)
+local function asDocFunction(source, oop)
+ local name = buildName(source, oop)
+ local arg = buildArg(source, oop)
+ local rtn = buildReturn(source)
local lines = {}
- lines[1] = ('function %s(%s)'):format(name or '', arg)
+ lines[1] = string.format('%s%s %s(%s)'
+ , ''
+ , oop and 'method' or 'function'
+ , name or ''
+ , arg)
lines[2] = rtn
return table.concat(lines, '\n')
end
@@ -211,7 +218,7 @@ return function (source, oop)
or source.type == 'integer' then
return asNumber(source)
elseif source.type == 'doc.type.function' then
- return asDocFunction(source)
+ return asDocFunction(source, oop)
elseif source.type == 'doc.type.name' then
return asDocTypeName(source)
elseif source.type == 'doc.field.name' then
diff --git a/script/core/hover/name.lua b/script/core/hover/name.lua
index 0de13c9a..2d1e361c 100644
--- a/script/core/hover/name.lua
+++ b/script/core/hover/name.lua
@@ -66,11 +66,6 @@ local function asDocField(source)
end
function buildName(source, oop)
- if oop == nil then
- oop = source.type == 'setmethod'
- or source.type == 'getmethod'
- or nil
- end
if source.type == 'local' then
return asLocal(source) or '', oop
end
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 54e61e7f..ac773d44 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -1160,5 +1160,17 @@ function m.isInString(ast, position)
end)
end
+function m.isOOP(source, oop)
+ if source.type == 'setmethod'
+ or source.type == 'getmethod' then
+ return true
+ end
+ if source.type == 'method'
+ or source.type == 'field'
+ or source.type == 'function' then
+ return m.isOOP(source.parent)
+ end
+ return false
+end
return m
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index 86471936..82af9c32 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -41,20 +41,17 @@ end
function TEST(expect)
files.removeAll()
- local targetScript, targetList = catch(expect[1].content, '?')
- local targetUri = furi.encode(expect[1].path)
-
- local sourceScript, sourceList = catch(expect[2].content, '?')
- local sourceUri = furi.encode(expect[2].path)
-
- files.setText(targetUri, targetScript)
- files.setText(sourceUri, sourceScript)
-
- if targetList['?'] then
- local targetPos = (targetList['?'][1][1] + targetList['?'][1][2]) // 2
- core.byUri(targetUri, targetPos)
+ local sourcePos, sourceUri
+ for _, file in ipairs(expect) do
+ local script, list = catch(file.content, '?')
+ local uri = furi.encode(file.path)
+ files.setText(uri, script)
+ if list['?'] then
+ sourceUri = uri
+ sourcePos = (list['?'][1][1] + list['?'][1][2]) // 2
+ end
end
- local sourcePos = (sourceList['?'][1][1] + sourceList['?'][1][2]) // 2
+
local hover = core.byUri(sourceUri, sourcePos)
assert(hover)
hover = tostring(hover):gsub('\r\n', '\n')