summaryrefslogtreecommitdiff
path: root/script-beta/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-09 17:29:00 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-09 17:29:00 +0800
commitd1ca1c8add2b122eb9b558d3c185f34de001e971 (patch)
tree4abcdbf6f8034ae80b2d376c36fcb01ea340f7ff /script-beta/core
parentb40b95f5aaba8da1aedbcfdea184ab7ba109c5a8 (diff)
downloadlua-language-server-d1ca1c8add2b122eb9b558d3c185f34de001e971.zip
hover 支持 require 路径
Diffstat (limited to 'script-beta/core')
-rw-r--r--script-beta/core/definition.lua11
-rw-r--r--script-beta/core/hover/description.lua43
-rw-r--r--script-beta/core/hover/init.lua7
3 files changed, 55 insertions, 6 deletions
diff --git a/script-beta/core/definition.lua b/script-beta/core/definition.lua
index 865fc7cb..5f16ad84 100644
--- a/script-beta/core/definition.lua
+++ b/script-beta/core/definition.lua
@@ -58,14 +58,17 @@ local function checkRequire(source, offset, callback)
if type(literal) ~= 'string' then
return
end
- local name = func.special
- if name == 'require' then
+ local lib = vm.getLibrary(func)
+ if not lib then
+ return
+ end
+ if lib.name == 'require' then
local result = workspace.findUrisByRequirePath(literal, true)
for _, uri in ipairs(result) do
callback(uri)
end
- elseif name == 'dofile'
- or name == 'loadfile' then
+ elseif lib.name == 'dofile'
+ or lib.name == 'loadfile' then
local result = workspace.findUrisByFilePath(literal, true)
for _, uri in ipairs(result) do
callback(uri)
diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua
new file mode 100644
index 00000000..1a6f19ca
--- /dev/null
+++ b/script-beta/core/hover/description.lua
@@ -0,0 +1,43 @@
+local vm = require 'vm'
+local ws = require 'workspace'
+local furi = require 'file-uri'
+local files = require 'files'
+
+local function asString(source)
+ local literal = vm.getLiteral(source)
+ if type(literal) ~= 'string' then
+ return nil
+ end
+ local parent = source.parent
+ if parent and parent.type == 'callargs' then
+ local result
+ local call = parent.parent
+ local node = call.node
+ local lib = vm.getLibrary(node)
+ if not lib then
+ return
+ end
+ if lib.name == 'require' then
+ result = ws.findUrisByRequirePath(literal, true)
+ elseif lib.name == 'dofile'
+ or lib.name == 'loadfile' then
+ result = ws.findUrisByFilePath(literal, true)
+ end
+ if result and #result > 0 then
+ for i, uri in ipairs(result) do
+ local path = furi.decode(uri)
+ if files.eq(path:sub(1, #ws.path), ws.path) then
+ path = path:sub(#ws.path + 1):gsub('^[/\\]*', '')
+ end
+ result[i] = ('[%s](%s)'):format(path, uri)
+ end
+ return table.concat(result, '\n')
+ end
+ end
+end
+
+return function (source)
+ if source.type == 'string' then
+ return asString(source)
+ end
+end
diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua
index 34a1afae..63129c3e 100644
--- a/script-beta/core/hover/init.lua
+++ b/script-beta/core/hover/init.lua
@@ -2,6 +2,7 @@ local files = require 'files'
local guide = require 'parser.guide'
local vm = require 'vm'
local getLabel = require 'core.hover.label'
+local getDesc = require 'core.hover.description'
local util = require 'utility'
local function getHoverAsFunction(source)
@@ -54,9 +55,11 @@ end
local function getHoverAsValue(source)
local label = getLabel(source, source)
+ local desc = getDesc(source)
return {
- label = label,
- source = source,
+ label = label,
+ description = desc,
+ source = source,
}
end