Using PHPStorm and an IDE for xys scripting

Discuss and share scripts and script files...
Post Reply
mydarkpassenger
Posts: 31
Joined: 19 Apr 2014 19:39

Using PHPStorm and an IDE for xys scripting

Post by mydarkpassenger »

I decided to see if I could use PHPStorm as an IDE for xys scripts (due to it's similarities to PHP) and it's working relatively well. For those who are interested, I decided to write down what I did for those who might want to try it out. BTW, the reason I wanted to use PHPStorm is because it gives you syntax highlighting, auto-completion for functions, the benefit of highlighting all instances of a function/variable and jumping to it's declaration, refactoring support (only deleting functions that are not called anywhere, smart renaming (only rename variables in scope and when renaming functions/files also update calls to them), error highlighting, etc.

First thing is this is highly recommended for people with XYplorer 15.4 or later. The reason why is that until this latest version, xys files could not contain their own functions like PHP. This is needed to get auto-complete support and allows for a much more PHP friendly syntax.

Now here's a thing to note. PHP files start with <?php or <? in order to enable PHP highlighting. Due to xys's label system this will confuse the interpreter. All you have to do is comment it out //<?php or //<? and everything will work fine. PHP isn't enabled before the comment line so it treats it like HTML.

You want to create a project for your files. This can be the entire script directory if you like (probably should be). The project stores your settings in there and can also auto-complete functions stored in any files that are in the project. I created a PHP file which has all the functions in the docs. It's basically an interface to let PHPStorm know about XYPlorer functions. By adding it to your project PHPStorm will be able to see the functions in there and use the auto-complete signatures from there. Once in you'll be able to type listfolder and there will be an auto-complete entry for it with what it expects and will tell you if you didn't specify enough parameters, etc.

In order to enable highlighting for xys or xyi (imports) in PHPStorm you need to associate those files with PHP files. You can do this by going to Settings|File Types go to the recognized file types and find PHP Files. In the bottom list will be extensions associated with PHP. Add one for xys and xyi. Now PHP highlighting will auto recognize.

Now I don't use labels much. PHPStorm doesn't understand them and unless you have multiple call points they really aren't necessary. What I started doing was using a main function and using that as the starting point for my script. This allows you to write anywhere on the line if you want with no issues (function calls and declarations don't need to be indented).

I also try to avoid using the Like and UnLike statements. I prefer compare($var, $var2) == 0 for Like and compare($var, $var2) != 1 for UnLike. This isn't a requirement but some of the xys syntax is a little different from PHP and it will reflect in a few red underlines in the IDE. These are only because PHP thinks they're errors but they'll work fine in xys files. The compare method and Like both work but compare won't show errors which makes things cleaner.

Despite these few inconveniences using it as my IDE has been tremendous. I call highlight a function and hit CTRL+B and go right to where it's declared. I can rename a variable in a function and not have to worry about accidently renaming something with a similar name, I can do a find usages search and find any files in the project who call that function (to make sure it's safe to delete or just what's calling it), I can rename a function and have it auto update all calls to it throughout the project, I have an outline of every function inside of a file to easily search through, I can easily see some syntax errors highlighted throughout a file and quickly find them without even running the script, etc. I included my xyplorer.xyi file for those which like to get the auto-imports. All you got to do is create a project and add it in there somewhere.

For those interested here's a simple hello world that will not throw out any errors in PHPStorm:

//<?

main();
function main() {
echo "Hello World";
}
Attachments
_xyplorer_interface.xys
(8.41 KiB) Downloaded 188 times

Post Reply