Skip to content

Commit ee476c7

Browse files
committed
fix #937
1 parent 01fbaf6 commit ee476c7

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# changelog
22

3+
## 2.6.4
4+
* `FIX` [#937](https://github.com./sumneko/lua-language-server/issues/937)
5+
36
## 2.6.3
47
`2022-1-25`
58
* `FIX` new files are not loaded correctly

script/core/completion/completion.lua

+24-17
Original file line numberDiff line numberDiff line change
@@ -1221,13 +1221,20 @@ end
12211221

12221222
---@async
12231223
local function tryWord(state, position, triggerCharacter, results)
1224+
if triggerCharacter == '('
1225+
or triggerCharacter == '#'
1226+
or triggerCharacter == ','
1227+
or triggerCharacter == '{' then
1228+
return
1229+
end
12241230
local text = state.lua
12251231
local offset = guide.positionToOffset(state, position)
12261232
local finish = lookBackward.skipSpace(text, offset)
12271233
local word, start = lookBackward.findWord(text, offset)
12281234
local startPos
12291235
if not word then
1230-
return nil
1236+
word = ''
1237+
startPos = position
12311238
else
12321239
startPos = guide.offsetToPosition(state, start - 1)
12331240
end
@@ -1241,17 +1248,17 @@ local function tryWord(state, position, triggerCharacter, results)
12411248
else
12421249
local parent, oop = findParent(state, startPos)
12431250
if parent then
1244-
if not hasSpace then
1245-
checkField(state, word, startPos, position, parent, oop, results)
1246-
end
1251+
checkField(state, word, startPos, position, parent, oop, results)
12471252
elseif isFuncArg(state, position) then
12481253
checkProvideLocal(state, word, startPos, results)
12491254
checkFunctionArgByDocParam(state, word, startPos, results)
12501255
else
12511256
local afterLocal = isAfterLocal(state, startPos)
1252-
local stop = checkKeyWord(state, startPos, position, word, hasSpace, afterLocal, results)
1253-
if stop then
1254-
return
1257+
if triggerCharacter ~= nil then
1258+
local stop = checkKeyWord(state, startPos, position, word, hasSpace, afterLocal, results)
1259+
if stop then
1260+
return
1261+
end
12551262
end
12561263
if not hasSpace then
12571264
if afterLocal then
@@ -1265,7 +1272,7 @@ local function tryWord(state, position, triggerCharacter, results)
12651272
end
12661273
end
12671274
end
1268-
if not hasSpace then
1275+
if not hasSpace and (#results == 0 or word ~= '') then
12691276
checkCommon(state, word, position, results)
12701277
end
12711278
end
@@ -1282,15 +1289,15 @@ local function trySymbol(state, position, results)
12821289
return nil
12831290
end
12841291
local startPos = guide.offsetToPosition(state, start)
1285-
if symbol == '.'
1286-
or symbol == ':' then
1287-
local parent, oop = findParent(state, startPos)
1288-
if parent then
1289-
tracy.ZoneBeginN 'completion.trySymbol'
1290-
checkField(state, '', startPos, position, parent, oop, results)
1291-
tracy.ZoneEnd()
1292-
end
1293-
end
1292+
--if symbol == '.'
1293+
--or symbol == ':' then
1294+
-- local parent, oop = findParent(state, startPos)
1295+
-- if parent then
1296+
-- tracy.ZoneBeginN 'completion.trySymbol'
1297+
-- checkField(state, '', startPos, position, parent, oop, results)
1298+
-- tracy.ZoneEnd()
1299+
-- end
1300+
--end
12941301
if symbol == '(' then
12951302
checkFunctionArgByDocParam(state, '', startPos, results)
12961303
end

test/completion/common.lua

+7
Original file line numberDiff line numberDiff line change
@@ -3067,3 +3067,10 @@ require '<??>'
30673067
(function (results)
30683068
assert(#results == 11, require 'utility'.dump(results))
30693069
end)
3070+
3071+
TEST [[
3072+
AAA = 1
3073+
3074+
<??>
3075+
]]
3076+
(EXISTS)

test/completion/init.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local core = require 'core.completion'
22
local files = require 'files'
33
local catch = require 'catch'
4+
local guide = require 'parser.guide'
45

56
EXISTS = {'EXISTS'}
67

@@ -68,12 +69,17 @@ function TEST(script)
6869
local newScript, catched = catch(script, '?')
6970

7071
files.setText('', newScript)
71-
local inputPos = catched['?'][1][1]
72+
local state = files.getState('')
73+
local inputPos = catched['?'][1][2]
7274
if ContinueTyping then
7375
local triggerCharacter = script:sub(inputPos - 1, inputPos - 1)
7476
core.completion('', inputPos, triggerCharacter)
7577
end
76-
local triggerCharacter = script:sub(inputPos, inputPos)
78+
local offset = guide.positionToOffset(state, inputPos)
79+
local triggerCharacter = script:sub(offset, offset)
80+
if triggerCharacter == '\n' then
81+
triggerCharacter = nil
82+
end
7783
local result = core.completion('', inputPos, triggerCharacter)
7884

7985
if not expect then

0 commit comments

Comments
 (0)