bscotch / stitch

Tools and apps for GameMaker development: a CLI for pipeline development, a VSCode extension for coding, and more.
Other
119 stars 13 forks source link

Stitch VSCode doesn't understand Grid Accessor syntax #108

Closed stdc105 closed 1 year ago

stdc105 commented 1 year ago

Sample offender code:

Script::data_load.gml

function stub() {
  var _grid = ds_grid_create(5, 5)
  _grid[# 0, 0] = "001" // 1
}

Expected: Stitch doesn't show error on comment 1 Actual: Stitch is reporting 2 errors on comment 1: Expecting token of type --> EndBracket <-- but found --> ',' <-- on comma, and Redundant input, expecting EOF but found: ] on closing square bracket.

In addition, if _grid is a local variable (defined by var) or an object field (defined without prefix), it shows the correct type of Id.DsGrid; but if it's a global variable under global.SOMETHING = ds_grid_create(5, 5), it will show type ANY.

Bug report environment: Windows 11 Pro 22H2 (22621.1928) GameMaker BETA IDE v2023.400.0.324 Runtime v2023.400.0.342 VSCode 1.80.0 (user setup) Stitch VSCode 1.3.0

adam-coster commented 1 year ago

Whoops, apparently we don't use DsGrids in any of our projects!

The accessor fix will be in the next version (after 1.3.2) by end of day Central Time.

I'm not sure why the global is ending up with an Any type, though using global.X is challenging for the parser since it's not possible to determine which global.X = assignment is the initial declaration (Stitch uses the declaration, or the first discovered assignment to determine the type).

If you use globalvar to declare them that might resolve it, since that unambiguously indicates where the declaration of that variable is.

stdc105 commented 1 year ago

This is great! Unfortunately we're using global.STUFF to define all of our global variables and we may not be able to change them right now, but that's okay, "Find References" works on global and in most cases I know the types already. Thank you for all the help and fixes!

adam-coster commented 1 year ago

Yeah the global thing is just sorta incompatible with static analysis, unfortunately.

Since Stitch only assigns types when things are assigned, you should be able to ensure that a type is correct for a given global.X if you:

Stitch gives the /// @type {TheType} directive precedence over inferred types, so as long as you can ensure that the first assignment Stitch sees is explicitly typed like that (by explicitly typing all assignments) you should end up with what you want.

Note that Stitch works from top to bottom on files, so you would only need to explicitly type a global's first assignment in a given file.

The latest version (1.4.0) was just published a moment ago and includes the DsGrid accessor fix, among a bunch of other fixes.