|
1 | 1 | local define = require 'proto.define' |
2 | 2 | local files = require 'files' |
3 | 3 | local guide = require 'parser.guide' |
| 4 | +local config = require 'config' |
| 5 | +local util = require 'utility' |
4 | 6 |
|
5 | 7 | local keyWordMap = { |
6 | 8 | { 'do', function(info, results) |
@@ -324,6 +326,66 @@ end" |
324 | 326 | end |
325 | 327 | return true |
326 | 328 | end }, |
| 329 | + { 'continue', function (info, results) |
| 330 | + local nonstandardSymbol = config.get(info.uri, 'Lua.runtime.nonstandardSymbol') |
| 331 | + if util.arrayHas(nonstandardSymbol, 'continue') then |
| 332 | + return |
| 333 | + end |
| 334 | + local version = config.get(info.uri, 'Lua.runtime.version') |
| 335 | + if version == 'Lua 5.1' then |
| 336 | + return |
| 337 | + end |
| 338 | + local mostInsideBlock |
| 339 | + guide.eachSourceContain(info.state.ast, info.start, function (src) |
| 340 | + if src.type == 'while' |
| 341 | + or src.type == 'in' |
| 342 | + or src.type == 'loop' |
| 343 | + or src.type == 'repeat' then |
| 344 | + mostInsideBlock = src |
| 345 | + end |
| 346 | + end) |
| 347 | + if not mostInsideBlock then |
| 348 | + return |
| 349 | + end |
| 350 | + -- 找一下 end 的位置 |
| 351 | + local endPos |
| 352 | + if mostInsideBlock.type == 'while' then |
| 353 | + endPos = mostInsideBlock.keyword[5] |
| 354 | + elseif mostInsideBlock.type == 'in' then |
| 355 | + endPos = mostInsideBlock.keyword[7] |
| 356 | + elseif mostInsideBlock.type == 'loop' then |
| 357 | + endPos = mostInsideBlock.keyword[5] |
| 358 | + elseif mostInsideBlock.type == 'repeat' then |
| 359 | + endPos = mostInsideBlock.keyword[3] |
| 360 | + end |
| 361 | + if not endPos then |
| 362 | + return |
| 363 | + end |
| 364 | + local endLine = guide.rowColOf(endPos) |
| 365 | + local tabStr = info.state.lua:sub( |
| 366 | + info.state.lines[endLine], |
| 367 | + guide.positionToOffset(info.state, endPos) |
| 368 | + ) |
| 369 | + local newText |
| 370 | + if tabStr:match '^[\t ]*$' then |
| 371 | + newText = ' ::continue::\n' .. tabStr |
| 372 | + else |
| 373 | + newText = '::continue::' |
| 374 | + end |
| 375 | + results[#results+1] = { |
| 376 | + label = 'goto continue ..', |
| 377 | + kind = define.CompletionItemKind.Snippet, |
| 378 | + insertText = "goto continue", |
| 379 | + additionalTextEdits = { |
| 380 | + { |
| 381 | + start = endPos, |
| 382 | + finish = endPos, |
| 383 | + newText = newText, |
| 384 | + } |
| 385 | + } |
| 386 | + } |
| 387 | + return true |
| 388 | + end } |
327 | 389 | } |
328 | 390 |
|
329 | 391 | return keyWordMap |
0 commit comments