LuaLS / LuaLS/lua-language-server

[Feature request] Class-based auto-require

Open
#3,202 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

My project has some strict styling, and what we have is a system where:

  • MyClass is the sole returned class in myclass.lua, annotated and everything
  • Usage is local MyClass = import("src.myclass")

The language server has a setting for auto-requires. Unfortunately, it hardcodes the require function & is completely filename based.

I've just opened #3201 to add the import thing, but I'd like to request a setting which makes auto-requires work better with the class names, rather than being filename-based.

Ex. MyClass.something() suggests to require the file as local MyClass = import("src.myclass") rather than myclass.

We've considered either not caring (very ugly for code-style), manually fixing it every time (makes auto-requires kind of useless) or changing the filenames to be cased the same as the class (not a proper solution but a workaround -- one that would make the file structure look worse & fear for case sensitive filesystems)

As far as I can tell, this seems like a language server limitation rather than a design limitation. I would try to contribute this option myself, but this codebase seems too complicated for me to understand unfortunately...

(I just realized I opened a similar request a year ago -- I completely forgot and have closed it now.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the language server's existing auto-require setting and the related #3201 request first. The work is done when class-based suggestions can produce the requested import-style statement instead of relying only on filenames.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.