From b947086c5b2db7899c692878234a279aff4dd321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 17 Mar 2021 17:06:07 +0800 Subject: completion: improve `then .. end` --- script/core/keyword.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'script/core/keyword.lua') diff --git a/script/core/keyword.lua b/script/core/keyword.lua index 5c5e291c..3ce9e045 100644 --- a/script/core/keyword.lua +++ b/script/core/keyword.lua @@ -1,5 +1,6 @@ local define = require 'proto.define' local guide = require 'core.guide' +local files = require 'files' local keyWordMap = { {'do', function (hasSpace, isExp, results) @@ -256,12 +257,20 @@ until $1" end return false end}, - {'then', function (hasSpace, isExp, results, text, start) - local first = text:match('%S+%s+(%S+)', start) + ---@param text string + {'then', function (hasSpace, isExp, results, text, start, uri) + local lines = files.getLines(uri) + local pos, first = text:match('%S+%s+()(%S+)', start) if first == 'end' or first == 'else' or first == 'elseif' then - return false + local startRow = guide.positionOf(lines, start) + local finishRow = guide.positionOf(lines, pos) + local startSp = text:match('^%s*', lines[startRow].start) + local finishSp = text:match('^%s*', lines[finishRow].start) + if startSp == finishSp then + return false + end end if not hasSpace then results[#results+1] = { -- cgit v1.2.3