diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-10-20 15:40:50 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-10-20 15:40:50 +0800 |
commit | 6897e265fef6b0a43f5f2a6355fd0ef300b72692 (patch) | |
tree | 96cd5a99dbd87a406faaa0aaaf72644cd5f51c16 | |
parent | 437bae522a28cd0def7427edb0484d56e4834c7b (diff) | |
download | lua-language-server-6897e265fef6b0a43f5f2a6355fd0ef300b72692.zip |
fix #1642
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 11 | ||||
-rw-r--r-- | script/core/look-backward.lua | 2 | ||||
-rw-r--r-- | script/parser/guide.lua | 3 | ||||
-rw-r--r-- | test/completion/common.lua | 31 |
5 files changed, 44 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md index 23da8fa2..4057bce8 100644 --- a/changelog.md +++ b/changelog.md @@ -43,6 +43,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`. * `FIX` [#1606] * `FIX` [#1608] * `FIX` [#1637] +* `FIX` [#1642] [#1177]: https://github.com/sumneko/lua-language-server/issues/1177 [#1458]: https://github.com/sumneko/lua-language-server/issues/1458 @@ -58,6 +59,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`. [#1608]: https://github.com/sumneko/lua-language-server/issues/1608 [#1626]: https://github.com/sumneko/lua-language-server/issues/1626 [#1637]: https://github.com/sumneko/lua-language-server/issues/1637 +[#1642]: https://github.com/sumneko/lua-language-server/issues/1642 ## 3.5.6 `2022-9-16` diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index d27ff0ad..39f95ddf 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -364,7 +364,7 @@ local function checkModule(state, word, position, results) if not locals[stemName] and not vm.hasGlobalSets(state.uri, 'variable', stemName) and not globals[stemName] - and stemName:match '^[%a_][%w_]*$' + and stemName:match(guide.namePatternFull) and matchKey(word, stemName) then local targetState = files.getState(uri) if not targetState then @@ -422,8 +422,11 @@ local function checkModule(state, word, position, results) end local function checkFieldFromFieldToIndex(state, name, src, parent, word, startPos, position) - if name:match '^[%a_][%w_]*$' then - return nil + if name:match(guide.namePatternFull) then + if not name:match '[\x80-\xff]' + or config.get(state.uri, 'Lua.runtime.unicodeName') then + return nil + end end local textEdit, additionalTextEdits local startOffset = guide.positionToOffset(state, startPos) @@ -726,7 +729,7 @@ local function checkCommon(state, word, position, results) end end end - for str, offset in state.lua:gmatch '([%a_][%w_]+)()' do + for str, offset in state.lua:gmatch('(' .. guide.namePattern .. ')()') do if #results >= 100 then results.incomplete = true break diff --git a/script/core/look-backward.lua b/script/core/look-backward.lua index d90c4fff..508b57eb 100644 --- a/script/core/look-backward.lua +++ b/script/core/look-backward.lua @@ -37,7 +37,7 @@ end function m.findWord(text, offset) for i = offset, 1, -1 do - if not text:sub(i, i):match '[%w_]' then + if not text:sub(i, i):match '[%w_\x80-\xff]' then if i == offset then return nil end diff --git a/script/parser/guide.lua b/script/parser/guide.lua index e8a53240..391dd3ad 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -81,6 +81,9 @@ local m = {} m.ANY = {"<ANY>"} +m.namePattern = '[%a_\x80-\xff][%w_\x80-\xff]*' +m.namePatternFull = '^' .. m.namePattern .. '$' + local blockTypes = { ['while'] = true, ['in'] = true, diff --git a/test/completion/common.lua b/test/completion/common.lua index c63ffa7a..38104d41 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -1107,6 +1107,37 @@ z<??> config.set(nil, 'Lua.runtime.version', 'Lua 5.4') TEST [[ +中文字段 = 1 + +中文<??> +]] +{ + { + label = '中文字段', + kind = define.CompletionItemKind.Enum, + textEdit = { + start = 20000, + finish = 20006, + newText = '_ENV["中文字段"]', + }, + }, +} + +config.set(nil, 'Lua.runtime.unicodeName', true) +TEST [[ +中文字段 = 1 + +中文<??> +]] +{ + { + label = '中文字段', + kind = define.CompletionItemKind.Enum, + }, +} +config.set(nil, 'Lua.runtime.unicodeName', false) + +TEST [[ io.close(1, <??>) ]] (nil) |