diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-29 15:47:31 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-29 15:47:31 +0800 |
commit | 2a795db6935b37980ba7410fa7fbe0e0fd0a562a (patch) | |
tree | f33a55a6b2fbe4c73c062c7f84067655750fa4b2 | |
parent | 7397df30ab802b6f6e3b75c6094d1c1711604937 (diff) | |
download | lua-language-server-2a795db6935b37980ba7410fa7fbe0e0fd0a562a.zip |
fix #1395
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 14 | ||||
-rw-r--r-- | script/core/look-backward.lua | 14 | ||||
-rw-r--r-- | test/completion/common.lua | 16 |
4 files changed, 38 insertions, 9 deletions
diff --git a/changelog.md b/changelog.md index 502b6fbc..1a060a3e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # changelog +## 3.5.2 +* `FIX` [#1395](https://github.com/sumneko/lua-language-server/issues/1395) + ## 3.5.1 `2022-7-26` * `NEW` supports [color](https://github.com/sumneko/lua-language-server/pull/1379) diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 09d276a6..71f38645 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1597,7 +1597,7 @@ end local function getComment(state, position) local offset = guide.positionToOffset(state, position) - local symbolOffset = lookBackward.findAnyOffset(state.lua, offset) + local symbolOffset = lookBackward.findAnyOffset(state.lua, offset, true) if not symbolOffset then return end @@ -1610,9 +1610,9 @@ local function getComment(state, position) return nil end -local function getluaDoc(state, position) +local function getLuaDoc(state, position) local offset = guide.positionToOffset(state, position) - local symbolOffset = lookBackward.findAnyOffset(state.lua, offset) + local symbolOffset = lookBackward.findAnyOffset(state.lua, offset, true) if not symbolOffset then return end @@ -2063,8 +2063,8 @@ local function tryluaDocOfFunction(doc, results) } end -local function tryluaDoc(state, position, results) - local doc = getluaDoc(state, position) +local function tryLuaDoc(state, position, results) + local doc = getLuaDoc(state, position) if not doc then return end @@ -2103,7 +2103,7 @@ local function tryComment(state, position, results) return end local word = lookBackward.findWord(state.lua, guide.positionToOffset(state, position)) - local doc = getluaDoc(state, position) + local doc = getLuaDoc(state, position) if not word then local comment = getComment(state, position) if not comment then @@ -2142,7 +2142,7 @@ local function tryCompletions(state, position, triggerCharacter, results) return end if getComment(state, position) then - tryluaDoc(state, position, results) + tryLuaDoc(state, position, results) tryComment(state, position, results) return end diff --git a/script/core/look-backward.lua b/script/core/look-backward.lua index eeee6017..8d3e3439 100644 --- a/script/core/look-backward.lua +++ b/script/core/look-backward.lua @@ -81,9 +81,19 @@ function m.findTargetSymbol(text, offset, symbol) return nil end -function m.findAnyOffset(text, offset) +---@param text string +---@param offset integer +---@param inline? boolean # 必须在同一行中(排除换行符) +function m.findAnyOffset(text, offset, inline) for i = offset, 1, -1 do - if not m.isSpace(text:sub(i, i)) then + local c = text:sub(i, i) + if inline then + if c == '\r' + or c == '\n' then + return nil + end + end + if not m.isSpace(c) then return i end end diff --git a/test/completion/common.lua b/test/completion/common.lua index 23b3eff6..997ebd14 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -3697,3 +3697,19 @@ f(<??>) kind = define.CompletionItemKind.EnumMember, }, } + +TEST [[ +-- +<??> +]] +(function (results) + assert(#results > 2) +end) + +TEST [[ +--xxx +<??> +]] +(function (results) + assert(#results > 2) +end) |