summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-06-13 18:30:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-06-13 18:30:01 +0800
commit4081b303684b95ec27fd833a1cd10978d4ad5e10 (patch)
treebd286d27d262934d662926247e885b56b72bd489 /script/core
parentcda4ec3f67a93a907752cc98572f0dac9c5dd83e (diff)
downloadlua-language-server-4081b303684b95ec27fd833a1cd10978d4ad5e10.zip
more smart completion for `continue`
fix #2042
Diffstat (limited to 'script/core')
-rw-r--r--script/core/completion/keyword.lua35
1 files changed, 27 insertions, 8 deletions
diff --git a/script/core/completion/keyword.lua b/script/core/completion/keyword.lua
index e6f50242..aa0e2148 100644
--- a/script/core/completion/keyword.lua
+++ b/script/core/completion/keyword.lua
@@ -3,6 +3,7 @@ local files = require 'files'
local guide = require 'parser.guide'
local config = require 'config'
local util = require 'utility'
+local lookback = require 'core.look-backward'
local keyWordMap = {
{ 'do', function(info, results)
@@ -372,17 +373,35 @@ end"
else
newText = '::continue::'
end
+ local additional = {}
+
+ local word = lookback.findWord(info.state.lua, guide.positionToOffset(info.state, info.start) - 1)
+ if word ~= 'goto' then
+ additional[#additional+1] = {
+ start = info.start,
+ finish = info.start,
+ newText = 'goto ',
+ }
+ end
+
+ local hasContinue = guide.eachSourceType(mostInsideBlock, 'label', function (src)
+ if src[1] == 'continue' then
+ return true
+ end
+ end)
+
+ if not hasContinue then
+ additional[#additional+1] = {
+ start = endPos,
+ finish = endPos,
+ newText = newText,
+ }
+ end
results[#results+1] = {
label = 'goto continue ..',
kind = define.CompletionItemKind.Snippet,
- insertText = "goto continue",
- additionalTextEdits = {
- {
- start = endPos,
- finish = endPos,
- newText = newText,
- }
- }
+ insertText = "continue",
+ additionalTextEdits = additional,
}
return true
end }