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

Improvements to @see and @source #1344

Closed
carsakiller opened this issue Jul 18, 2022 · 5 comments
Closed

Improvements to @see and @source #1344

carsakiller opened this issue Jul 18, 2022 · 5 comments
Labels
enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)
Milestone

Comments

@carsakiller
Copy link
Collaborator

carsakiller commented Jul 18, 2022

The Problem

In its current state, @see is relatively useless. It does not actually show up on hover and is currently only really useful if you actually go to the definition of whatever is being defined. Even though http is highlighted in the below image, hovering it does nothing and it has no function. This is okay for referring to a function within the same file but is severely lacking when it comes to libraries.

--- helpers.lua ---

---GET some URL
---@param url string
---@see http
local function get(url)
    local headers = {Authorization = "ABCDEFG"}
    http.get(url, headers)
end

get("localhost")

image

Besides it not really being visible, it is lacking in usability as it is only good for plain text as far as I can tell. I think it would be super useful if it could be used to link to other files in the workspace (relative to the definition file).

Proposal

EDIT: View my comment below for a more complete solution.

--- helpers.lua ---

---GET some URL
---@param url string
---@see [http Class](workspace/path/to/http)
local function get(url)
    local headers = {Authorization = "ABCDEFG"}
    http.get(url, headers)
end

get("localhost")

image

Note that the file extension is not included in the path, I think it would be helpful if the .lua file extension were assumed as a default so workspace/path/to/http.lua could be linked to through workspace/path/to/http. Should there be multiple @see tags, I think it should display one per line:
image

As a bonus, it would be useful if while typing out the path to another file in the workspace, autocompletions were provided as seen below while using the TypeScript extension. This is a nice quality of life feature as it would make it easier to get the path right but is not necessary.
image

@carsakiller
Copy link
Collaborator Author

Just saw the new @source tag, that should probably also allow linking to files in the workspace as explained above. It isn't too helpful if you absolutely link to a source and when someone else opens the file the path doesn't match and an error is thrown.

@sumneko sumneko added enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) labels Jul 18, 2022
@carsakiller
Copy link
Collaborator Author

Another feature for this that I could see being very useful is linking to an actual function within a file.

---@see http.get
function get(url) end

This would require the text after @see to be parsed and then we would have to find the definition of the symbol (like how the "Go To Definition" command works).

Clicking on the link in the hover window would then go to the definition of the selected class/function/etc.

This is probably the better way to implement it seeing as there is also @source now. My thinking goes like this:

I want to link to the function I am wrapping

Use @see:

---@see class.function
function myWrapper() end

I want to link to a website where I got this code from

Use @source:

---@source https://example.com
function fromTheInternet() end

So @see is used for linking within this project or to a library defined in the extension's settings and @source is for linking a URL to a website.

@carsakiller carsakiller changed the title Improvements to @see Improvements to @see and @source Jul 24, 2022
@sumneko sumneko added this to the 3.6.0 milestone Sep 19, 2022
@sumneko
Copy link
Collaborator

sumneko commented Sep 19, 2022

source is an internally used annotation, you can pretend it doesn't exist. Perhaps a better name would be shadow .

@carsakiller
Copy link
Collaborator Author

Now I am really confused as to what @source does 😄. Do you have an example in the server you could link to?

I think a better name would just be @link or @url then for an annotation that lets you link to a website.

@sumneko
Copy link
Collaborator

sumneko commented Sep 20, 2022

It is used for jumping to another language, for example:

---@source lmathlib.c:220:11
function math.max(...) end

math.max(1, 2)

When requesting goto definition for math.max, it will jump into lmathlib.c instead of lua file.

This is a private feature for $/api/report of https://marketplace.visualstudio.com/items?itemName=CppCXY.emmylua-unity

sumneko added a commit that referenced this issue Nov 2, 2022
@sumneko sumneko closed this as completed in 02dd5b6 Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)
Projects
None yet
Development

No branches or pull requests

2 participants