summaryrefslogtreecommitdiff
path: root/script/core/keyword.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-03-17 17:06:07 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-03-17 17:06:07 +0800
commitb947086c5b2db7899c692878234a279aff4dd321 (patch)
tree73c8090c3f11bc4d340901d881bbd176d996cfb4 /script/core/keyword.lua
parentbed85ea48999b871d9ea6b3eef260dc88e4ee2cc (diff)
downloadlua-language-server-b947086c5b2db7899c692878234a279aff4dd321.zip
completion: improve `then .. end`
Diffstat (limited to 'script/core/keyword.lua')
-rw-r--r--script/core/keyword.lua15
1 files changed, 12 insertions, 3 deletions
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] = {