LuaLS / LuaLS/lua-language-server

require path with custom package.loaders

Open
#2,644 3 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

In my project I'm adding new package.loaders which means I'm able to import things that are not real files.
```lua
local bindings = require "bindings.core" -- This is not a real file
```
Any path starting with `bindings.` is treated differently. Is there a way to instruct the Lua Language Server to treat those specific requires in a special way and have them returning the right type annotation?
I'd like to not specify the @type every time I'm requiring these special packages.
```lua
---@type CoreBindings <---- I'm forced to specify the type
local bindings = require "bindings.core"
```
If there's a valid solution I'd need it to work outside of VS code. I'm running LuaLS as a standalone check.

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

Start by tracing how standalone LuaLS resolves require "bindings.core" and applies package.loaders information to type inference. Define how a configuration for the bindings. prefix would be supplied outside VS Code, then verify that the require receives CoreBindings without a repeated @type annotation.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.