LuaLS / LuaLS/lua-language-server

---@class with function return question

Abierto
#2,602 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

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

Descripción

so I have this (as a mockup):
```lua
do
---@class a
local a = {}

---@generic T
---@param self a
---@param new T
---@return T
a.extend = function(self, new)
--...
return new
end
end
```
and it's supposed to be inheritance for prototypes, right, but I'm trying to make the LS think that it returns the second parameter `new` and it does that and the LS thinks that, so far so good. So this
```lua
local b = a:extend{
n = 1
}
```
will make it like this:
![p1](https://github.com/LuaLS/lua-language-server/assets/50140319/ae40c16c-62bd-4429-8c40-1c2d5190d446)
but the problem is, that if I use `---@class b` here, then it will ignore what the function returns and I get this:
![p2](https://github.com/LuaLS/lua-language-server/assets/50140319/b0535d12-35f5-49cc-8088-2ae955b32f4a)
am I missing something or is it just not possible? Though, if I separate it into two statements like this,
```lua
---@class b
local b = {
n = 1
}

b = a:extend(b)
```
then I get what I want:
![p3](https://github.com/LuaLS/lua-language-server/assets/50140319/d56f304d-8fef-46c6-baa8-45491c2829d2)
but it's not ideal, since it's two statements now and I can't use the `fun{}` syntactic sugar this way, which would be the whole reason, right. Is there a way to make it work? Also I'm unsure about how to properly word the title here

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

No se nombran archivos fuente ni pruebas. Reproduce los dos fragmentos de Lua de una línea y los dos de dos instrucciones; después, sigue la inferencia de tipos de LuaLS para declaraciones locales, anotaciones de clase, genéricos y valores de retorno de funciones. Se considera terminado cuando el comportamiento compatible está implementado y cubierto por una prueba de regresión, o cuando la limitación está documentada claramente.

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

Evaluación

Stack tecnológico
lua
Área
devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.