[VS Code] ZScript with Intellisense support

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

[VS Code] ZScript with Intellisense support

Post by Nash »

Is there any possibility to see Intellisense-like features for ZScript, in any program? I tried mucking around with VS Code the other day but I couldn't figure it out.

I was thinking earlier about some of the usual complaints (especially in the early days of ZScript) about how intimidating it is, and I think Intellisense would help a lot. Speaking from personal experience - a musician person who has almost no clue about computer science - the defining factor that got me comfortable with working with the (G)ZDoom source (enough for me to build confidence to send Pull Requests) was actually Intellisense.

Being able to hover over something, and get context sensitive help, makes ALL the difference. Seeing where a variable is in the member chain, seeing what this constant is supposed to represent, things like that.

I believe if ZScript is edited in an Intellisense-enabled environment, it would help new users a LOT, those who are afraid to try real programming. It certainly has helped me, and I'm just some dumb musician!
Last edited by Nash on Tue Oct 03, 2017 12:51 pm, edited 1 time in total.
User avatar
Rachael
Posts: 13980
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: ZScript with Intellisense support

Post by Rachael »

This is something that would be appropriate for editors such as DoomBuilder or Slade.

But regardless - what you are talking about is exactly the purpose of forward declarations - you're supposed to know, in advance, what a "symbol" is (not the definition of a symbol, but what any string of characters representing a function/variable is).

Would intellisense help? Absolutely - being able to hit F11 to peek at a function's definition, or a global variable's declaration, is hugely useful.

Ultimately, Slade or GZDBBF would probably need to develop their own ZScript partial compilers/interpreters in order to create something like this. And this project actually seems fairly simple conceptually - it's getting into all the various constructs that ZScript uses that would probably be most time consuming. But it is doable. (After all, it was done for C/C++/Java/C#/Visual Basic already, wasn't it?)

(P.S. want to know how I survive GZDoom's coding environment while rarely using Visual Studio? Extremely liberal use of "grep -r". Now you know. ;))
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript with Intellisense support

Post by Nash »

Image

I'm slowly transitioning into using VS Code exclusively for ZScript. It's not perfect, but if you install the C++ highlighter, and tell VS Code to use C++ highlighting for your ZScript files (details below), it looks pretty convincing.

Best of all, Intellisense ALMOST works for the most part. It's functional enough to recognize your custom ZScript classes and show you info about member variables if you hover your mouse over it... as well as peeking/jumping to the definition of something.

As far as I can tell, if I could figure out how to make the grammar understand ZScript: "just" taking the C++ highlighter and repurpose it with some minor tweaks would do the job I think. Here's what needs to be working, from what I can tell:

- let keyword ("auto" works, so just find out how it's doing things for "auto" and add "let" to the parser)
- Make VS Code recognize all the base classes in GZDoom.pk3
- Make it recognize const declarations.
- Include directives. Now this one is something I'm a bit unsure of, since unlike C++, a typical ZScript project will usually dump all their #includes in 1 file (usually zscript.txt in the project's root directory). Perhaps there's way to tell VS Code, "look at this one file for all #includes".

What I like about VS Code is it's very lightweight on my computer, has awesome dark UI (I'm sorry, Notepad++ is just starting to hurt my eyes - and before anyone says it - N++ does not have recolourable UI. Only recolourable text) and is super customizable. I've already setup the hotkey to run my project from within VS Code and it shows a nice terminal output at the bottom which prints useful stuff like ACS errors and what-not. The built-in file explorer and file search (Ctrl + E) is also great for quickly jumping from file-to-life for fast editing.

Ok anyway here's what to do to get basic highlighting for ZScript:

- First install the official C++ highlighter from the highlighter marketplace
- Then go to File -> Preferences
- Place your custom file associations in the user settings override to the right. Ctrl + S to save it after you're done editing to see it hot load the changes. Here's mine for reference

Code: Select all

    "files.associations":
    {
        "*.acs": "cpp",
        "*.zc": "cpp",
        "*.txt": "cpp"
    }
 
To setup a keybind to run your project:

First you must have a folder opened. A folder is sort of like a workspace or "project". This won't work if you open single files individually. VS Code has to be in "I'm opening a folder" mode (you will see your file list to the left). File -> Open Folder.

With a folder opened, go to Tasks -> Configure Tasks

Here's a sample of my custom task. Remember to Ctrl + S to save after you're done.

Code: Select all

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Play Live Another Day",
            "command": "D:/LiveAnotherDay/data/zplay.bat",
            "type": "shell"
        }
    ]
}
IMPORTANT: Remember what exactly you used for "taskName". You'll need this later.

Now go to File -> Preferences -> Keyboard Shortcuts. You will see something that says "For advanced customizations open and edit keybindings.json". Click the link.

Enter your custom keybind overrides, again, mine for reference and don't forget to save as usual. I bound mine to F6. Note that the "args" part exactly matches "taskName" from above.

Code: Select all

// Place your key bindings in this file to overwrite the defaults
[
    {
        "key": "f6",
        "command": "workbench.action.tasks.runTask",
        "args": "Play Live Another Day"
    }
] 
GiveOneMoreChance
Posts: 19
Joined: Thu Aug 10, 2017 8:09 pm

Re: ZScript with Intellisense support

Post by GiveOneMoreChance »

- let keyword ("auto" works, so just find out how it's doing things for "auto" and add "let" to the parser)
- Make VS Code recognize all the base classes in GZDoom.pk3
- Make it recognize const declarations.
- Include directives. Now this one is something I'm a bit unsure of, since unlike C++, a typical ZScript project will usually dump all their #includes in 1 file (usually zscript.txt in the project's root directory). Perhaps there's way to tell VS Code, "look at this one file for all #includes".
VS code uses Regex for matching text, example "match": "[a-zA-Z_$][\\w\\-$]*". So adding let and recognize const not so difficult.
for Gzdoom base classes we can add snippets.
for #include need add to includePath base zscript file and link other files.
I start working on this things...
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript with Intellisense support

Post by Nash »

GiveOneMoreChance wrote: I start working on this things...
Sweet! Please let us know if you make any progress. I'm definitely interested. Also if you need any help, just ask.

Return to “Editing (Archive)”