diff options
author | Sewbacca <sebastian.kalus@kolabnow.com> | 2022-11-18 17:45:12 +0100 |
---|---|---|
committer | Sewbacca <sebastian.kalus@kolabnow.com> | 2022-11-18 17:45:12 +0100 |
commit | 1b44530283a7388eb56faa0ad3f5e9262b205149 (patch) | |
tree | 6c115cc62e4b3d3f310f76d0cf72f1f422dfdcab /script/core/completion | |
parent | f8f9b68d3e89e602bcfe80fa18b2f5cb0846e846 (diff) | |
download | lua-language-server-1b44530283a7388eb56faa0ad3f5e9262b205149.zip |
Added complex require paths
Diffstat (limited to 'script/core/completion')
-rw-r--r-- | script/core/completion/completion.lua | 124 |
1 files changed, 70 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 |