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

Conversation

NyakoFox
Copy link
Contributor

@NyakoFox NyakoFox commented Jun 13, 2025

Auto-require always adds the require function specifically. However, it's common in projects to have their own special require functions, like import or include -- so this PR adds a configuration option which lets you change what it imports.

Lua.completion.requireFunction defaults to "require". I think I did this right?

This is open as a draft because I'm unable to test this -- I don't fully understand the environment or how to debug this project. If someone could test this, it'd be great. (The built exe did nothing when ran, unlike the exe included in VSCode... not really sure what's happening there.)

Auto-require always adds the `require` function specifically. However,
it's common in projects to have their own special `require` functions,
like `import` or `include` -- so this PR adds a configuration option
which lets you change what it imports.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a configurable option to customize the auto-require insertion function, allowing users to override the default "require" with alternatives such as "import" or "include".

  • Updated autoRequire logic to fetch the function name from configuration
  • Added corresponding configuration entry in the template and updated documentation and locales
  • Updated changelog to highlight the new setting

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
script/core/command/autoRequire.lua Uses config to dynamically set the require function in auto-require
script/config/template.lua Adds a new configuration setting for the require function
locale/*/setting.lua Updates locale files with a new setting; translations need completing
doc/*/config.md Documents the new configuration option
changelog.md Updates changelog with new setting information
Comments suppressed due to low confidence (2)

script/core/command/autoRequire.lua:123

  • Consider adding unit tests to verify that the auto-require functionality correctly uses the configured function name instead of a hard-coded value.
local requireName = config.get(uri, "Lua.completion.requireFunction")

locale/zh-tw/setting.lua:182

  • Update the TODO translation in this locale to provide a proper translated string for clarity.
config.completion.requireFunction        = -- TODO: need translate!

@carsakiller
Copy link
Collaborator

I believe runtime.special already allows users to specify an alternative name for require, such as import or include.

I think it would make more sense to build this functionality into that setting, rather than adding a whole new setting.

@NyakoFox
Copy link
Contributor Author

runtime.special exists to make variables act like certain other variables -- the user should use these two together, but I don't think they should be the same setting. You can make multiple variables act like require with runtime.special or make one variable act like another which isn't require, but this PR adds a setting for specifically the auto-require system which doesn't have much to do with runtime.special.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants