Skip to content

Add configuration value for what auto-require adds #3201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -8,6 +8,7 @@
* `FIX` Prevent class methods from triggering missing-fields diagnostics
* `ADD` missing locale
* `FIX` updates the EmmyLuaCodeStyle submodule reference to a newer commit, ensuring compatibility with GCC 15
* `NEW` Setting: `Lua.completion.requireFunction`: What the auto-require completion should add (e.g. `import` instead of `require`)

## 3.14.0
`2025-4-7`
Expand Down
16 changes: 16 additions & 0 deletions doc/en-us/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ string
"@"
```

# completion.requireFunction

The function to insert when an auto-require is triggered.

## type

```ts
string
```

## default

```jsonc
"require"
```

# completion.requireSeparator

The separator used when `require`.
Expand Down
16 changes: 16 additions & 0 deletions doc/pt-br/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ string
"@"
```

# completion.requireFunction

The function to insert when an auto-require is triggered.

## type

```ts
string
```

## default

```jsonc
"require"
```

# completion.requireSeparator

The separator used when `require`.
Expand Down
16 changes: 16 additions & 0 deletions doc/zh-cn/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ string
"@"
```

# completion.requireFunction

The function to insert when an auto-require is triggered.

## type

```ts
string
```

## default

```jsonc
"require"
```

# completion.requireSeparator

`require` 时使用的分隔符。
Expand Down
16 changes: 16 additions & 0 deletions doc/zh-tw/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ string
"@"
```

# completion.requireFunction

The function to insert when an auto-require is triggered.

## type

```ts
string
```

## default

```jsonc
"require"
```

# completion.requireSeparator

`require` 時使用的分隔符。
Expand Down
2 changes: 2 additions & 0 deletions locale/en-us/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ config.completion.autoRequire =
"When the input looks like a file name, automatically `require` this file."
config.completion.showParams =
"Display parameters in completion list. When the function has multiple definitions, they will be displayed separately."
config.completion.requireFunction =
"The function to insert when an auto-require is triggered."
config.completion.requireSeparator =
"The separator used when `require`."
config.completion.postfix =
Expand Down
2 changes: 2 additions & 0 deletions locale/es-419/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ config.completion.autoRequire =
"Agrega automáticamente el `require` correspondiente cuando la entrada se parece a un nombre de archivo."
config.completion.showParams =
"Muestra los parámetros en la lista de completado. Cuando la función tiene múltiples definiciones, se mostrarán por separado."
config.completion.requireFunction = -- TODO: need translate!
"The function to insert when an auto-require is triggered."
config.completion.requireSeparator =
"Separador usado en `require`."
config.completion.postfix =
Expand Down
2 changes: 2 additions & 0 deletions locale/ja-jp/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ config.completion.autoRequire = -- TODO: need translate!
"When the input looks like a file name, automatically `require` this file."
config.completion.showParams = -- TODO: need translate!
"Display parameters in completion list. When the function has multiple definitions, they will be displayed separately."
config.completion.requireFunction = -- TODO: need translate!
"The function to insert when an auto-require is triggered."
config.completion.requireSeparator = -- TODO: need translate!
"The separator used when `require`."
config.completion.postfix = -- TODO: need translate!
Expand Down
2 changes: 2 additions & 0 deletions locale/pt-br/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ config.completion.autoRequire = -- TODO: need translate!
"When the input looks like a file name, automatically `require` this file."
config.completion.showParams = -- TODO: need translate!
"Display parameters in completion list. When the function has multiple definitions, they will be displayed separately."
config.completion.requireFunction = -- TODO: need translate!
"The function to insert when an auto-require is triggered."
config.completion.requireSeparator = -- TODO: need translate!
"The separator used when `require`."
config.completion.postfix = -- TODO: need translate!
Expand Down
2 changes: 2 additions & 0 deletions locale/zh-cn/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ config.completion.autoRequire =
"输入内容看起来是个文件名时,自动 `require` 此文件。"
config.completion.showParams =
"在建议列表中显示函数的参数信息,函数拥有多个定义时会分开显示。"
config.completion.requireFunction = -- TODO: need translate!
"The function to insert when an auto-require is triggered."
config.completion.requireSeparator =
"`require` 时使用的分隔符。"
config.completion.postfix =
Expand Down
2 changes: 2 additions & 0 deletions locale/zh-tw/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ config.completion.autoRequire =
"輸入內容看起來是個檔名時,自動 `require` 此檔案。"
config.completion.showParams =
"在建議列表中顯示函式的參數資訊,函式擁有多個定義時會分開顯示。"
config.completion.requireFunction = -- TODO: need translate!
"The function to insert when an auto-require is triggered."
config.completion.requireSeparator =
"`require` 時使用的分隔符。"
config.completion.postfix =
Expand Down
1 change: 1 addition & 0 deletions script/config/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ local template = {
},
['Lua.completion.autoRequire'] = Type.Boolean >> true,
['Lua.completion.showParams'] = Type.Boolean >> true,
['Lua.completion.requireFunction'] = Type.String >> 'require',
['Lua.completion.requireSeparator'] = Type.String >> '.',
['Lua.completion.postfix'] = Type.String >> '@',
['Lua.signatureHelp.enable'] = Type.Boolean >> true,
Expand Down
4 changes: 3 additions & 1 deletion script/core/command/autoRequire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local rpath = require 'workspace.require-path'
local client = require 'client'
local lang = require 'language'
local guide = require 'parser.guide'
local config = require 'config'

local function inComment(state, pos)
for _, comm in ipairs(state.comms) do
Expand Down Expand Up @@ -119,7 +120,8 @@ local function applyAutoRequire(uri, row, name, result, fmt, fullKeyPath)
if fmt.col and fmt.col > #text then
sp = (' '):rep(fmt.col - #text - 1)
end
text = ('local %s%s= require%s%s\n'):format(name, sp, quotedResult, fullKeyPath)
local requireName = config.get(uri, "Lua.completion.requireFunction")
text = ('local %s%s= %s%s%s\n'):format(name, sp, requireName, quotedResult, fullKeyPath)
client.editText(uri, {
{
start = guide.positionOf(row, 0),
Expand Down
Loading