Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
* `FIX` Auto-require now detects existing imports using `Lua.completion.requireFunction` (e.g. `import`) instead of `require`, so new imports use the preferred syntax and get inserted after existing ones

## 3.19.2
`2026-10-13`
Expand Down
3 changes: 2 additions & 1 deletion script/core/command/autoRequire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local function findInsertRow(uri)
if not state or not text then
return
end
local requireName = config.get(uri, "Lua.completion.requireFunction")
local lines = state.lines
local fmt = {
pair = false,
Expand All @@ -37,7 +38,7 @@ local function findInsertRow(uri)
end
local ln = lines[i]
local lnText = text:match('[^\r\n]*', ln)
if not lnText:find('require', 1, true) then
if not lnText:find(requireName, 1, true) then
if row then
break
end
Expand Down
13 changes: 13 additions & 0 deletions test/command/auto-require.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local util = require 'utility'
local files = require 'files'
local autoRequire = require 'core.command.autoRequire'
local client = require 'client'
local config = require 'config'

local findInsertRow = util.getUpvalue(autoRequire, 'findInsertRow')
local applyAutoRequire = util.getUpvalue(autoRequire, 'applyAutoRequire')
Expand Down Expand Up @@ -92,4 +93,16 @@ end
text = 'local test = require "test"\n'
}

local originRequireFunction = config.get(nil, 'Lua.completion.requireFunction')
config.set(nil, 'Lua.completion.requireFunction', 'import')
TEST [[
local modulea = import("modulea")
local moduleb = import("moduleb")
]] 'modulec' {
start = 20000,
finish = 20000,
text = 'local modulec = import("modulec")\n'
}
config.set(nil, 'Lua.completion.requireFunction', originRequireFunction)

client.editText = originEditText
Loading