summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md2
-rw-r--r--script/core/completion/completion.lua11
-rw-r--r--script/core/look-backward.lua2
-rw-r--r--script/parser/guide.lua3
-rw-r--r--test/completion/common.lua31
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)