LuaLS / LuaLS/lua-language-server
Returning module type from require wrapper
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Lua
- Sterne
- 4.4k
- Forks
- 442
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem custom_require-Wrapper und dem im Issue beschriebenen vorhandenen Plugin-Matcher und verfolge anschließend, wie Modultypen und „specials“ Parameter auflösen. Als abgeschlossen gilt die Aufgabe, wenn der Wrapper den zurückgegebenen Modultyp aus seinem zweiten Argument ableitet, ohne auf Textersetzung zurückzugreifen, die die Syntaxhervorhebung beeinträchtigt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100