New Script Editor Hover Tips and User-Defined Function Documentation

This is fantastic!

However, it would be nice to be able to put a strikethrough on deprecated functions like Roblox does with their deprecated ones in the auto-complete box.

So, if you have a whole big module system that many people use with many functions, it would be nice to let them know what NOT to use. Adding a deprecation message and a strikethrough to the function for the auto-complete box, would be lovely! :slight_smile:
image

For instance, it could be done like this:

--[[
-- Function description.
]]
local function dontusethisfunction(): (type checking stuff here)--

end


--[[
-- Function description.
]]
--<strikethrough>
local function dontusethisfunction()

end
--</strikethrough>
3 Likes

Please add this for variables! Right now this doesn’t work.

3 Likes

Never thought about that, that would be nice as well, since some variables do indeed have descriptions!
image

4 Likes

ngl it would be even better if non functions even had this feature

1 Like

Do you mean like variables? Well, there would be quite a mixed take on that I think, you will have some saying “That is a great idea” and you will have some that will say “Yes… But it would be quite messy. So no.”

I think it depends on how you give the description, so here’s an example of miss-using it:

-- This true or false value determines the state of the players characters collision with other players characters.
local value = true

Heres an example of using it correctly:

-- Determines Players Collision.
local value = true

So I honestly think it would work and STILL be tidy and clean if used correctly.

Also, forget to mention: There will also be some who will say, “This is pointless because you can just check what a variable does, that’s what the find feature is for.” or “This is pointless because as long as you named your variable right, a description is unnecessary”—and to that, I say, “What about module variables?” If someone is using your module, it would be nice to also give them a bit of description of what it does, regardless of name.

3 Likes

honestly i wanted this for the module variables to give them a description like this:

local module = {}


-- Fires when blah blah blah
module["OnEvent"] = {}

since it looks useful to explain them to someone whos new to your module

3 Likes

Indeed, that’s what I was saying, I completely agree with you!

3 Likes

Dont have access to bug reports, but __call metamethods don’t show function type tips and docs

local mt = {}

--[[
    test
--]]
function mt.__call(self: any, meow: "mrrp")

end

local tbl = setmetatable({}, mt)
-- doesnt show the ui that shows the function args, and the functions doc comment
tbl()

Theres a function attribute for marking functions as depreciated, its just not implemented yet.

http://rfcs.luau.org/syntax-attribute-functions-deprecated.html

1 Like

Can the user-defined function documentation be made to ignore the leading double-hypens that are, by some people’s preference (including mine), included at the end of a multi-line comment?

For example, this…

--[[
  Does all the things
--]]
function foo()
end

…produces this:
image

I’ve made multi-line comments this way forever and it kind of drives me crazy.

1 Like

I like how my functions show their descriptions and info about their parameters (which I made a habit of writing long before this update), but there’s one problem with it…

The tooltip includes line breaks, which are okay for separating the first line (which lists the function’s name and parameters, which is redundant, I know) from its description, but this also includes other line breaks, but I only add those to keep the full comment on-screen without having to scroll sideways.

This is what the tooltip looks like now; Note the random line break after “If” on its third line…


Obviously, that’s just the break in the comment, but again, if I remove that, the original comment goes off the right side, adding the scrollbar at the bottom of the script editor, which I don’t like, and try to avoid.

I wouldn’t know how this could be “fixed” without messing up other programmers’ comments that require intentional single line breaks like this, but it’ll be disappointing if the only workaround is to make my comments super long, or just accept the awkward line spacing in the pop-up.

2 Likes

Are these tips going to work for dynamic loading of modules, too?

An example would be creating one’s own library handler, for example.

Example

Library simple code:

local Modules = {}
for _, module in pairs(script:GetChildren()) do
	if not module:IsA("ModuleScript") then continue end
	Modules[module.Name] = require(Modules)
end

-- Get module by name
local function GetModule(self: any, name: string)
	return Modules[name]
