summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/completion/keyword.lua35
-rw-r--r--script/parser/guide.lua2
2 files changed, 28 insertions, 9 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 }
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index e7eb3751..d7399b4d 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -720,7 +720,7 @@ end
--- 遍历所有指定类型的source
---@param ast parser.object
---@param type string
----@param callback fun(src: parser.object)
+---@param callback fun(src: parser.object): any
---@return any
function m.eachSourceType(ast, type, callback)
local cache = getSourceTypeCache(ast)