summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-10-12 17:09:12 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-10-12 17:09:12 +0800
commitf73fe1369a79344394bf258df1782b9aafe4eff5 (patch)
tree632ad1c240d9a5f8f46d0e2958243a81e0264871
parent2c6db7286b64e8ff59b3d36e7898211c4633fc7f (diff)
downloadlua-language-server-f73fe1369a79344394bf258df1782b9aafe4eff5.zip
fix #729
-rw-r--r--changelog.md1
-rw-r--r--script/core/command/autoRequire.lua16
-rw-r--r--test/command/auto-require.lua30
3 files changed, 47 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index b8ad4ac9..08e3cae5 100644
--- a/changelog.md
+++ b/changelog.md
@@ -5,6 +5,7 @@
* `FIX` [#718](https://github.com/sumneko/lua-language-server/issues/718)
* `FIX` [#719](https://github.com/sumneko/lua-language-server/issues/719)
* `FIX` [#725](https://github.com/sumneko/lua-language-server/issues/725)
+* `FIX` [#729](https://github.com/sumneko/lua-language-server/issues/729)
* `FIX` runtime errors
## 2.4.2
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
diff --git a/test/command/auto-require.lua b/test/command/auto-require.lua
index a52662fb..c2c0935f 100644
--- a/test/command/auto-require.lua
+++ b/test/command/auto-require.lua
@@ -40,4 +40,34 @@ local aaaaaa = require 'aaa'
text = 'local test = require \'test\'\n'
}
+TEST [[
+local DEBUG = true
+local aaaaaa = require 'aaa'
+]] 'test' {
+ start = 20000,
+ finish = 20000,
+ text = 'local test = require \'test\'\n'
+}
+
+TEST [[
+-- comment
+-- comment
+local aaaaaa = require 'aaa'
+]] 'test' {
+ start = 30000,
+ finish = 30000,
+ text = 'local test = require \'test\'\n'
+}
+
+TEST [[
+--[=[
+comment chunk
+]=]
+local aaaaaa = require 'aaa'
+]] 'test' {
+ start = 40000,
+ finish = 40000,
+ text = 'local test = require \'test\'\n'
+}
+
client.editText = originEditText