ManiaScript for Visual Studio Code

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: ManiaScript for Visual Studio Code

Post by zocka »

I had a bit of a look through your language repo and have some suggestions I don't want to make pull requests for:

Please support CDATA sections in themplate strings as well as XML comments.
The latter tend to create malformed XML with ManiaScript.

And the $< $> around these placeholders in strings are optional. They are common to avoid broken formatting, but not necessary.

Operators:
MS doesn't have bitwise operators yet as far as I know and no ++/-- so these shouldn't be highlighted.
Also there is the keyword is as instanceof (or comparable operators).

Keywords:
switchtype is a thing (like switch, case values are class identifiers). I saw you have a switch-literal thing. I don't know what it is used for, but maybe you want to extend this (as for these *-literal files: we don't need regex, but maybe foreach and while - idk).
assert() is a basic function like log() and might want to be highlighted equally.
Just a bit ago I stumbled across #Command (https://github.com/maniaplanet/game-mod ... pt.txt#L37)
try/catch/finally/throw are no keywords in MS either to my knowledge.
persistent/netread/netwrite are keywords in context of variable declaration (declare ... <Type> <Identifier> for <Identifier>).
This is a keyword.

Labels:
Labels can be ---Label--- as well. (I didn't see it in language-label, but my color scheme doesn't really highlight operators at all, so actually some of my remarks might be off. In that case sorry for that.)


Oh and while you stated that you forked this thing off of my tmLanguage file: I merely updated this whole struct and property list (at that time poorly) generating it from the MS docs. Thus the list is not complete and I didn't bother too much with the stuff I now mentioned above.

I now have an updated (unpublished) script to generate these data from the doxygen XML (enums, structs, public members, namespaces - mostly including descriptions etc.). I tried generating VS Code snippets like sublime-completions, but they aren't quite comparable and thus not completely useful.
As you built your tmLanguage generation with js though, you would probably do these things with a node script as well.


Finally out of curiosity: how do you plan to support intellisense? From what I read so far this requires a bit more work on actually parsing etc. the script?

greetz
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
tonechild
Posts: 12
Joined: 20 Mar 2017, 12:43

Re: ManiaScript for Visual Studio Code

Post by tonechild »

Hi Zocka!

Thanks for your response and also the initial work on this! I also appreciate the updates regarding some of the syntax, as well as some corrections regarding the ones I have. It's a shame they dont have try/catch/finally - I put that in with some hope haha.

I'll be sure to add the keywords you have and also remove some that dont need to exist.

For intellisense, you don't need a parser per se. You can either fauxparse by using event listeners / triggers (can explain more but maybe I'll just explain after I make it because this is what I'm doing) or use language server with a compiler (can hook to a REPL) or language server that uses parsing like BNF parsing to an AST. The compiler would have to be either reverse engineered or supplied by Nadeo, I was thinking if maybe could use maniaplanet.exe to compile it or something (probably not) - another thing you could do is create your own BNF parser that generates an AST, then just use the AST with the lang server.

I have actually entertained the idea of creating a BNF parse for this, but I think it would be so much better if Nadeo could release a REPL (do you know anything about this?) Because a language server needs only a REPL (or at least a standalone compiler as REPL can be made from one) for some awesome intellisense.

For now, I am actually planning on using some lightweight parsing, (more regular expression with fuzzy searching etc) for intellisense, as that actually can be done pretty easily because I have a lot of know-how with events and javascript, etc, and bnf parsing is not something I've done before but I'm super interested in it in the future. it wont be as awesome as being able to build an Abstract Syntax Tree or compiling it like a REPL.The current intellisense being implemented should be pretty good though (i hope)

Thanks again, I'll update some things ;)

Also I should have some basic intellisense running in the next update
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: ManiaScript for Visual Studio Code

Post by zocka »

I don't feel like we would get too much from Nadeo (viewtopic.php?f=279&t=38429).
I spent some time trying to get a propper grammar to generate a parser from, but it didn't work too well and I had more urgent things to do.

(A complete parser would really be nice to improve on build-tools like script concatenation or managed variables.)

For now I'm curious for your next update ;)
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
tonechild
Posts: 12
Joined: 20 Mar 2017, 12:43

Re: ManiaScript for Visual Studio Code

