diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2024-08-15 18:48:20 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2024-08-15 18:48:20 +0800 |
commit | bed118701e6fb12e27f67d744b1895952eb24e33 (patch) | |
tree | be2ae678298eb09f31407dda5a19e48b68d18aab /script/core | |
parent | 2fe2ff371a8d2ee97a46c1b48eb421d9f8ee65ad (diff) | |
download | lua-language-server-bed118701e6fb12e27f67d744b1895952eb24e33.zip |
fix incorrect indent fixings
fix #2799
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/fix-indent.lua | 64 |
1 files changed, 13 insertions, 51 deletions
diff --git a/script/core/fix-indent.lua b/script/core/fix-indent.lua index 59adfb7b..0542e4a8 100644 --- a/script/core/fix-indent.lua +++ b/script/core/fix-indent.lua @@ -60,59 +60,20 @@ local function getIndent(state, row) return indent end -local function isInBlock(state, position) - local block = guide.eachSourceContain(state.ast, position, function(source) - if source.type == 'ifblock' - or source.type == 'elseifblock' then - if source.keyword[4] and source.keyword[4] <= position then - return true - end - end - if source.type == 'else' then - if source.keyword[2] and source.keyword[2] <= position then - return true - end - end - if source.type == 'while' then - if source.keyword[4] and source.keyword[4] <= position then - return true - end - end - if source.type == 'repeat' then - if source.keyword[2] and source.keyword[2] <= position then - return true - end - end - if source.type == 'loop' then - if source.keyword[4] and source.keyword[4] <= position then - return true - end - end - if source.type == 'in' then - if source.keyword[6] and source.keyword[6] <= position then - return true - end - end - if source.type == 'do' then - if source.keyword[2] and source.keyword[2] <= position then - return true - end - end - if source.type == 'function' then - if source.args and source.args.finish <= position then - return true - end - if not source.keyword[3] or source.keyword[3] >= position then - return true - end +---@param state parser.state +---@param pos integer +---@return parser.object +local function getBlock(state, pos) + local block + guide.eachSourceContain(state.ast, pos, function (src) + if not src.bstart then + return end - if source.type == 'table' then - if source.start + 1 == position then - return true - end + if not block or block.bstart < src.bstart then + block = src end end) - return block ~= nil + return block end local function fixWrongIndent(state, change) @@ -135,7 +96,8 @@ local function fixWrongIndent(state, change) if not util.stringStartWith(myIndent, lastIndent) then return end - if isInBlock(state, lastPosition) then + local myBlock = getBlock(state, position) + if myBlock.bstart >= lastOffset then return end |