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

Unknown references through addon namespaces #31

Closed
Arxareon opened this issue Apr 29, 2022 · 6 comments
Closed

Unknown references through addon namespaces #31

Arxareon opened this issue Apr 29, 2022 · 6 comments
Labels
bug Something isn't working EmmyLua EmmyLua annotations

Comments

@Arxareon
Copy link

Hey!

I'm communicating between different files of my addons through the provided addon namespaces. Previously, annotations and references were pulled through the namespace so I could Ctrl+click to jump to a function shared in the namespace from one file to another or I could see the EmmyLua annotation on a function defined in another file for instance.

More specifically, I use a global table shared between addons, which contains subtables with version keys. A specific key is shared in the addon namespace so all files of the addon can access the specific subtable of that global table with that key (if multiple addons are on the same version, they can access the same subtable with the identical key - that's the idea in a nutshell).

Now, this functionality is broken. I'm not sure if it was broken by the main Lua extension of sumneko or WoW API specifically.

Example:

Code in file 1:

--Addon identifier name, namespace table
local addonNameSpace, ns = ...

--This is a hello
ns.Hello = function() end

--This is a global hello
Hello = function() end

Code in file 2:

--Addon identifier name, namespace table
local addonNameSpace, ns = ...

ns.Hello()

Hello()

Annotation and jump to definition doesn't work when it's through the namespace table:
image

Annotation and jump to definition does work when it's global (as it did previously with the namespace as well):
image

It might be related to this issue, I'm not sure: #28 (comment)

@Ketho Ketho added bug Something isn't working EmmyLua EmmyLua annotations labels May 1, 2022
@Ketho
Copy link
Owner

Ketho commented May 1, 2022

This is indeed a pretty glaring issue. The addon namespace appears to be properly supported by IntelliJ EmmyLua but not in Sumneko's implementation.

As in you can only define it once with ---@class and all the other files with ---@type can only read from it.

file1.lua

---@class ns
local _, ns = ...
ns.test = "banana"

file2.lua

---@type ns
local _, ns = ...
ns.hello = "world"

file3.lua

---@type ns
local _, ns = ...

print(ns.test)
print(ns.hello)

vscode
image

intellij
image

I will need to make an issue for Sumneko to support this behavior.

@Arxareon
Copy link
Author

Arxareon commented May 2, 2022

Thanks for looking into it & for letting Sumneko know!
Not sure what was changed or exactly when, but it definitely was working before.

@Arxareon
Copy link
Author

A suggestion for anyone who have a hard time with this issue:
A temporary solution is to roll back Sumneko's Lua extension to version 2.6.8 for the time being.
image
image

@Ketho
Copy link
Owner

Ketho commented May 25, 2022

I'll paste the solution Sumneko gave: using @class multiple times (when you need to make it mutable).

  • file1.lua
---@class ns
local _, ns = ...
ns.foo = "bar"
  • file2.lua
---@class ns
local _, ns = ...
ns.fruit = "banana"

@Ketho Ketho closed this as completed May 25, 2022
@Arxareon
Copy link
Author

Arxareon commented May 25, 2022


Edit:

I'll paste the solution Sumneko gave: using @class multiple times (when you need to make it mutable).

  • file1.lua
---@class ns
local _, ns = ...
ns.foo = "bar"
  • file2.lua
---@class ns
local _, ns = ...
ns.fruit = "banana"

@Ketho I see you've closed the issue while I was writing up this reply. When you got the time, could you please take a look at my write-up below since I can't seem to be able to get it working again for me with my code. 😁


Glad to see there's a solution, but I have to follow up on Sumneko's response with a question here:
So, in my case I have this structure:

File 1:

--Addon identifier name, namespace table
local addonNameSpace, ns = ...

--Version string
ns.WidgetToolsVersion = "1.4"

--Global WidgetTools table containing toolbox subtables for each respective WidgetTools version (WidgetToolbox["version_string"])
if not WidgetToolbox then WidgetToolbox = {} end

--Create the global reference subtable for the current version
if not WidgetToolbox[ns.WidgetToolsVersion] then

	--Create Toolbox
	WidgetToolbox[ns.WidgetToolsVersion] = {}

	---Dump an object and its contents to the in-game chat
	---@param object any Object to dump out
	WidgetToolbox[ns.WidgetToolsVersion].Dump = function(object)
		--Stuff..
	end

	--More stuff..
end

File 2:

--Addon name, namespace
local addonNameSpace, ns = ...
local _, addon = GetAddOnInfo(addonNameSpace)

--WidgetTools reference
local wt = WidgetToolbox[ns.WidgetToolsVersion]

wt.Dump()

As is, wt.Dump() is unknown.


I don't quite know how to get the annotations from Dump's definition from one file to the other through the subtable at the version key within the global table. By adding @class descriptions I can only get the type to go through:

File 1:

---Create Toolbox
---@class WidgetToolbox
---@field Dump function (Even if I put something here, it doesn't show - but I'd want the details annotations to appear including @param, @return and more)
WidgetToolbox[ns.WidgetToolsVersion] = {}

File 2:

---WidgetTools reference
---@class WidgetToolbox
local wt = WidgetToolbox[ns.WidgetToolsVersion]

Gives me this:
image


Previously, in Sumneko's Lua version 2.6.8, I'd see this (even without having any @class definitions added):
image


I could just revert to 2.6.8 and continue using that, but what my question is, how could I restore this functionality for the structure I built? (It might be overengineered but I have good reasons to have built the toolbox like this and it's been working for me quite well.)

@Ketho
Copy link
Owner

Ketho commented May 25, 2022

I could just revert to 2.6.8 and continue using that, but what my question is, how could I restore this functionality for the structure I built?

I honestly have no idea, this is way over my head. That would be a question for Sumneko, and I suppose you would have to keep using 2.6.8 otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working EmmyLua EmmyLua annotations
Projects
None yet
Development

No branches or pull requests

2 participants