summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-11 14:52:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-11 14:52:09 +0800
commit764084f9d2e8f7bb69aea8fc97453f10c9ba7f77 (patch)
treeb1db5b23a9e7569eec21f7df250fd61d0cd7a343 /server
parentf34e6c5ff4ed205881db18049c4a3db542c90b6b (diff)
downloadlua-language-server-764084f9d2e8f7bb69aea8fc97453f10c9ba7f77.zip
更新crossfile
Diffstat (limited to 'server')
-rw-r--r--server/src/core/hover/hover.lua31
-rw-r--r--server/src/core/hover/name.lua10
-rw-r--r--server/src/vm/global.lua10
-rw-r--r--server/src/vm/value.lua3
-rw-r--r--server/test/crossfile/hover.lua4
5 files changed, 34 insertions, 24 deletions
diff --git a/server/src/core/hover/hover.lua b/server/src/core/hover/hover.lua
index 2e87936c..c7aba17e 100644
--- a/server/src/core/hover/hover.lua
+++ b/server/src/core/hover/hover.lua
@@ -175,19 +175,6 @@ local function getValueHover(source, name, value, lib)
}
end
-local function getStringHover(result, lsp)
- if not result.uri then
- return nil
- end
- if not lsp or not lsp.workspace then
- return nil
- end
- local path = lsp.workspace:relativePathByUri(result.uri)
- return {
- description = ('[%s](%s)'):format(path:string(), result.uri),
- }
-end
-
local function hoverAsValue(source, lsp, select)
local lib, fullkey = findLib(source)
local value = source:bindValue()
@@ -212,14 +199,26 @@ local function hoverAsValue(source, lsp, select)
return hover
end
+local function hoverAsTargetUri(source, lsp)
+ local uri = source:get 'target uri'
+ if not lsp or not lsp.workspace then
+ return nil
+ end
+ local path = lsp.workspace:relativePathByUri(uri)
+ return {
+ description = ('[%s](%s)'):format(path:string(), uri),
+ }
+end
+
return function (source, lsp, select)
if not source then
return nil
end
- if source.type ~= 'name' then
- return
+ if source:get 'target uri' then
+ return hoverAsTargetUri(source, lsp)
end
- if source:bindValue() then
+ if source.type == 'name' and source:bindValue() then
return hoverAsValue(source, lsp, select)
end
+ return nil
end
diff --git a/server/src/core/hover/name.lua b/server/src/core/hover/name.lua
index 78c30b4d..4419e4b5 100644
--- a/server/src/core/hover/name.lua
+++ b/server/src/core/hover/name.lua
@@ -11,7 +11,15 @@ return function (source)
declarat = source
end
if not declarat then
- return source:getName() or ''
+ -- 如果声明者没有给名字,则找一个合适的名字
+ local name = value:eachInfo(function (info)
+ if info.type == 'local' or info.type == 'set' or info.type == 'return' then
+ if info.source.type == 'name' and info.source.uri == value.uri then
+ return info.source[1]
+ end
+ end
+ end)
+ return name or ''
end
local key
diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua
index 4e368641..ba5da73a 100644
--- a/server/src/vm/global.lua
+++ b/server/src/vm/global.lua
@@ -6,11 +6,11 @@ return function (lsp)
local global = lsp and lsp.globalValue
if not global then
global = createValue('table')
- end
- for name, lib in pairs(library.global) do
- if not global:rawGet(name) then
- local value = libraryBuilder.value(lib)
- global:rawSet(name, value)
+ for name, lib in pairs(library.global) do
+ if not global:rawGet(name) then
+ local value = libraryBuilder.value(lib)
+ global:rawSet(name, value)
+ end
end
end
if lsp then
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 8124b484..a3aad7a6 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -235,6 +235,9 @@ function mt:mergeValue(value)
if value._lib then
self._lib = value._lib
end
+ if value.uri then
+ self.uri = value.uri
+ end
end
function mt:addInfo(tp, source, ...)
diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua
index 03f3c6d5..ffa89bc0 100644
--- a/server/test/crossfile/hover.lua
+++ b/server/test/crossfile/hover.lua
@@ -72,8 +72,8 @@ function TEST(data)
local sourceVM = lsp:loadVM(sourceUri)
assert(sourceVM)
local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
- local result, source = core.findSource(sourceVM, sourcePos)
- local hover = core.hover(result, source, lsp)
+ local source = core.findSource(sourceVM, sourcePos)
+ local hover = core.hover(source, lsp)
assert(hover)
if data.hover.description then
data.hover.description = data.hover.description:gsub('%$ROOT%$', ws:uriEncode(ROOT):gsub('%%', '%%%%'))