diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-27 17:50:38 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-27 17:50:38 +0800 |
commit | 9474261f54ae620a853856f9adce0083ce66dec7 (patch) | |
tree | 96a8d98a7216092ef5fbc58507e078425a3ea762 /server/src | |
parent | 927928f3585342dbb3c8960fe7158e25e6536126 (diff) | |
download | lua-language-server-9474261f54ae620a853856f9adce0083ce66dec7.zip |
居然不能吃之前的字符
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/matcher/completion.lua | 40 | ||||
-rw-r--r-- | server/src/matcher/hover.lua | 4 | ||||
-rw-r--r-- | server/src/method/textDocument/completion.lua | 22 |
3 files changed, 49 insertions, 17 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index ba57532f..18f5c366 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -269,9 +269,13 @@ local function searchInArg(vm, inCall, inString, callback) for _, enum in ipairs(lib.enums) do if enum.name == name and enum.enum then if inString then - callback(enum.enum, CompletionItemKind.EnumMember, nil, enum.description) + callback(enum.enum, CompletionItemKind.EnumMember, { + documentation = enum.description + }) else - callback(('%q'):format(enum.enum), CompletionItemKind.EnumMember, nil, enum.description) + callback(('%q'):format(enum.enum), CompletionItemKind.EnumMember, { + documentation = enum.description + }) end end end @@ -391,7 +395,7 @@ end local function makeList(source) local list = {} local mark = {} - local function callback(var, defualt, detail, documentation) + local function callback(var, defualt, data) local key if type(var) == 'string' then key = var @@ -402,20 +406,16 @@ local function makeList(source) return end mark[key] = true + data = data or {} + list[#list+1] = data if var == key then - list[#list+1] = { - label = key, - kind = defualt, - detail = detail, - documentation = documentation, - } + data.label = var + data.kind = defualt else - list[#list+1] = { - label = var.key, - kind = getKind(var, defualt), - detail = detail or getDetail(var), - documentation = documentation or getDocument(var, source), - } + data.label = var.key + data.kind = getKind(var, defualt) + data.detail = data.detail or getDetail(var) + data.documentation = data.documentation or getDocument(var, source) end end return list, callback @@ -461,7 +461,15 @@ local function searchSpecial(vm, pos, callback) end table.insert(name, 1, key) end - callback(table.concat(name, '.') .. '+1', CompletionItemKind.Snippet) + local label = table.concat(name, '.') .. '+1' + -- TODO 把index实例化才能拿到正确的位置 + callback(label, CompletionItemKind.Snippet, { + textEdit = { + start = source.start + 1, + finish = source.finish + 1, + newText = ('%s] = '):format(label), + } + }) end end diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua index 900f9227..b0f194d1 100644 --- a/server/src/matcher/hover.lua +++ b/server/src/matcher/hover.lua @@ -183,8 +183,10 @@ local function buildValueName(result, source) key = tostring(declarat[1]) elseif func.type == 'function' then key = '' - else + elseif type(result.key) == 'string' then key = result.key + else + key = '' end local parentName = declarat.parentName diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua index b866d18c..3a8a2e6b 100644 --- a/server/src/method/textDocument/completion.lua +++ b/server/src/method/textDocument/completion.lua @@ -1,5 +1,20 @@ local matcher = require 'matcher' +local function posToRange(lines, start, finish) + local start_row, start_col = lines:rowcol(start) + local finish_row, finish_col = lines:rowcol(finish) + return { + start = { + line = start_row - 1, + character = start_col - 1, + }, + ['end'] = { + line = finish_row - 1, + character = finish_col - 1, + }, + } +end + return function (lsp, params) local uri = params.textDocument.uri local vm, lines = lsp:loadVM(uri) @@ -8,6 +23,7 @@ return function (lsp, params) end -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1) + log.debug(table.dump(params.position)) local items = matcher.completion(vm, position) if not items then return nil @@ -17,10 +33,16 @@ return function (lsp, params) end for i, item in ipairs(items) do item.sortText = ('%04d'):format(i) + if item.textEdit then + item.textEdit.range = posToRange(lines, item.textEdit.start, item.textEdit.finish) + item.textEdit.start = nil + item.textEdit.finish = nil + end end local response = { isIncomplete = true, items = items, } + log.debug(table.dump(response)) return response end |