File tree Expand file tree Collapse file tree 4 files changed +100
-9
lines changed
Expand file tree Collapse file tree 4 files changed +100
-9
lines changed Original file line number Diff line number Diff line change 22
33## 3.6.22
44* ` FIX ` [ #2038 ]
5+ * ` FIX ` [ #2042 ]
56
7+ [ #2042 ] : https://github.com/LuaLS/lua-language-server/issues/2042
68[ #2038 ] : https://github.com/LuaLS/lua-language-server/issues/2038
79
810## 3.6.21
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ local files = require 'files'
33local guide = require ' parser.guide'
44local config = require ' config'
55local util = require ' utility'
6+ local lookback = require ' core.look-backward'
67
78local keyWordMap = {
89 { ' do' , function (info , results )
@@ -372,17 +373,35 @@ end"
372373 else
373374 newText = ' ::continue::'
374375 end
376+ local additional = {}
377+
378+ local word = lookback .findWord (info .state .lua , guide .positionToOffset (info .state , info .start ) - 1 )
379+ if word ~= ' goto' then
380+ additional [# additional + 1 ] = {
381+ start = info .start ,
382+ finish = info .start ,
383+ newText = ' goto ' ,
384+ }
385+ end
386+
387+ local hasContinue = guide .eachSourceType (mostInsideBlock , ' label' , function (src )
388+ if src [1 ] == ' continue' then
389+ return true
390+ end
391+ end )
392+
393+ if not hasContinue then
394+ additional [# additional + 1 ] = {
395+ start = endPos ,
396+ finish = endPos ,
397+ newText = newText ,
398+ }
399+ end
375400 results [# results + 1 ] = {
376401 label = ' goto continue ..' ,
377402 kind = define .CompletionItemKind .Snippet ,
378- insertText = " goto continue" ,
379- additionalTextEdits = {
380- {
381- start = endPos ,
382- finish = endPos ,
383- newText = newText ,
384- }
385- }
403+ insertText = " continue" ,
404+ additionalTextEdits = additional ,
386405 }
387406 return true
388407 end }
Original file line number Diff line number Diff line change 720720--- 遍历所有指定类型的source
721721--- @param ast parser.object
722722--- @param type string
723- --- @param callback fun ( src : parser.object )
723+ --- @param callback fun ( src : parser.object ): any
724724--- @return any
725725function m .eachSourceType (ast , type , callback )
726726 local cache = getSourceTypeCache (ast )
Original file line number Diff line number Diff line change @@ -4114,3 +4114,73 @@ f({
41144114 kind = define .CompletionItemKind .Text ,
41154115 },
41164116}
4117+
4118+ TEST [[
4119+ while true do
4120+ continue<??>
4121+ end
4122+ ]]
4123+ {
4124+ {
4125+ label = ' continue' ,
4126+ kind = define .CompletionItemKind .Keyword ,
4127+ },
4128+ {
4129+ label = ' goto continue ..' ,
4130+ kind = define .CompletionItemKind .Snippet ,
4131+ additionalTextEdits = {
4132+ {
4133+ start = 10004 ,
4134+ finish = 10004 ,
4135+ newText = ' goto ' ,
4136+ },
4137+ {
4138+ start = 20000 ,
4139+ finish = 20000 ,
4140+ newText = ' ::continue::\n ' ,
4141+ },
4142+ }
4143+ },
4144+ }
4145+
4146+ TEST [[
4147+ while true do
4148+ goto continue<??>
4149+ end
4150+ ]]
4151+ {
4152+ {
4153+ label = ' continue' ,
4154+ kind = define .CompletionItemKind .Keyword ,
4155+ },
4156+ {
4157+ label = ' goto continue ..' ,
4158+ kind = define .CompletionItemKind .Snippet ,
4159+ additionalTextEdits = {
4160+ {
4161+ start = 20000 ,
4162+ finish = 20000 ,
4163+ newText = ' ::continue::\n ' ,
4164+ }
4165+ }
4166+ },
4167+ }
4168+
4169+ TEST [[
4170+ while true do
4171+ goto continue<??>
4172+ ::continue::
4173+ end
4174+ ]]
4175+ {
4176+ {
4177+ label = ' continue' ,
4178+ kind = define .CompletionItemKind .Keyword ,
4179+ },
4180+ {
4181+ label = ' goto continue ..' ,
4182+ kind = define .CompletionItemKind .Snippet ,
4183+ additionalTextEdits = {
4184+ }
4185+ },
4186+ }
You can’t perform that action at this time.
0 commit comments