简体   繁体   English

VSCode 语言扩展(GameMaker / GML 文件)的变量名称自动完成?

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

I'm editing GML files ( GameMaker Studio ) in VSCode.我正在VSCode 中编辑 GML 文件( GameMaker Studio )。 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.有一个很棒的插件, GML Support ,它为内置的 GML 函数和实例变量添加了自动完成功能以及其他一些很酷的东西。

However, VSCode doesn't seem to recognise local variables in GML (see screen grab below. Dot notation works fine)但是,VSCode 似乎无法识别 GML 中的局部变量(请参阅下面的屏幕截图。点符号工作正常)

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.我查看了VSCode 的 Programmatic Language Extension以进行变量名称自动完成,但仍然不知道如何使用 VSCode 的语言服务器注册变量声明(即var fooBar = 23; )。

Ideally, I'd like the Language Server to respect variable scope for GML files:理想情况下,我希望语言服务器尊重 GML 文件的变量范围:

  1. global variables - any var declarations for files under script folder全局变量 - script文件夹下文件的任何var声明
  2. any local variable declarations - all var declarations in the surrounding {...}任何局部变量声明 - 周围{...}中的所有var声明

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.编辑:查看vscode-python以了解如何使用registerCompletionItemProvider (基于VSCode 语言扩展 doco )。 Unfortunately, still not clear to me as vscode-python seem to rely on Jedi to provide symbols?不幸的是,我仍然不清楚,因为 vscode-python 似乎依赖绝地来提供符号?

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)):如果您想启用简单的自动完成,您可以将以下内容添加到您的settings.json (命令面板➜ 打开设置(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.对于适当的解决方案,您需要使用registerCompletionItemProvider并根据需要或随时索引文件。

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.对于处理 GML 语法的复杂性,您可以在我制作的基于 Ace 的外部编辑器中查看代码 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).处理变量定义特别要求您以相对置信度(可以通过平衡解析器完成)跳过字符串、注释和循环值( var name[=value][, name2[=value2]] )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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