summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/command/autoRequire.lua12
-rw-r--r--test/command/auto-require.lua18
3 files changed, 25 insertions, 6 deletions
diff --git a/changelog.md b/changelog.md
index e0fd3a10..796cc74c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 2.4.6
+* `FIX` [#744](https://github.com/sumneko/lua-language-server/issues/744)
* `FIX` [#748](https://github.com/sumneko/lua-language-server/issues/748)
## 2.4.5
diff --git a/script/core/command/autoRequire.lua b/script/core/command/autoRequire.lua
index 56096c55..aa641967 100644
--- a/script/core/command/autoRequire.lua
+++ b/script/core/command/autoRequire.lua
@@ -27,7 +27,7 @@ local function findInsertRow(uri)
quot = '"',
col = nil,
}
- local hasFounded
+ local row
for i = 0, #lines do
if inComment(state, guide.positionOf(i, 0)) then
goto CONTINUE
@@ -35,16 +35,16 @@ local function findInsertRow(uri)
local ln = lines[i]
local lnText = text:match('[^\r\n]*', ln)
if not lnText:find('require', 1, true) then
- if hasFounded then
- return i, fmt
+ if row then
+ break
end
if not lnText:match '^local%s'
and not lnText:match '^%s*$'
and not lnText:match '^%-%-' then
- return i, fmt
+ break
end
else
- hasFounded = true
+ row = i + 1
local lpPos = lnText:find '%('
if lpPos then
fmt.pair = true
@@ -60,7 +60,7 @@ local function findInsertRow(uri)
end
::CONTINUE::
end
- return 0, fmt
+ return row or 0, fmt
end
local function askAutoRequire(visiblePaths)
diff --git a/test/command/auto-require.lua b/test/command/auto-require.lua
index c2c0935f..8543a6ab 100644
--- a/test/command/auto-require.lua
+++ b/test/command/auto-require.lua
@@ -70,4 +70,22 @@ local aaaaaa = require 'aaa'
text = 'local test = require \'test\'\n'
}
+TEST [[
+local offset
+local space_size
+
+---@class A
+---@field a string
+---@field b string
+local M = {}
+
+---@return A
+function M.new()
+end
+]] 'test' {
+ start = 0,
+ finish = 0,
+ text = 'local test = require "test"\n'
+}
+
client.editText = originEditText