LuaLS / LuaLS/lua-language-server
Returning module type from require wrapper
Personne n'a encore pris cette issue.
- Langage dominant
- Lua
- Étoiles
- 4.4k
- Forks
- 442
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le wrapper custom_require et le plugin matcher existant décrit dans l’issue, puis suivez la manière dont les types de modules et les « specials » résolvent les paramètres. Le travail est terminé lorsque le wrapper déduit le type du module retourné à partir de son deuxième argument sans dépendre d’un remplacement de texte qui casse la coloration syntaxique.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- lua
- Domaine
- devtools
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100