LuaLS / LuaLS/lua-language-server

@return支持多种类型

Open
#1,583 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

两个方案,大佬参考:
方案一采用语法@return ()|()|()这种

---@return (string,number)|(nil, string)
local function foo()
  do
    return 'foo', 1 --正常
  end
  do
    return nil, 'some error' --正常
  end
  do
    return nil, 1 -- 此处出错
  end
end

方案二,其实我觉得这种更直观,也便于书写

---@return string,number
---@return nil, string
local function foo()
  do
    return 'foo', 1 --正常
  end
  do
    return nil, 'some error' --正常
  end
  do
    return nil, 1 -- 此处出错
  end
end

现在的设定,下面两种定义是等效的

---@return string,number
local function foo() end

---@return string
---@return number
local function foo() end

可见,通过逗号表达式,一条@return语句就可以表达多个值类型,多条连续的@return语法应该留给更重要的多返回类型语法!优雅,简洁!个人愚见,仅供参考

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the language server's existing @return parsing and return-type validation, then compare both proposed syntaxes against the examples in the issue. Done means one agreed syntax supports multiple alternative return signatures and rejects the mismatched return shown in the example, with coverage for the existing comma-separated behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.