Skip to content

Commit 6897e26

Browse files
committed
fix #1642
1 parent 437bae5 commit 6897e26

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
4343
* `FIX` [#1606]
4444
* `FIX` [#1608]
4545
* `FIX` [#1637]
46+
* `FIX` [#1642]
4647

4748
[#1177]: https://github.com/sumneko/lua-language-server/issues/1177
4849
[#1458]: https://github.com/sumneko/lua-language-server/issues/1458
@@ -58,6 +59,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
5859
[#1608]: https://github.com/sumneko/lua-language-server/issues/1608
5960
[#1626]: https://github.com/sumneko/lua-language-server/issues/1626
6061
[#1637]: https://github.com/sumneko/lua-language-server/issues/1637
62+
[#1642]: https://github.com/sumneko/lua-language-server/issues/1642
6163

6264
## 3.5.6
6365
`2022-9-16`

script/core/completion/completion.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ local function checkModule(state, word, position, results)
364364
if not locals[stemName]
365365
and not vm.hasGlobalSets(state.uri, 'variable', stemName)
366366
and not globals[stemName]
367-
and stemName:match '^[%a_][%w_]*$'
367+
and stemName:match(guide.namePatternFull)
368368
and matchKey(word, stemName) then
369369
local targetState = files.getState(uri)
370370
if not targetState then
@@ -422,8 +422,11 @@ local function checkModule(state, word, position, results)
422422
end
423423

424424
local function checkFieldFromFieldToIndex(state, name, src, parent, word, startPos, position)
425-
if name:match '^[%a_][%w_]*$' then
426-
return nil
425+
if name:match(guide.namePatternFull) then
426+
if not name:match '[\x80-\xff]'
427+
or config.get(state.uri, 'Lua.runtime.unicodeName') then
428+
return nil
429+
end
427430
end
428431
local textEdit, additionalTextEdits
429432
local startOffset = guide.positionToOffset(state, startPos)
@@ -726,7 +729,7 @@ local function checkCommon(state, word, position, results)
726729
end
727730
end
728731
end
729-
for str, offset in state.lua:gmatch '([%a_][%w_]+)()' do
732+
for str, offset in state.lua:gmatch('(' .. guide.namePattern .. ')()') do
730733
if #results >= 100 then
731734
results.incomplete = true
732735
break

script/core/look-backward.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ end
3737

3838
function m.findWord(text, offset)
3939
for i = offset, 1, -1 do
40-
if not text:sub(i, i):match '[%w_]' then
40+
if not text:sub(i, i):match '[%w_\x80-\xff]' then
4141
if i == offset then
4242
return nil
4343
end

script/parser/guide.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ local m = {}
8181

8282
m.ANY = {"<ANY>"}
8383

84+
m.namePattern = '[%a_\x80-\xff][%w_\x80-\xff]*'
85+
m.namePatternFull = '^' .. m.namePattern .. '$'
86+
8487
local blockTypes = {
8588
['while'] = true,
8689
['in'] = true,

test/completion/common.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,37 @@ z<??>
11061106

11071107
config.set(nil, 'Lua.runtime.version', 'Lua 5.4')
11081108

1109+
TEST [[
1110+
中文字段 = 1
1111+
1112+
中文<??>
1113+
]]
1114+
{
1115+
{
1116+
label = '中文字段',
1117+
kind = define.CompletionItemKind.Enum,
1118+
textEdit = {
1119+
start = 20000,
1120+
finish = 20006,
1121+
newText = '_ENV["中文字段"]',
1122+
},
1123+
},
1124+
}
1125+
1126+
config.set(nil, 'Lua.runtime.unicodeName', true)
1127+
TEST [[
1128+
中文字段 = 1
1129+
1130+
中文<??>
1131+
]]
1132+
{
1133+
{
1134+
label = '中文字段',
1135+
kind = define.CompletionItemKind.Enum,
1136+
},
1137+
}
1138+
config.set(nil, 'Lua.runtime.unicodeName', false)
1139+
11091140
TEST [[
11101141
io.close(1, <??>)
11111142
]]

0 commit comments

Comments
 (0)