diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/completion.lua | 27 | ||||
-rw-r--r-- | server/src/core/document_symbol.lua | 37 |
2 files changed, 51 insertions, 13 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 92a93552..f5444e67 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -327,6 +327,28 @@ local function searchSource(vm, source, word, callback) end end +local function searchInRequire(vm, select, source, callback) + if select ~= 1 then + return + end + if not vm.lsp or not vm.lsp.workspace then + return + end + if source.type ~= 'string' then + return + end + local list = vm.lsp.workspace:matchPath(vm.uri, source[1]) + for _, str in ipairs(list) do + callback(str, nil, CompletionItemKind.File, { + textEdit = { + start = source.start, + finish = source.finish, + newText = ('%q'):format(str), + } + }) + end +end + local function searchCallArg(vm, source, word, callback, pos) local results = {} for _, src in ipairs(vm.sources) do @@ -387,6 +409,11 @@ local function searchCallArg(vm, source, word, callback, pos) end end end + + -- 搜索特殊函数 + if lib.special == 'require' then + searchInRequire(vm, select, source, callback) + end end local function searchAllWords(vm, source, word, callback) diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua index 47389ec2..dd18ac23 100644 --- a/server/src/core/document_symbol.lua +++ b/server/src/core/document_symbol.lua @@ -31,7 +31,7 @@ local SymbolKind = { TypeParameter = 26, } -local function buildLocal(source, callback) +local function buildLocal(vm, source, callback) local loc = source:bindLocal() local value = loc:getInitValue() local hvr = hover(source) @@ -47,15 +47,19 @@ local function buildLocal(source, callback) kind = SymbolKind.Variable end local valueSource = value.source - if valueSource.start == 0 then + if valueSource.start == 0 or value.uri ~= vm.uri then valueSource = source end + local name = hvr.name + if vm.uri ~= value.uri then + name = tostring(source[1] or '') + end -- 由于范围不允许交叉,为了支持 local x, y, z = 1, 2, 3 的形式 -- 范围只能限定在变量上 -- 而 local function xx() 的形式范围会包含整个 function if source.start > valueSource.start then callback { - name = hvr.name, + name = name, detail = hvr.label:gsub('[\r\n]', ''), kind = kind, range = { valueSource.start, valueSource.finish }, @@ -64,7 +68,7 @@ local function buildLocal(source, callback) } else callback { - name = hvr.name, + name = name, detail = hvr.label:gsub('[\r\n]', ''), kind = kind, range = { source.start, source.finish }, @@ -74,7 +78,7 @@ local function buildLocal(source, callback) end end -local function buildSet(source, callback) +local function buildSet(vm, source, callback) if source:bindLocal() then return end @@ -97,12 +101,19 @@ local function buildSet(source, callback) kind = SymbolKind.Object end local valueSource = value.source + if valueSource.start == 0 or value.uri ~= vm.uri then + valueSource = source + end + local name = hvr.name + if vm.uri ~= value.uri then + name = tostring(source[1] or '') + end -- 由于范围不允许交叉,为了支持 x, y, z = 1, 2, 3 的形式 -- 范围只能限定在变量上 -- 而 function xx() 的形式范围会包含整个 function if source.start > valueSource.start then callback { - name = hvr.name, + name = name, -- 前端不支持多行 detail = hvr.label:gsub('[\r\n]', ''), kind = kind, @@ -112,7 +123,7 @@ local function buildSet(source, callback) } else callback { - name = hvr.name, + name = name, -- 前端不支持多行 detail = hvr.label:gsub('[\r\n]', ''), kind = kind, @@ -123,7 +134,7 @@ local function buildSet(source, callback) end end -local function buildReturn(source, callback) +local function buildReturn(vm, source, callback) local value = source:bindFunction() if not value then return @@ -144,18 +155,18 @@ local function buildReturn(source, callback) } end -local function buildSource(source, callback) +local function buildSource(vm, source, callback) if source:action() == 'local' then - buildLocal(source, callback) + buildLocal(vm, source, callback) return end if source:action() == 'set' then - buildSet(source, callback) + buildSet(vm, source, callback) return end if source.type == 'return' then for _, src in ipairs(source) do - buildReturn(src, callback) + buildReturn(vm, src, callback) end return end @@ -197,7 +208,7 @@ return function (vm) local symbols = {} for _, source in ipairs(vm.sources) do - buildSource(source, function (data) + buildSource(vm, source, function (data) symbols[#symbols+1] = data end) end |