-
Notifications
You must be signed in to change notification settings - Fork 46
Smart completion
An [as of yet] unique feature of GMEdit is in being able to provide contextual syntax completion and syntax highlighting for variables and (2.3) methods.
This works for the following syntactic constructs:
-
obj_name.field
:
As this would find you the first instance of an object type, automatically presents you with associated variables. -
self.field
:
Automatically inside objects and 2.3 constructors, or by tagging through @self.
(note: can also be summoned without self-prefix by typing a period.
out-of-context) -
a_macro.field
anda_globalvar.field
:
If fields were outlined using @hint. -
a_local_var.field
:
If local variable type was specified viavar name:Type
syntax.
Variables are collected as following:
- GMEdit will pick up normal variable assignments (
name = value
) that are not nested inside curly brackets{}
. - For objects, Create events are indexed automatically.
- Scripts are indexed if they are marked with @interface.
- Parent (be it object parent or struct parent) variables are included automatically.
- Non-parent relationships can be indicated via @implements.
- Given multiple variable defintions, GMEdit will display information about "nearest" one
(own variables > variables from interfaces > variables from parent > variables from parent's interfaces) - Anything that is not picked up automatically can be indicated via @hint.
Suppose you have obj_enemy
with the following Create event:
maxhealth = 10;
my_health = maxhealth;
my_target = noone;
// attack = function(target) {} // 2.3 method
After saving, if you were to type self.
anywhere in the object, you would only get the variables defined in Create event and the built-in variables rather than everything that you have in your project.
Similarly, if you were to type obj_enemy.
anywhere in the project, you would only get those same variables.
With above setup, if you were to write
var e:obj_enemy = instance_nearest(x, y, obj_enemy);
After saving, typing e.
would show you only the variables from obj_enemy
.
2.2: Suppose you had scr_enemy_ai
that would be called by obj_enemy
with the following
/// @self {obj_enemy}
self.my_target = instance_nearest(x, y, obj_player);
After saving, typing self.
would show you only the variables from obj_enemy
.
2.3 version (much the same, but JSDoc tags sit outside the functions now):
/// @self {obj_enemy}
function scr_enemy_ai() {
self.my_target = instance_nearest(x, y, obj_player);
}
Suppose you had a pair of functions that represent things that you might assign into constructors/objects:
/// @interface {IHorsable}
function scr_init_horsable() {
neigh = function(magnitude) { throw "not implemented!" }
}
/// @interface
function scr_twovars() {
oneVar = 1;
twoVar = 2;
}
(in 2.2, make that two scripts with /// @interface
inside the script and replace function(){} by another script)
You would then be able to mark them for inclusion in auto-completion and highlighting by doing the following in Create event of an object:
/// @implements {IHorsable}
scr_twovars(); /// @implements
myVar = "hi!";
Or, for constructors,
/// @implements {IHorsable}
function Some() constructor {
// ...
scr_twovars(); /// @implements
myVar = "hi!";
}
which would then show you myVar
, oneVar
, twoVar
, and neigh(magnitude)
when typing self.
.
- Like with most GMEdit features, you'll need to save (Ctrl+S) when adding/changing code that specifies types.
- GMEdit currently does not handle
self
insidewith
-loops being a different type and will highlight it as per outer type if you useself.field
.
This may be changed in future, but would most likely unnecessarily stress the syntax highlighter with re-parsing parts of the source code on changes.
- Smart auto-completion
- JSDoc tags (incl. additional ones)
- @hint tag (mostly 2.3)
- `vals: $v1 $v2` (template strings)
- #args (pre-2.3 named arguments)
- ??= (for pre-GM2022 optional arguments)
- ?? ?. ?[ (pre-GM2022 null-conditional operators)
- #lambda (pre-2.3 function literals)
- => (2.3+ function shorthands)
- #import (namespaces and aliases)
- v:Type (local variable types)
- #mfunc (macros with arguments)
- #gmcr (coroutines)