Annotating members of a table in a global table which are initialized within a function, VSCode integration #3444
Unanswered
sparr
asked this question in
Annotation Authoring
Replies: 1 comment
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am working on adding annotations to https://github.com/beyond-all-reason/Beyond-All-Reason/tree/master/luaui/Widgets. A convention among these files is that they expect a global table named
WGto exist. A single widget file will typically create one entry in the WG table. That entry is itself a table with most of its values being functions. For example,WG.FlowUI.guishaderCheckDlist()orWG['info'].clearDisplayUnitID()orWG.TerraformBrush.setAngleSnapStep(). These functions form the exposed API for the widget in question, which other widgets might call by referencing that WG table.Some widgets create their WG entry at the top level of the widget script, to be run when the script is first loaded.
Some widgets create their WG entry in an Initialize function that will get called by the widget loader.
Some WG entries are created one entry at a time, e.g.
WG.info = {} WG.info['foo'] = bar.Some WG entries are created with an inline table, e.g.
WG.info = {foo = bar}.I would like to be able to annotate every WG.foo.bar at the point where it is defined, such that the language server will correctly associate that with references to WG.foo.bar in other files. I'm having a difficult time getting this to work, particularly using the Lua extension in VSCode, although I'm open to trying to interact directly with LuaLS for troubleshooting purposes.
One approach I've tried is to use class/field annotations at each function definition site:
This makes "Go To Definition" work seamlessly in VSCode, but the tooltip for
WG.buildmenu.getGroupsin other files now suggests that getGroups is a union type of the function or the whole class.Another approach is to use type annotations:
This produces the expected/desired tooltip which shows the signature of the function, but now "Go To Definition" gets confused and forces me to choose between the annotation or the definition.
Is there one best way to do this without any of these drawbacks, across all the various ways the tables are populated?
All reactions