镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix: improve type narrow with literal alias param during completion and signature help - #2932

Merged
sumneko merged 4 commits into
LuaLS:masterfrom
tomlau10:fix/completion_type_narrow
Nov 5, 2024
Merged

sumneko merged 4 commits into
LuaLS:masterfrom
tomlau10:fix/completion_type_narrow

Conversation

@tomlau10

@tomlau10 tomlau10 commented Nov 3, 2024

Copy link
Copy Markdown
Contributor

This supports type narrow during completion and signature help when function params are using @alias with literal values, as requested here: #1456 (comment)

Example use case:

---@alias events.AAA
---| "AAA" # description to AAA
---@alias events.BBB
---| "BBB" # description to BBB

---@class Emitter
---@field on fun(self: self, event: events.AAA,  cb: fun(a: integer))
---@field on fun(self: self, event: events.BBB, cb: fun(b: string))
local Emitter = {}

Emitter:on('BBB', <??>) --< trigger completion will suggest `fun(b: string)`, instead of showing both

中文版

上述 issue comment 作者想用 @alias 來定義 event name,因為這樣可以對 enum value 加 description,但發現用 alias 後做 completion 時無法做 type narrow。
這個 PR 是想在做 completion 和 signature help 時,增加檢查 function param 對應的 literal values 是否符合 event name

  • 如果 function param 沒有 literal value => 無從判斷,維持原狀不會 narrow
  • 有 literal values,並且至少 1個跟 call param literal value 是 match => 允許
  • 有 literal values,但無一跟 call param literal value 是 match => 過濾掉

@sumneko
sumneko merged commit 1753f07 into LuaLS:master Nov 5, 2024
@tomlau10
tomlau10 deleted the fix/completion_type_narrow branch November 9, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants