diff options
Diffstat (limited to 'script/core/completion/keyword.lua')
-rw-r--r-- | script/core/completion/keyword.lua | 35 |
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 } |