Skip to content

Commit

Permalink
fix #1642
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Oct 20, 2022
1 parent 437bae5 commit 6897e26
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand Down
11 changes: 7 additions & 4 deletions script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion script/core/look-backward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions script/parser/guide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions test/completion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,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, <??>)
]]
Expand Down

0 comments on commit 6897e26

Please sign in to comment.