Post by tonechild »

Just finished up a parser that creates an AST of the doc.h file, which can be used for a decent amount of intellisense and further language parsing. (planning on using a transform of the AST for yet another parser that should inspect the langauge further, not sure tho)

You can see the AST (16k lines lol) here: https://github.com/MattMcFarland/manias ... t/ast.json
tonechild
Posts: 12
Joined: 20 Mar 2017, 12:43

Re: ManiaScript for Visual Studio Code

Post by tonechild »

Happy to declare that intellisense has been added. There is still some tweaking to be done, and adding live parsing as well to allow for intellisense to update.

Image

You can get a copy of this here: https://marketplace.visualstudio.com/it ... aniascript
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: ManiaScript for Visual Studio Code

Post by zocka »

That's not bad to look up the API, but doesn't do much work yet.
Maybe you could add the return type (and signature if applicable) and maybe description (if available) to the completion dialog so that we could at least look up the next available members without too much effort (e.g. CMlScript.Page is CMlPage; CMlPage.MainFrame is CMlFrame; CMlFrame (and thus Page.MainFrame in my current context) has the listed properties).
The main reasons for editor support are (imo) looking up function parameters (order and types), auto-completing long names (especially enums) or browsing through available members to see where a desirable type is returned.

(I really like, how well this works with basic completions in Sublime Text
Image)


I played around a bit with this plugin stuff for label completion without much further insight into the code:
https://gist.github.com/PRGfx/0ac8ce180 ... be12b2a728
It would search for +++ Label +++ or --- Label --- occurences and give you a selection to pick one to then insert a snippet like

Code: Select all

*** \selectedLabel ***
***
$0
***
Maybe instead of using a command this could be invoked (or offered) after typing ***. And as it says in the gist it only works on files in memory (I think. The file had to be opened before in this instance of VSC, I didn't test too much). And the requested files should be filtered to be maniascript or xml I suppose. Maybe you can draw some inspiration from this feature, I think it would be quite cool. I found myself switching between files multiple times to see, how I named my entry points :D
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
tonechild
Posts: 12
Joined: 20 Mar 2017, 12:43

Re: ManiaScript for Visual Studio Code

Post by tonechild »

Thanks for sharing that gist :)

You should consider contributing and sending a PR!

As for the current state of intellisense, I agree with you and am going to improve it upon next release. The next iteration will include some parsing, so intellisense can understand what methods variables have.

Another thing is I couldn't figure out how to add documentation snippets. I'll have to review Microsoft's docs, because while they clearly point out an API that makes it possible, it seems that the completionitems only have two properties, the label and type. But MS shows they can have a lot more properties like documentation links, etc.

PRs are welcome!
User avatar
Cerovan
Posts: 2044
Joined: 11 Jul 2011, 11:27
Location: France
Contact:

Re: ManiaScript for Visual Studio Code

Post by Cerovan »

Image

I'll contribute when i'll have time :thumbsup:
Online Programmer & Meme Master ヾ(⌐■_■)ノ

Access to your Player Page

You have troubles, please contact the Ubisoft Support

Maniaplanet Documentation (Editors, Scripting, Title Pack, etc...)
tonechild
Posts: 12
Joined: 20 Mar 2017, 12:43

Re: ManiaScript for Visual Studio Code

Post by tonechild »

Woohoo!! Nice to have support from a NADEO team member :)

I've started working on the next feature, which will be the language server. If you want to understand what language servers are (as they are vastly different than http servers), why we will use one, etc, I recommend you read this: https://code.visualstudio.com/docs/exte ... age-server

Tiny excerpt on why:
In general, validating a programming language can be expensive. Especially when validation requires parsing multiple files and building up abstract syntax trees. To avoid that performance cost, language servers in VS Code are executed in a separate process.
The MVP for language server will be a fully working language server and integration with the client, as well as parsing that includes much more intelligent suggestions (including the label suggestion!)

The feature is currently being tracked on a separate branch in git, as "feature/language-server"
User avatar
adamkooo2
Posts: 1371
Joined: 13 Jun 2014, 08:43
Location: Slovakia
Contact:

Re: ManiaScript for Visual Studio Code

Post by adamkooo2 »

Is it supporting the newest commands from MP4?
/\rkady
Image
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 2 guests