1

I'm editing GML files (GameMaker Studio) in VSCode. There's a wonderful plugin, GML Support which adds autocomplete for inbuilt GML functions and instances variables along with a bunch of other cool things.

However, VSCode doesn't seem to recognise local variables in GML (see screen grab below. Dot notation works fine)

I had a look at the VSCode's Programmatic Language Extension for variable name auto-completion but still don't get how I could register the variable declaration (i.e. var fooBar = 23;) with VSCode's Language Server.

Ideally, I'd like the Language Server to respect variable scope for GML files:

  1. global variables - any var declarations for files under script folder
  2. any local variable declarations - all var declarations in the surrounding {...}

What would be the easiest way to add variable name completion as described above?

Thanks in advance!


Edit: looked at vscode-python to see how registerCompletionItemProvider (based on VSCode Language Extension doco) could be used. Unfortunately, still not clear to me as vscode-python seem to rely on Jedi to provide symbols?

So any points appreciated!

enter image description here

snowbound
  • 1,692
  • 2
  • 21
  • 29
  • 1
    According to https://github.com/gml-support/gml-support/blob/master/src/gml/completionProvider.js#L76, completion for GML either use hard-coded names (for global functions or built-in stuff), or very basic parsing for function names. You would need to add something similar for variable names I guess, but respecting the scope would be much more difficult, you'd probably need a language server for this kind of thing. – Holt Jul 12 '21 at 12:26
  • Thanks @holt. Can VSCode be made to just search for `words` used in the current file - which would work for local variables in the current file. I could just use specific naming convention for global files. Right now, VSCode is able to `ctrl-space` suggest words I've typed previously in a `plaintext` file, but with `GML Support` extension loaded, that ability seem to have been turned off? – snowbound Jul 12 '21 at 13:07

1 Answers1

0

If you want to enable simple auto-completion, you can add the following to your settings.json (Command Palette ➜ Open Settings (JSON)):

  "[gml-gms81]": { "editor.quickSuggestions": true },
  "[gml-gms1]": { "editor.quickSuggestions": true },
  "[gml-gms2]": { "editor.quickSuggestions": true },

which works for a workaround:

enter image description here


For a proper solution, well, you'll need to use the registerCompletionItemProvider and index the file on demand or as you go.

The official example demonstrates the use.

For intricacies of processing GML syntax, you can peck at the code in the Ace-based external editor that I made. Processing variable definitions specifically requires you to skip over strings, comments, and loop over values (var name[=value][, name2[=value2]]) with relative degree of confidence (which can be accomplished through a balanced parser).

YellowAfterlife
  • 2,967
  • 1
  • 16
  • 24
  • thanks @yellowAfterLife. Unfortunately that the `editor` settings doesn't work once the file type is changed to GML2 which is added by the `gml-support` extension. I did find https://marketplace.visualstudio.com/items?itemName=Atishay-Jain.All-Autocomplete which seem to work sometimes - auto completion occasionally conflicts with `gml-support`, but it'll do. `GMEdit` looks pretty cool. Great work! I gave it a try, but ended up going back to vscode because of git integration. Plus I'm too tied to Vim and VSCode / Sublime shortcuts :p – snowbound Jul 16 '21 at 12:47
  • Testing further, it seems like the `quickSuggestions` will only pop up once the regular auto-completion menu has no more items to offer, which is either a bug or unfortunate behaviour. As for GMEdit, you can change keybinds and there are predefined options in Code Editor Settings, but there are definitely functionality gaps compared to VSC. – YellowAfterlife Aug 14 '21 at 15:09