LuaLS / LuaLS/lua-language-server

Returning module type from require wrapper

Abierto
#1,245 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement
Lenguaje dominante
Lua
Estrellas
4.4k
Forks
442
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el wrapper custom_require y el matcher de plugins existente descrito en el issue; después, sigue cómo los tipos de módulo y los "specials" resuelven los parámetros. Se considera terminado cuando el wrapper infiere el tipo de módulo devuelto a partir de su segundo argumento sin depender de un reemplazo de texto que rompe el resaltado de sintaxis.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
lua
Área
devtools
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.