diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-22 18:12:58 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-22 18:12:58 +0800 |
commit | 40b6da834d649828cea1a9f59b69657264a8c3c5 (patch) | |
tree | 950888727a0016047d812b21832302511f863502 /server/src/core | |
parent | a69fc879a80f05c7bf27e98d14462bb0a0cbde38 (diff) | |
download | lua-language-server-40b6da834d649828cea1a9f59b69657264a8c3c5.zip |
自动处理引号
Diffstat (limited to 'server/src/core')
-rw-r--r-- | server/src/core/completion.lua | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index ecb7a90c..8f481b4f 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -518,24 +518,43 @@ local function searchSource(vm, source, word, callback, pos) end end -local function buildTextEdit(start, finish, str) +local function buildTextEdit(start, finish, str, quo) + local text, lquo, rquo + if quo == '"' then + text = str:gsub('\r', '\\r'):gsub('\n', '\\n'):gsub('"', '\\"') + lquo = quo + rquo = quo + elseif quo == "'" then + text = str:gsub('\r', '\\r'):gsub('\n', '\\n'):gsub("'", "\\'") + lquo = quo + rquo = quo + else + lquo = quo + rquo = ']' .. lquo:sub(2, -2) .. ']' + while str:find(rquo, 1, true) do + lquo = '[=' .. quo:sub(2) + rquo = ']' .. lquo:sub(2, -2) .. ']' + end + text = str + end return { label = str, + filterText = str, textEdit = { - start = start + 1, - finish = finish - 1, - newText = ('%q'):format(str), + start = start + #quo, + finish = finish - #quo, + newText = text, }, additionalTextEdits = { { start = start, - finish = start, - newText = '', + finish = start + #quo - 1, + newText = lquo, }, { - start = finish, + start = finish - #quo + 1, finish = finish, - newText = '', + newText = rquo, }, } } @@ -556,7 +575,7 @@ local function searchInRequire(vm, select, source, callback) return end for _, str in ipairs(list) do - local data = buildTextEdit(source.start, source.finish, str) + local data = buildTextEdit(source.start, source.finish, str, source[2]) data.documentation = map[str] callback(str, nil, CompletionItemKind.Reference, data) end |