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 is sensitive to the order of function defined #107

Closed stdc105 closed 1 year ago

stdc105 commented 1 year ago

Sample offender code:

obj_shop::Create_0.gml

global.ITEMS = []
global.MONEY = 250

shop = [
  {
    item: "001",
    price: 100,
    can_buy: true,
    sold: false,
  },
  {
    item: "002",
    price: 200,
    can_buy: true,
    sold: false,
  },
]

buy = function(_i) {
  array_push(global.ITEMS, shop[_i].item)
  global.MONEY -= shop[_i].price
  shop[_i].sold = true
  check_can_buy() // 1
}

check_can_buy = function() {
  for (var _i = 0; _i < array_length(shop); _i++) {
    if shop[_i].sold {
      shop[_i].can_buy = false
    } else {
      shop[_i].can_buy = global.MONEY > shop[_i].price
    }
  }
}

check_can_buy() // 2

Expected: no warning will show on comment 1 or comment 2. Actual: a check_can_buy is not declared anywhere. warning shows on comment 1.

While it might be an issue if buy is called before check_can_buy is defined, in reality buy will be assigned to a button that is executed in Step event, which runs fine in GameMaker.

Updated to 1.3.0 from pre-release today and found it working with our project now. Despite the issue, it's still great to have an extension that works with GameMaker in VSCode. Can't say enough thanks for that alone!

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

stdc105 commented 1 year ago

Stitch is also reporting a lot of other not declared anywhere warning. Most of them are scope issues that are basically "call our functions in the right object", or "call this setup function before using that variable" thing. While I understand our code is not optimal, it would be very welcome if we can temporarily disable this warning.

adam-coster commented 1 year ago

Regarding the order-of-definitions problem: There's probably a fairly straight forward resolution to that, so I'll add it to the ToDo list.

Regarding the "not declared" noise: I'll probably eventually add some options for deciding which "problems" get shown, but not until I'm confident that everything is behaving properly so that issues with Stitch itself don't get hidden. I definitely understand the annoyance though -- our main project has >6k warnings right now!

stdc105 commented 1 year ago

Per disabling warning: that's totally fair! I can live with it for a while, and I would expect a lot of them to disappear once grid accessor syntax and order-of-definitions improvement is released.

I will also spend some time to set up a VSCode plugin dev environment this weekend and see if I can contribute to fixes in the future!

adam-coster commented 1 year ago

The latest version (1.4.0) fixes that order-of-definitions problem (and the accessor problem), and the fix to that resolved a lot of other problems as well. You should see a lot fewer warnings and errors now, and the errors should be more actionable.