summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/completion/completion.lua124
-rw-r--r--script/workspace/require-path.lua5
2 files changed, 75 insertions, 54 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 009b4297..64a7899a 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -363,63 +363,79 @@ local function checkModule(state, word, position, results)
goto CONTINUE
end
local path = furi.decode(uri)
- local fileName = path:match '[^/\\]*$'
- local stemName = fileName:gsub('%..+', '')
- if not locals[stemName]
- and not vm.hasGlobalSets(state.uri, 'variable', stemName)
- and not globals[stemName]
- and stemName:match '^[%a_][%w_]*$'
- and matchKey(word, stemName) then
- local targetState = files.getState(uri)
- if not targetState then
- goto CONTINUE
- end
- local targetReturns = targetState.ast.returns
- if not targetReturns then
- goto CONTINUE
- end
- local targetSource = targetReturns[1] and targetReturns[1][1]
- if not targetSource then
- goto CONTINUE
- end
- if targetSource.type ~= 'getlocal'
- and targetSource.type ~= 'table'
- and targetSource.type ~= 'function' then
- goto CONTINUE
+ local relativePath = workspace.getRelativePath(path)
+ local infos = rpath.getVisiblePath(uri, path)
+ local testedStem = { }
+ for _, sr in ipairs(infos) do
+ local pattern = sr.searcher
+ :gsub("(%p)", "%%%1")
+ :gsub("%%%?", "([%%a_][%%w_]*)")
+
+ local stemName = relativePath
+ :match(pattern)
+
+ if not stemName or testedStem[stemName] then
+ goto INNER_CONTINUE
end
- if targetSource.type == 'getlocal'
- and vm.getDeprecated(targetSource.node) then
- goto CONTINUE
- end
- results[#results+1] = {
- label = stemName,
- kind = define.CompletionItemKind.Variable,
- commitCharacters = { '.' },
- command = {
- title = 'autoRequire',
- command = 'lua.autoRequire',
- arguments = {
- {
- uri = guide.getUri(state.ast),
- target = uri,
- name = stemName,
+ testedStem[stemName] = true
+
+ if not locals[stemName]
+ and not vm.hasGlobalSets(state.uri, 'variable', stemName)
+ and not globals[stemName]
+ and stemName:match '^[%a_][%w_]*$'
+ and matchKey(word, stemName) then
+ local targetState = files.getState(uri)
+ if not targetState then
+ goto INNER_CONTINUE
+ end
+ local targetReturns = targetState.ast.returns
+ if not targetReturns then
+ goto INNER_CONTINUE
+ end
+ local targetSource = targetReturns[1] and targetReturns[1][1]
+ if not targetSource then
+ goto INNER_CONTINUE
+ end
+ if targetSource.type ~= 'getlocal'
+ and targetSource.type ~= 'table'
+ and targetSource.type ~= 'function' then
+ goto INNER_CONTINUE
+ end
+ if targetSource.type == 'getlocal'
+ and vm.getDeprecated(targetSource.node) then
+ goto INNER_CONTINUE
+ end
+ results[#results+1] = {
+ label = stemName,
+ kind = define.CompletionItemKind.Variable,
+ commitCharacters = { '.' },
+ command = {
+ title = 'autoRequire',
+ command = 'lua.autoRequire',
+ arguments = {
+ {
+ uri = guide.getUri(state.ast),
+ target = uri,
+ name = stemName,
+ },
},
},
- },
- id = stack(function () ---@async
- local md = markdown()
- md:add('md', lang.script('COMPLETION_IMPORT_FROM', ('[%s](%s)'):format(
- workspace.getRelativePath(uri),
- uri
- )))
- md:add('md', buildDesc(targetSource))
- return {
- detail = buildDetail(targetSource),
- description = md,
- --additionalTextEdits = buildInsertRequire(state, originUri, stemName),
- }
- end)
- }
+ id = stack(function () ---@async
+ local md = markdown()
+ md:add('md', lang.script('COMPLETION_IMPORT_FROM', ('[%s](%s)'):format(
+ workspace.getRelativePath(uri),
+ uri
+ )))
+ md:add('md', buildDesc(targetSource))
+ return {
+ detail = buildDetail(targetSource),
+ description = md,
+ --additionalTextEdits = buildInsertRequire(state, originUri, stemName),
+ }
+ end)
+ }
+ end
+ ::INNER_CONTINUE::
end
::CONTINUE::
end
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index aec298a6..5e3ab31a 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -41,6 +41,10 @@ local function getOnePath(uri, path, searcher)
return nil
end
+---comment
+---@param suri string
+---@param path string
+---@return rpath.SearchResult[]
function m.getVisiblePath(suri, path)
local searchers = config.get(suri, 'Lua.runtime.path')
local strict = config.get(suri, 'Lua.runtime.pathStrict')
@@ -87,6 +91,7 @@ function m.getVisiblePath(suri, path)
if head then
mySearcher = head .. searcher
end
+ ---@class rpath.SearchResult
result[#result+1] = {
searcher = mySearcher,
expect = expect,