Thread Tools Display Modes
12/19/23, 04:24 PM   #1
vsrs_au
Join Date: Dec 2022
Posts: 17
How to get VSCode to recognise XML objects in LUA files?

I'm using VSCode, with some LUA plugins, to write a ESOUI addon, and I've managed to configure the sumneko.lua VSCode extension to recognise ESOUI global functions and constants (e.g. events). It still flags any objects defined in the addon's XML files as unknown, though. Is there any way to configure VSCode to find these definitions?

VSCode also flags the constant (?) "GuiRoot" as unknown in the addon code line
Code:
FooAddonIndicator:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
so in this line, both "FooAddonIndicator" (defined in the XML file) and "GuiRoot" are flagged.

I have both the addon framework and the api-lua-intellij autocomplete directories in the workspace.libraries search list for the VSCode sumneko.lua extension, but it still won't find "GuiRoot" for some reason.

My apologies if this information is already available somewhere on this forum. I've been reading Baertram's guides, the ESOUI API pages, and also guides on LUA, so I have done my best to teach myself.
  Reply With Quote
12/19/23, 04:27 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,980
Moved to dev tools forum.

I'm not sure how VScode can do that, i'm using IntelliJ IDEA and if you include teh esoui source code (you can download it here at esoui like an addon: https://www.esoui.com/downloads/info...ourcecode.html).
Extract the zip file -> esoui folder with all folders and files somewhere -> Not in live/Addons!!! I'd e.g. put it somewhere totally different so it get's not loaded "as an addon".

In IntelliJ IDEA you need to define that folder then in the project config as an "SDK" e.g. "SDK - ESO live".
And if you include that SDK to the project it will find globals like GuiRoot and others and you can search and naviggate them via CTRL+left click etc.

Not sure how VScode does that but must be similar.

btw: XML created controls can be created via lua code too so there is no "only XML" or "only lua".
The only thing that's different is that the XML attributes and tags and the code to craete them there looks different.

Here is a XML valdator scheme for ESOUI, by sirinsidiator.
If you include that into your XML files top line you can auto complete some XML attributes and tags via SHIFT+SPACE or whatever VSCode supports for auto completion there.

Overwrite <GuiXml> with this:

Code:
<GuiXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sir.insidi.at/or/schema/esoui.xsd">
Edit:
GuiRoot is never defined in any esoui lua files I just saw, there is no "GuiRoot =" or similar.
So that's why VScode and IntelliJ IDEA might not know such globals.

Guess you would have to define them yourself in the auto completion files if you really need them.
There is only GuiRoot for all controls of the UI and GuiMouse for the mouse cursor area.

Last edited by Baertram : 12/19/23 at 04:37 PM.
  Reply With Quote
12/19/23, 05:37 PM   #3
wookiefriseur
 
wookiefriseur's Avatar
Join Date: Mar 2014
Posts: 53
Lightbulb

Yeah, like Baertram mentioned you need your own autocomplete files in addition to the ESO-Api ones.

You can add multiple ones. That's what one of my workspace configs looks like:

JSON Code:
  1. "Lua.workspace.library": [
  2.       "S:/ESOAPI/IntelliJ_ESOUI_AutoCompletion/Releases/API100035",
  3.       "Z:/Dokumente/Elder Scrolls Online/live/AddOns/FurnitureShoppingList/FurnitureShoppingList.lua",
  4.       "Z:/Dokumente/Elder Scrolls Online/live/AddOns/LibAddonMenu-2.0/LibAddonMenu-2.0.lua",
  5.       "Z:/Dokumente/Elder Scrolls Online/live/AddOns/LibCustomMenu/LibCustomMenu.lua",
  6.       "Z:/Dokumente/Elder Scrolls Online/live/AddOns/LibAsync/LibAsync.lua",
  7.       "Z:/Dokumente/Elder Scrolls Online/live/AddOns/LibCharacterKnowledge/Public.lua",
  8.       "Z:/Dokumente/Elder Scrolls Online/live/AddOns/LibCharacterKnowledge/Internal.lua",
  9.       "Z:/Dokumente/Elder Scrolls Online/live/AddOns/sidTools/StartUp.lua",
  10.       "S:/ESOAPI/eso-api_base_manual.lua",
  11.       "Z:/Dokumente/Elder Scrolls Online/live/AddOns/FurnitureCatalogue/.scripts/luaDoc_Definitions.lua"
  12.     ],


Most of the GUI elements are just Control. As long as you have a definition for Control somewhere, you can type hint global elements as Control in the autocomplete file and custom variables directly, if you want. Something like:


Lua Code:
  1. -- In autocomplete file
  2.  
  3. ---@class Control
  4. GuiRoot = nil
  5. -- or like this
  6.  
  7. GuiRoot = Control
  8.  
  9.  
  10. -- type hinting of a local variable
  11. ---@class Control
  12. local someControl = WINDOW_MANAGER:CreateControlFromVirtual(...)
  13. someControl:SetHidden(true)




And this is what I have as Definition of control and GuiRoot in some file:
Lua Code:
  1. ---@class Control
  2. ---@field GetNamedChild fun(self: Control, childName: string): Control
  3. ---@field SetAnchor void
  4. ---@field SetHidden fun(self: Control, aHidden: boolean): void
  5. ---@field SetMouseEnabled void
  6. ---@field icon
  7. ---@field mats
  8. ---@field text Control
  9. ---@field comboBox ZO_ComboBox_Base
  10. ---@field SetText fun(self: Control, text: string): Control
  11. ---@field SetNormalTexture fun(self: Control, texture: string): Control
  12. ---@field SetMouseOverTexture fun(self: Control, texture: string): Control
  13. ---@field SetPressedTexture fun(self: Control, texture: string): Control
  14. Control = nil
  15.  
  16.  
  17. GuiRoot = Control


With the autocomplete hints you can get rid of all false positive errors and concentrate on the real error messages.





Generation Script

If you don't want to do it manually and have Python you can try my project specific generator. Should work with most other ESO-GUI XML files.


https://github.com/manavortex/Furnit...generateGui.py

And that's the result:
https://github.com/manavortex/Furnit...ns.lua#L22-L99
  Reply With Quote

ESOUI » Developer Discussions » Dev Tools » How to get VSCode to recognise XML objects in LUA files?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off