简体   繁体   中英

Variable name autocomplete for VSCode Language Extension (GameMaker / GML files)?

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 (ie 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!

在此处输入图片说明

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:

在此处输入图片说明


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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM