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

Implement @external tag for External Types #143

Merged
merged 5 commits into from
Jul 13, 2024

Conversation

YetAnotherClown
Copy link
Collaborator

@YetAnotherClown YetAnotherClown commented Jun 7, 2024

Resolves #8

This implements a simple @external <name> <url> tag for linking to External Types.

In this implementation, @external is a tag which can be defined in any doc comment, and then used in any doc comment.

The url argument simply links to any external documentation page, e.g. https://eryn.io/roblox-lua-promise/api/Promise.

Notable Changes

  • The passing test all_tags was updated to include the usage of the external type. A new passing test external_types was added to test the new external tag.
  • Name conflicts with the @class and @external tag are now reported as an error.
  • Added tests for name conflicts.

Example

--- @class MyClass
--- A sample class.
local MyClass = {}
MyClass.__index = MyClass

--[=[
	This is a function that will return a [Promise].

	@method returnAPromise
	@within MyClass
	@external Promise https://eryn.io/roblox-lua-promise/api/Promise
	@return Promise -- The Promise it returns
]=]
function MyClass:returnAPromise()
	-- Returns a roblox-lua-promise
end

--- @prop promise Promise
--- @within MyClass
--- I can also use the Promise type here!

@evaera
Copy link
Owner

evaera commented Jun 10, 2024

I'm not sure this matches the original vision for the @external tag. I don't think it should need to be associated with a class. Rather, it's just a name that is ultimately hyperlinked on the docs website, similar to how all of the Roblox classes are hyperlinked. Just a mapping of names to links.

@YetAnotherClown
Copy link
Collaborator Author

@evaera If you could find some time to share more on the original vision for the @external tag I would be happy to revise my implementation. I tried looking for any previous discussion on it prior, but I wasn't able to find anything. Thank you.

@evaera
Copy link
Owner

evaera commented Jun 10, 2024

Just what's specified in the issue, it's pretty simple. No need for @class or anything else. The external names should just turn into a list of additional names, like the Roblox classes are today, which are hyperlinked when they appear in the typical type positions where we do hyperlinks now.

@YetAnotherClown YetAnotherClown marked this pull request as draft June 10, 2024 20:28
@YetAnotherClown YetAnotherClown marked this pull request as ready for review July 6, 2024 12:24
@YetAnotherClown
Copy link
Collaborator Author

The dependency on the @class tag has been removed, the @external tag can now be used on any doc comment. The PR Description and the Documentation in the PR has been updated to reflect this.

@evaera
Copy link
Owner

evaera commented Jul 11, 2024

Excellent work, thank you. I noticed that we have a "don't do this" warning for defining multiple external types with the same name. Would it be possible to simply make this error instead? I believe we already error if you define multiple classes of the same name.

Also, does it work when you define an external type by itself in a doc comment? Like:

--[=[
@external test example.com
]=]

..with no other class, function, type, etc. associated. I didn't see an example like this in the tests.

@YetAnotherClown
Copy link
Collaborator Author

Just tested it, external types by themselves in a doc comment like your example will fail, expecting an explicit kind tag. Do you expect this to work? Currently external types are stored on doc entries as a vector called external_types, I would have to find another way to output the external types from the Extractor.

I also just tested having multiple classes of the same name, it doesn't error for me. I can implement something though to support warning for both classes and external tags if they have the same name.

@evaera
Copy link
Owner

evaera commented Jul 11, 2024

I think that erroring if there are name conflicts makes the most sense, since it’s invalid and is likely a mistake. We have other errors for things that are invalid (I guess not for multiple classes of the same name though, but we probably should have had that to begin with).

And yeah, I think it would be useful for those to work without having to be attached to a doc entry of another kind. I think we have an issue open for being able to put multiple doc comments in one comment. So that would be separate work, but would allow you to put multiple external tags in one block. For now, I think having external tags be their own kind of doc comment is best

@YetAnotherClown
Copy link
Collaborator Author

Added functionality for erroring on name conflicts with any tag we specify, I just set it to @class and @external. Added tests for it, fixed the other tests that broke because of this.

@evaera
Copy link
Owner

evaera commented Jul 13, 2024

Looks good!

@YetAnotherClown YetAnotherClown merged commit 441fbcd into evaera:master Jul 13, 2024
1 check passed
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.

External types
2 participants