diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-10-12 17:09:12 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-10-12 17:09:12 +0800 |
commit | f73fe1369a79344394bf258df1782b9aafe4eff5 (patch) | |
tree | 632ad1c240d9a5f8f46d0e2958243a81e0264871 /script/core/command | |
parent | 2c6db7286b64e8ff59b3d36e7898211c4633fc7f (diff) | |
download | lua-language-server-f73fe1369a79344394bf258df1782b9aafe4eff5.zip |
fix #729
Diffstat (limited to 'script/core/command')
-rw-r--r-- | script/core/command/autoRequire.lua | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/script/core/command/autoRequire.lua b/script/core/command/autoRequire.lua index b485fcb1..56096c55 100644 --- a/script/core/command/autoRequire.lua +++ b/script/core/command/autoRequire.lua @@ -6,6 +6,18 @@ local client = require 'client' local lang = require 'language' local guide = require 'parser.guide' +local function inComment(state, pos) + for _, comm in ipairs(state.comms) do + if comm.start <= pos and comm.finish >= pos then + return true + end + if comm.start > pos then + break + end + end + return false +end + local function findInsertRow(uri) local text = files.getText(uri) local state = files.getState(uri) @@ -17,6 +29,9 @@ local function findInsertRow(uri) } local hasFounded for i = 0, #lines do + if inComment(state, guide.positionOf(i, 0)) then + goto CONTINUE + end local ln = lines[i] local lnText = text:match('[^\r\n]*', ln) if not lnText:find('require', 1, true) then @@ -43,6 +58,7 @@ local function findInsertRow(uri) fmt.col = eqPos end end + ::CONTINUE:: end return 0, fmt end |