LuaLS / LuaLS/lua-language-server

Returning module type from require wrapper

Aperta
#1,245 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement
Lingua principale
Lua
Stelle
4.4k
Fork
442
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I cannot figure out a way to make a function return the type information of a module.
Basically, we have a wrapper function for require, which takes 2 params, the first being the repository, the second being the module name.
It's a weird legacy thing we have to deal with in our code.
I was just wondering how I can annotate that function to return the module type of the second parameter.
It can basically ignore the first parameter. I've added paths to the library & paths etc... and the typing does work when specifying using normal require, just not the custom wrapper.

essentially the code of the wrapping function (not exact, but like I said, the first param can be ignored):

function custom_require(repo, modname)
    return require(modname)
end

I was hoping it could do something similar to the following annotation, but I have not been able to do so.

---@param repo string
---@param modname string
---@return module<modname>

The only way I've got it to work functionally is to use the plugin feature to replace the text, but this screws up the colouring / highlighting of the entire file.

plugin matcher: "()local([^\n]+)custom_require%([^\n,]+,([^\n%)]+)%)()"
with "---@module " .. mod .. "\nlocal" .. varDec .. "require(" .. mod .. ")". (where varDec is the second group match, and mod is the third, the first being the position)

And the "specials" don't help in this case, as that tries to use the first param, not second.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il wrapper custom_require e il plugin matcher esistente descritto nell’issue, quindi segui come i tipi di modulo e gli "specials" risolvono i parametri. Il lavoro è completato quando il wrapper deduce il tipo del modulo restituito dal suo secondo argomento senza affidarsi a una sostituzione di testo che rompe l’evidenziazione della sintassi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
lua
Ambito
devtools
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.