summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-29 21:09:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-29 21:09:23 +0800
commitf04887db153e16055d67d8a2febb5c3db8fc43c0 (patch)
tree8a3a2a83c839594d1d62cc1315121785d38f7a1f /script
parent3f62ee8a93c91473de9a7e1b1612d148f92699a1 (diff)
downloadlua-language-server-f04887db153e16055d67d8a2febb5c3db8fc43c0.zip
#632
Diffstat (limited to 'script')
-rw-r--r--script/core/hover/description.lua80
-rw-r--r--script/core/hover/init.lua5
2 files changed, 51 insertions, 34 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index f0534373..576ed42a 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -10,47 +10,55 @@ local util = require 'utility'
local guide = require 'parser.guide'
local noder = require 'core.noder'
-local function asStringInRequire(source, literal)
+local function collectRequire(mode, literal)
local rootPath = ws.path or ''
+ local result, searchers
+ if mode == 'require' then
+ result, searchers = ws.findUrisByRequirePath(literal)
+ elseif mode == 'dofile'
+ or mode == 'loadfile' then
+ result = ws.findUrisByFilePath(literal)
+ end
+ if result and #result > 0 then
+ local shows = {}
+ for i, uri in ipairs(result) do
+ local searcher = searchers and searchers[uri]
+ local path = furi.decode(uri)
+ if path:sub(1, #rootPath) == rootPath then
+ path = path:sub(#rootPath + 1)
+ end
+ path = path:gsub('^[/\\]*', '')
+ if vm.isMetaFile(uri) then
+ shows[i] = ('* [[meta]](%s)'):format(uri)
+ elseif searcher then
+ searcher = searcher:sub(#rootPath + 1)
+ searcher = ws.normalize(searcher)
+ searcher = searcher:gsub('^[/\\]+', '')
+ shows[i] = ('* [%s](%s) %s'):format(path, uri, lang.script('HOVER_USE_LUA_PATH', searcher))
+ else
+ shows[i] = ('* [%s](%s)'):format(path, uri)
+ end
+ end
+ table.sort(shows)
+ local md = markdown()
+ md:add('md', table.concat(shows, '\n'))
+ return md
+ end
+end
+
+local function asStringInRequire(source, literal)
local parent = source.parent
if parent and parent.type == 'callargs' then
- local result, searchers
local call = parent.parent
local func = call.node
local libName = vm.getLibraryName(func)
if not libName then
return
end
- if libName == 'require' then
- result, searchers = ws.findUrisByRequirePath(literal)
- elseif libName == 'dofile'
- or libName == 'loadfile' then
- result = ws.findUrisByFilePath(literal)
- end
- if result and #result > 0 then
- local shows = {}
- for i, uri in ipairs(result) do
- local searcher = searchers and searchers[uri]
- local path = furi.decode(uri)
- if path:sub(1, #rootPath) == rootPath then
- path = path:sub(#rootPath + 1)
- end
- path = path:gsub('^[/\\]*', '')
- if vm.isMetaFile(uri) then
- shows[i] = ('* [[meta]](%s)'):format(uri)
- elseif searcher then
- searcher = searcher:sub(#rootPath + 1)
- searcher = ws.normalize(searcher)
- searcher = searcher:gsub('^[/\\]+', '')
- shows[i] = ('* [%s](%s) %s'):format(path, uri, lang.script('HOVER_USE_LUA_PATH', searcher))
- else
- shows[i] = ('* [%s](%s)'):format(path, uri)
- end
- end
- table.sort(shows)
- local md = markdown()
- md:add('md', table.concat(shows, '\n'))
- return md
+ if libName == 'require'
+ or libName == 'dofile'
+ or libName == 'loadfile' then
+ return collectRequire(libName, literal)
end
end
end
@@ -146,6 +154,13 @@ local function tryDocClassComment(source)
end
end
+local function tryDocModule(source)
+ if not source.module then
+ return
+ end
+ return collectRequire('require', source.module)
+end
+
local function buildEnumChunk(docType, name)
local enums = vm.getDocEnums(docType)
if not enums or #enums == 0 then
@@ -365,4 +380,5 @@ return function (source)
or tyrDocParamComment(source)
or tryDocComment(source)
or tryDocClassComment(source)
+ or tryDocModule(source)
end
diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua
index cf0da19d..784ef75d 100644
--- a/script/core/hover/init.lua
+++ b/script/core/hover/init.lua
@@ -71,14 +71,15 @@ local accept = {
['integer'] = true,
['doc.type.name'] = true,
['function'] = true,
+ ['doc.module'] = true,
}
-local function getHoverByUri(uri, offset)
+local function getHoverByUri(uri, position)
local ast = files.getState(uri)
if not ast then
return nil
end
- local source = findSource(ast, offset, accept)
+ local source = findSource(ast, position, accept)
if not source then
return nil
end