Feature Request: ability to overload the return value type
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 45/100
Línea de trabajo
Comienza rastreando cómo el servidor de lenguaje representa múltiples valores de retorno anotados y los comprueba en los sitios de llamada. Usa el ejemplo de ECS del issue como el comportamiento que se debe investigar, incluidos los casos de cero y dos valores. Se considera terminado cuando una anotación compatible puede expresar retornos multivalor de todo o nada o unidos, sin requerir el cast mostrado, y los diagnósticos están cubiertos para ambos casos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
macOS
What is the issue affecting?
Annotations
Feature request
In my game's ECS bindings I have getter functions that work like this:
---@param id integer
---@return number? inv_mass
---@return number? restitution
function ecs.get_collision_body_values(id) end
local inv_mass, restitution = ecs.get_collision_body_values(entity_id)
This calls into a native ECS implementation that either pushes the 2 return values and returns with return 2; (2 return values) or if the return values doesn't exist, push nothing and return 0; (zero return values).
This can be used in my game code like this:
local function debug_body(id)
local inv_mass, restitution = ecs.get_collision_body_values(id)
if inv_mass == nil then -- collision_body component not set, do nothing
return
end
---@cast restitution number
-- ^^ have to cast restitution number? -> number to avoid warning
print(inv_mass, restitution)
end
Would be nice if there was a way to annotate an "all or nothing" multiple return value type. E.g., a function will either return multiple return values (e.g., not number? but number) or that it will return nothing. Or I guess more generally, the ability to somehow specify a union of different multivalue return types.
FWIW, it'd be possible to return "a bunch of values" or "nothing" by using a table? return type. However, I'm trying very hard not to allocate tables in my hot game's hot paths, thus I favor concrete types and multiple return.
- Lenguaje dominante
- Lua
- Estrellas
- 4.4k
- Forks
- 442
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de LuaLS/lua-language-server
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
LuaLS/lua-language-server#1776 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
LuaLS/lua-language-server#3461 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
LuaLS/lua-language-server#3460 · 1 comentario · 1 reacción ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
LuaLS/lua-language-server#3459 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
LuaLS/lua-language-server#3458 ·
Todos los issues de LuaLS/lua-language-server
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
api7/lua-resty-saml#62 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 94/100
codymikol/multiverse.nvim#320 ·
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100