Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emmylua_doc_cli: Does not render union with comments as parameter type. #134

Open
rhys-vdw opened this issue Mar 3, 2025 · 9 comments
Open

Comments

@rhys-vdw
Copy link

rhys-vdw commented Mar 3, 2025

Input:

---Called when a construction unit wants to "use his nano beams".
---
---@param unitID integer
---@param unitDefID integer
---@param action
---  | -1 # Build
---  | CMD.REPAIR # Repair
---  | CMD.RECLAIM # Reclaim
---  | CMD.RESTORE # Restore
---  | CMD.RESURRECT # Resurrect
---  | CMD.CAPTURE # Capture
---@return boolean actionAllowed
function SyncedCallins:AllowBuilderHoldFire(unitID, unitDefID, action) end

Output:

### SyncedCallins.AllowBuilderHoldFire
---
```lua
function SyncedCallins.AllowBuilderHoldFire(
  unitID: integer,
  unitDefID: integer,
  action: ()
) -> actionAllowed boolean
```





Called when a construction unit wants to "use his nano beams".
@CppCXY
Copy link
Owner

CppCXY commented Mar 3, 2025

My support for param integers does not include negative numbers, CMD.REPAIR is recognized as a type, and multiline unions should use ---| without spaces in between.

@rhys-vdw
Copy link
Author

rhys-vdw commented Mar 3, 2025

Thanks. FYI removing -1 and whitespace still yields incorrect output:

Input:

---Called when a construction unit wants to "use his nano beams".
---
---@param unitID integer
---@param unitDefID integer
---@param action
---| CMD.REPAIR # Repair
---| CMD.RECLAIM # Reclaim
---| CMD.RESTORE # Restore
---| CMD.RESURRECT # Resurrect
---| CMD.CAPTURE # Capture
---@return boolean actionAllowed
function SyncedCallins:AllowBuilderHoldFire(unitID, unitDefID, action) end

Output:

### SyncedCallins.AllowBuilderHoldFire
---
```lua
function SyncedCallins.AllowBuilderHoldFire(
  unitID: integer,
  unitDefID: integer,
  action: ()
) -> actionAllowed boolean
```

@CppCXY
Copy link
Owner

CppCXY commented Mar 3, 2025

Image

I see that I originally supported expressions with spaces, and I also mentioned that the union must is types. If the type does not exist, I will not display it.

@CppCXY
Copy link
Owner

CppCXY commented Mar 3, 2025

In the latest commit, I have supported negative numbers as a type.

@rhys-vdw
Copy link
Author

rhys-vdw commented Mar 3, 2025

Sorry I should have included CMD:

---Command constants.
---
---@enum CMD
CMD = {
	---@type 40
	REPAIR = nil,

	---@type 90
	RECLAIM = nil,

	---@type 110
	RESTORE = nil,

	---@type 125
	RESURRECT = nil,

	---@type 130
	CAPTURE = nil,
}

I have not tested your change yet, but I will.

@CppCXY
Copy link
Owner

CppCXY commented Mar 3, 2025

It seems that luals treats each enum member as a type. Currently, I do not support this.

@rhys-vdw
Copy link
Author

rhys-vdw commented Mar 3, 2025

It doesn't handle this well either: LuaLS/lua-language-server#3104

But it seems like the correct annotation.

@rhys-vdw
Copy link
Author

I've updated to a union of -1|CMD which should be correct, but now it outputs no type at all.

input:

---Called when a construction unit wants to "use his nano beams".
---
---@param unitID integer
---@param unitDefID integer
---@param action -1|CMD
---
---One of the following:
---	- `-1` build,
---	- `CMD.REPAIR` repair,
---	- `CMD.RECLAIM` reclaim,
---	- `CMD.RESTORE` restore,
---	- `CMD.RESURRECT` resurrect, or
---	- `CMD.CAPTURE` capture.
---@return boolean actionAllowed
function SyncedCallins:AllowBuilderHoldFire(unitID, unitDefID, action) end

output:

## methods

### SyncedCallins.AllowBuilderHoldFire

```lua
function SyncedCallins.AllowBuilderHoldFire(
  unitID: integer,
  unitDefID: integer,
  action
) -> actionAllowed boolean

Called when a construction unit wants to "use his nano beams".

Alternatively if I parenthesize type as (-1|CMD) I get:

function SyncedCallins.AllowBuilderHoldFire(
  unitID: integer,
  unitDefID: integer,
  action: unknown
) -> actionAllowed boolean

@rhys-vdw
Copy link
Author

Ah, I think this is a general problem with using a literal type in a union.

---@return ("left"|"right"|false) position `"left"` or `"right"` when dual screen is enabled, otherwise `false`.
function Spring.GetMiniMapDualScreen() end

See there is no false in the docs here:

```lua
function Spring.GetMiniMapDualScreen() -> position ("left"|"right")
```

@return `position` - `"left"` or `"right"` when dual screen is enabled, otherwise `false`.

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

No branches or pull requests

2 participants