end return {
	GetModule = GetModule
}

After adding a module named “ModuleScript” inside the library handler

local module = {}

-- Can you see this?
local function thisIsTest(test: number)
	
end

return module

image

Adding a typeof() does not work (which is kind of expected I would say). It would be cool if there was a way to do this though.

you could fix this with just doing this

--[[
does something when blah blah blah
]]

just remove the two - at the end of your comment

Alright, get ready, as this post is a bit long. It goes over several requested features as well as a few of my own.

Function Type Support

So, for starters, a few others mentioned it would be really nice if user documentation would also support function types, as currently there is no good way to do it.

However, adding on to what they said, beyond merely improving code organization, it would also add the additional functionality of documenting overloaded functions. As @MuffinHandler mentioned, it is currently not possible to do this.

For example, I currently have a module for creating CSG cones to model with and have begun documenting it. However, as you can see, it contains a single overloaded function for creating cones.
If documentation for function types were added, it would enabled the documentation of overloaded functions. As @Mauio64 and @vvv331 mentioned, it could be done over the type or within a type.

Example:


Note: The ConeCreator type represents the type of the Module.

Links

It would also be beneficial to include the ability to link to other instances, such as above where I mention the [UnionOperation](https://create.roblox.com/docs/reference/engine/classes/UnionOperation) class, as it would allow users to quickly click on the related links and view the documentation of the linked objects in case they needed to. Perhaps through use of a <link> tag or something.

I’m not quite sure how support for custom types could be linked, though I’m sure there’s a way.

Variables

As @Ohio_trouble350 mentioned, it would also be beneficial to be able to provide documentation for variables, as it could benefit both programmers while they are creating a program and the users of the program. It would especially help in areas where Object-Oriented Programming is used, as the objects of a class would get fleshed-out documentation that make it easier to use.

It would also be beneficial if documentation could also be done in-line with the variable for single-line comments. It makes the code more readable by having the description of the variable not getting in the way of defining new variables and thus having the variables closer together without interruption.

Example:

Special Annotations & Styling

Last but not least, special annotations for function or type documentation. Of course, the benefit the common annotations (@param, @return, @error, ect.) would bring is evident. They would format the documentation so it would be easier to both read and write and improve developers quality of life due to not having to manually format the documentation. Last but not least, they can even be styled to further enhance readability.

That isn’t to say that HTML tags aren’t useful in documentation, quite the opposite in fact. They can be, however, tedious to structure so that the documentation is easily readable.


Examples
IntelliJ JavaDoc Example

One good example of the styling that can be done with special annotations is how the IntelliJ IDE styles user documentation.

The annotation and markup tags — although no markup tags are in the image — are made to be bold and a slightly lighter color than the normal text, causing them to stand out without attracting all the attention. Then the variable, exception, and link names are made to be a different color, making them stand out from the rest of the text so they aren’t easily mistaken. Everything else is the same style, however, so it’s clear that it is description (i.e. - the actual content) while the other elements are mostly structure. And all of it fits within a neat block without the need for bulky html tags or whitespace to make it more readable, albeit the option is still there if needed.

When displaying the documentation in a tooltip, the tags help structure it and make it very readable.

As you can see, everything remains distinct, with the tags indenting their respective content text and separating it from the function description while the different coloring continues to separate the structure of the documentation from the description.

All in all, the styling and annotation tags make reading and writing the documentation a breeze.


Current Luau Documentation

The current user documentation, however, lacks distinction and could clearly benefit from adding styling and annotation tags to the documentation. Furthermore, while adding the markdown tags to format the documentation makes it more readable in the tooltip, it actively makes it less readable in the actual file.

Since the text lacks distinction, its poor readability is enhanced if the documentation is compacted.

Either way though, the tooltip is readable, although it would certainly benefit from annotations.




Potential Luau Documentation

What the documentation could look like with annotations — at least in the source code — is very simple and efficient. And it would look even better if styling was added.

The appearance of the comment/documentation block brackets doesn’t really matter since it could be anything.


One of the more interesting possibilities of special annotations is the embedded code example shown in the :WaitForChild documentation.

An interesting thing to point out is that the documentation tooltip that shows up from autocomplete seems to be just a little different than the tooltip from hovering over the method, the difference being that the code example part is missing in the latter.

Does the documentation for the built-in methods pull from different sources for the header and hover tooltip, or is it a difference in how the documentation is either processed or rendered?

Module Function Definition Hover Tooltip

This one is short and sweet. When hovering over a function that is also being defined as part of a module, the tooltip that shows the documentation doesn't show up. It would be beneficial if it did in this scenario so that the developer could quickly check how the documentation looks and make any necessary edits in an efficient manner.
Examples

Local Function Hover:
Screenshot 2024-11-25 at 11.22.56 AM
There was no difference whether it was a local or global function

Versus: Module Function Hover
Screenshot 2024-11-25 at 11.29.27 AM
As you can see, no tooltip pops up above. It does, however, pop up when the cursor is hovering over the function reference from the module:
Screenshot 2024-11-25 at 11.27.49 AM
There was no difference whether it was a module function or method


Summary

A list of the features/improvements mentioned:

  • Support for documenting function types
  • Support for links in documentation
  • Support for variable documentation
  • Support for in-line variable documentation
  • Support for Special Annotations
  • Module Function Definition Hover Tooltip

I know this is a lot, but I believe they are all features that would improve user documentation. This feature is already off to a great start, so keep up the good work!

18 Likes

So no links no code example?? ! pleaase

1 Like

I agree with everything, and would like to put emphasis on this part specifically. Right now, making nice looking tooltips = making less readable comments.

Claire’s example here is nice, but in practice it feels more like a workaround than a solution… It’d be much better to just have the tags be less prominent so writing more comments to summarize documentation isn’t necessary.

Compare this list of HTML-style tagged params:
image

To this list of simple annotated params:
image

The first looks great in the tooltip but will make me and my team squint in the editor for a good few seconds. The second is alright in the tooltip, but more importantly, much easier to parse visually than the first in the editor.

2 Likes

I use my solution because it stands out, can be folded into a multi-line comment and makes the specificity of each parameter’s tooltip absolute - you can’t get confused or forget which parameter you’re on nearly as easily. It’s a trait I picked up from XML in C#.

The @param solution is nice for sure, but developers will more often than not make it so that you only know what the parameter does - not it’s name. If you have two parameters of the same type that do generally similar - or the same - things for two different objects, then you can get confused later on when you revisit something.

If you use param, my method, or whichever you prefer, please just remember to add the parameter name and a dash! We’ve all had a late night where we’re trying to get one last feature in and can’t quite think straight without explicit documentation!

1 Like

Yeah the param example could definitely be improved, I just used it to show comments with less visual clutter

1 Like

Something we’re missing that I believe ROBLOX’s own internal docs can do is the stepping of tooltips for whichever parameter you’re on. It’s not even consistent with their APIs. Some have it, some don’t.

My API documentation looks nice in bulk…


But ROBLOX’s can be stepped to only the current parameter/argument… which both doesn’t show up without scrolling down and doesn’t work correctly sometimes. (WHY?!)

2 Likes

I agree! I noticed this the other day while working on something and thought it would be really nice if it also did it for user defined functions. However, it will likely remain impossible unless we are given a method for explicitly identifying/defining parameters, like the proposed @param. Otherwise it would just seem like additional documentation of the function.

I’m a bit confused by what you mean here, as I’ve never read documentation where the parameter being described was not listed. Additionally, in the example given, it does mention the name of the parameter being described. Did you just mean that it was hard to read due to the name not being separated (by a dash or colon) from the rest of the parameter description?