Shop OBEX P1 Docs P2 Docs Learn Events
Visual Studio Code editor for P1 & P2 (spin & pasm) obsolete — Parallax Forums

Visual Studio Code editor for P1 & P2 (spin & pasm) obsolete

Cluso99Cluso99 Posts: 18,066
edited 2021-05-26 11:21 in Propeller 2
Stephen Moraco has taken over development. Thanks heaps Stephen! His posts start here...
forums.parallax.com/discussion/comment/1509623/#Comment_1509623

Over the next day or so Stephen will be creating a replacement thread and the moderators will shift the later posts to the new thread. I’ll then provide a link here.

Attached is alpha version 0.1.0 of extensions for VS Code to edit P1 & P2 code.

There is a version for Spin/Pasm P1 (for files xxxx.spin) and a Spin/Pasm P2 (for files xxxx.spin2). They use a common color theme included called spin-theme.

Note: P2 has spin1 code support for editing. I am not sure if eric's fastspin compiler will compile this to P2ASM ???

To install, unzip and copy the 3 folders (spin1, spin2 and spin-theme) to %userprofile%/.vscode/extensions and restart VSCode. Then activate the spin-theme using Ctl-K Ctl-T and selecting Spin-Theme.

If you want to change the colors, edit the file ...\spin-theme\themes\spin-theme.json

Please report bugs here. (quite possibly missing some opcodes)

VSCode-spin-v0.1.0.jpg
«1

Comments

  • Cluso99Cluso99 Posts: 18,066
    -reserved-
  • Question, looking to use the p1 version. Will it. compile and download to the prop1?
  • Cluso99Cluso99 Posts: 18,066
    edited 2019-04-22 14:07
    Question, looking to use the p1 version. Will it. compile and download to the prop1?
    No. It’s just an editor, though it runs on windoze, linux and mac, and free.
  • Would it be possible to modify the extension to compile Spin? Could I do it with little to no experience making extensions?
  • Cluso99Cluso99 Posts: 18,066
    edited 2019-04-22 16:50
    Would it be possible to modify the extension to compile Spin? Could I do it with little to no experience making extensions?
    Trying to be polite, but if you have to ask, then the answer is probably no. I don’t know VSC enough yet to know if it’s even possible. It’s not how i would tackle it tho. I’d call an existing compiler instead - why spend hundreds of hours reinventing what’s been done?
  • Cluso99, that's probably what he's asking. Some way to get the menu item compile to call the command line compiler and display the info.
  • Yeah, interesting, but I really prefer to edit and compile without changing programs in between. Really neat, though!
  • Wuerfel_21Wuerfel_21 Posts: 4,351
    edited 2019-04-22 20:12
    Just set up your compiler in (project folder)/.vscode/launch.json as ususal
    Or use the built-in terminal to invoke it
  • Would it be possible to modify the extension to compile Spin? Could I do it with little to no experience making extensions?
    You probably would not want to use the editor extension to compile .spin or .spin2 code. But, you can create a VSC (Visual Studio Code) Task, which can execute any command-line such as fastspin compiler or openspin, loaders, etc... If you Google something like "How to create a Virtual Studio Code Task", you'll find examples of how to do this.

    If this is not something you would prefer to do on your own, it's probably "not for you"... Creating scripts and such that execute command-line programs is for the most part, something for those that are comfortable with Linux, Win or macOS scripting at the shell level (or maybe javascript or python). The problem with this sort of scripting is it will be dependent on where you store your compilers, assemblers, loaders and other required development software. I could write (and have) a scripted Task, but it would be dependent on my system configuration and would probably cause more angst for other users. This is why IDEs like SimpleIDE and PropTools exist. They work because all of these required programs are contained in a location governed by the IDE's installation process. So far, for P2, there is no single all-in-one IDEesque installation that will accomplish this. We're all either working with what exists or creating that next environment for P2. It's unfortunate, but at this time most of the resources for building P2's development environment are volunteers. But it's also "fortunate" to have those volunteers!

    dgately
  • Wuerfel_21Wuerfel_21 Posts: 4,351
    edited 2019-04-23 08:28
    dgately wrote: »
    The problem with this sort of scripting is it will be dependent on where you store your compilers, assemblers, loaders and other required development software.

    Actually, the "proper" way is to put all the tools on your PATH, so the scripts don't need to know their location
  • Wuerfel_21 wrote: »
    dgately wrote: »
    The problem with this sort of scripting is it will be dependent on where you store your compilers, assemblers, loaders and other required development software.
    Actually, the "proper" way is to put all the tools on your PATH, so the scripts don't need to know their location
    Exactly! But as evidenced by many forum postings, using a $PATH is within the same category of activities done by those who write shell scripts, execute programs from the command line, create IDE extensions, etc...
  • Ahle2Ahle2 Posts: 1,178
    Visual Studio Code is fantastic... Is that REALLY an open source, small footprint, fast, good looking, free, platform independent and flexible code editor from MICROSOFT?! I don't think I have ever used more than a couple of those words to describe a Microsoft product ever. This MUST be an alternative reality!!

    Cluso, thank you for your contribution. From now on Visual Studio Code + your spin highlighting + fastspin compiler + loadp2 + my json compile and run config has made every other option obsolete. (IMHO) :smiley:

    My setup works perfectly with just "ctrl + shift + b" to compile and run and the terminal pops up in VSC, so no need to have a separate shell open. Seamless!

    These are the easy steps I made to make VSC my new P2 "IDE"
    1. Install Cluso's spin highlighting in VSC
    2. Download/Install fastspin and loadp2
    3. Add the paths to fastspin and loadp2 binaries to the path environment variable
    4. Configure the default build task to call fastspin and then loadp2

    Here is my "tasks.json" file for my SIDcog P2 project as a reference.
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Compile",
                "type": "shell",
                "command": "fastspin -2 SIDcogP2.spin2"
            },
            {
                "label": "Run",
                "type": "shell",
                "command": "loadp2 SIDcogP2.binary",
                "dependsOn": [
                    "Compile"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

  • Cluso99Cluso99 Posts: 18,066
    edited 2019-04-24 00:53
    Ahle2,
    Many thanks for your json file. I’ve been reading how to do that but you’ve done it for me so thanks.

    Any idea how to request the filename (eg SIDcogP2) as a variable?
    Do you have much VSC experience as i am trying to get the CON/OBJ/VAR/PUB/PRI/DAT scope to remain persistent so i can separate the various keywords into their respective scopes? I know how to see what scopes are current by placing the cursor on various words using Ctl-Sh-P and selecting Developer: Inspect TM Scopes.

    If we can get this working, we can add Erics Basic, C, etc addon language easily too.

    I am just starting with VS Code and I see the number of users is huge, coming from all the other editors out there. Agreed, this is one time MS has truly helped the masses for free :smiley:

    @Roy,
    Thanks for pushing me to look at VS Code. Best thing I’ve done for a while. Haven’t worked out how to run scripts like i do for work in Notepad++ yet but that will come i think.
  • Cluso99Cluso99 Posts: 18,066
    Here is a link for how to automate the tasks, including windows and linux commands, default filenames, paths, getting input parameters from the user, etc. I'm reading thru this now ;)

    https://code.visualstudio.com/docs/editor/tasks
  • @Cluso99
    Glad it is working out for you, I have been very happy with it for working on Python and Shader (HLSL) code. I will be checking out your spin/pasm related stuff for it soon.
  • Cluso99Cluso99 Posts: 18,066
    Roy Eltham wrote: »
    @Cluso99
    Glad it is working out for you, I have been very happy with it for working on Python and Shader (HLSL) code. I will be checking out your spin/pasm related stuff for it soon.

    Currently it is quite basic tho I'm working to improve it.
    Hoping others will add to it too, so it will improve over time :smiley:
  • Question, looking to use the p1 version. Will it. compile and download to the prop1?

    And I agree.
    But where to find the command line tools for P1/Spin1 ?

  • rosco_pcrosco_pc Posts: 448
    edited 2019-04-24 05:17
    openspin and/or fastspin. Unzip them somewhere and add them to your CMD path (for WIN10):

    Access is still via the System Properties dialog: type path in the Search box, click "Edit the system environment variables", and click the "Environment Variables" button. Double click 'path' variable and add the folders where you unzipped the tools

    Edit: for fastspin it is maybe better to download spin2gui
  • Cluso99Cluso99 Posts: 18,066
    edited 2019-04-24 06:18
    This json file will build a P1 binary using c:/Propeller/fastspin.exe
    Works on Windows and hopefully will work on linux and mac.
    Change the command path below if fastspin.exe is in another directory.

    Warning: Check there is no tasks.json file present first! If so, make sure you save it elsewhere first.
    As far as I can tell so far, there is no way to have multiple tasks.json files present.

    Save it as/in %userprofile%/.vscode/extensions/.vscode/tasks.json

    To compile in VSC place cursor in the source file and press Ctl-Shift-B which will open a terminal window and compile it. Check for errors.
    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558 
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Compile",
                "type": "shell",
                "windows": {
                    "command": "C:/Propeller/fastspin ${file}"
                },
                "linux": {
                    "command": "C:/Propeller/fastspin ${file}"
                },
                "osx": {
                    "command": "C:/Propeller/fastspin ${file}"
                },
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    
  • Cluso99Cluso99 Posts: 18,066
    This json file is for compiling P2 using fastspin.
    (see previous post for details of where to install it and note the warning)
    Note this means that both P1 and P2 tasks.json files cannot co-exist until I find a way around this :(
  • Ahle2Ahle2 Posts: 1,178
    @Cluso99

    No I have no experience with VSC actually, yesterday was my first time trying it because I wanted to try out your syntax highlighting. (ofcourse, as a developer I have heard a lot about VSC, but never tried it myself). I instantly fell in love with it and everything is intuitive and visually pleasing. 10 minutes googling and fiddling, I had the json file configured to run my SIDcog project with a keyboard shortcut. I love it. I just migrated from PNUT! :smiley:

    I love how the project directory itself is the workspace/project and that you you can have all build related things in the standard ".vscode" directory in your project directory. I don't think it's neccessary to even have a Makefile or an external buildsystem (for C/C++, java.. etc); Just make the json file do everything. All you have to do is to setup the paths to compiler/loaders the right way. I'm not entirely sure about my own claim, but I will try it out. I need to read up on tasks and what can be done.

    Why not make some kind of standard script or installer that can download/configure everything for developing P2 code using VSC on any platform. In the end it might be possible to just make a copy of a project directory and run it on any platform that is setup the "standard P2 way".


  • Ahle2Ahle2 Posts: 1,178
    Thinking a little mor about it, a Parallax supported VSC standard config might be exactly what will make the P2 a worthy alternative for "serious" embedded developers. VSC is by far the most beloved editor in 2019 according to different surveys. Everybody seems to love it. And because it is the defacto standard nowdays, developers will feel at home right away. Configured the right way it becomes a fully featured IDE.
  • Ahle2Ahle2 Posts: 1,178
    Cluso99 wrote: »
    This json file will build a P1 binary using c:/Propeller/fastspin.exe
    Works on Windows and hopefully will work on linux and mac.
    Change the command path below if fastspin.exe is in another directory.

    Warning: Check there is no tasks.json file present first! If so, make sure you save it elsewhere first.
    As far as I can tell so far, there is no way to have multiple tasks.json files present.

    Save it as/in %userprofile%/.vscode/extensions/.vscode/tasks.json

    To compile in VSC place cursor in the source file and press Ctl-Shift-B which will open a terminal window and compile it. Check for errors.
    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558 
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Compile",
                "type": "shell",
                "windows": {
                    "command": "C:/Propeller/fastspin ${file}"
                },
                "linux": {
                    "command": "C:/Propeller/fastspin ${file}"
                },
                "osx": {
                    "command": "C:/Propeller/fastspin ${file}"
                },
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

    You do know that you can have ".vscode/tasks.json" in your project directory, right? That way you can have each project configured exactly the way you want it. Then I don't think it's a good idea to have absolute paths to compilers/linkers/loaders. Setting up environment variables makes more sense if you want tasks.json to be deployable on any system for any Propeller user out there. There might be a way of making some kind of template tasks.json that can be automatically configured for each P1/P2-project you start in vscode?!
  • Cluso99Cluso99 Posts: 18,066
    Ahle2 wrote: »
    You do know that you can have ".vscode/tasks.json" in your project directory, right? That way you can have each project configured exactly the way you want it. Then I don't think it's a good idea to have absolute paths to compilers/linkers/loaders. Setting up environment variables makes more sense if you want tasks.json to be deployable on any system for any Propeller user out there. There might be a way of making some kind of template tasks.json that can be automatically configured for each P1/P2-project you start in vscode?!
    I thought that I tried it in the project directory but it could have been before I got it working.
    I've been reading about multiple selectable tasks within the tasks.json file so I will be trying that. And I'll try putting the json file in the project directory again.

  • Ahle2 wrote: »
    I don't think it's neccessary to even have a Makefile or an external buildsystem (for C/C++, java.. etc); Just make the json file do everything.

    As far as I can tell, it doesn't do that. (Unless you want to use a C++ compiler in whole-program mode)

  • Ahle2Ahle2 Posts: 1,178
    @Wuerfel_21
    After reading up on this, it seems that you are right. There is no built in mechanism to only compile altered files.
  • To get the most out of VSCode with a C/C++ project, you'd want to combine it with CMake and the CMake Tools VSCode extension: https://vector-of-bool.github.io/2018/07/20/cmt-1.1.0.html
    But yes - that does mean installing two more tools on your system (CMake + some kind flavor of make) on top of VSCode and your toolchain. But you'd get a lot more IDE features out of it than you otherwise would.
  • Cluso99Cluso99 Posts: 18,066
    edited 2020-07-16 05:48
    Might be time to bump this thread :sunglasses:

    I haven't done any more with automating VSC but I do edit all my P1 and P2 programs now with VSC. I use VSC daily with Python for work.
    VSC handles python and spin/pasm/spin2/pasm2 just fine. I just need to get the P1 and P2 compilers working from VSC. Just not enough hours in the day :(

    I note in todays VSC release there are new buttons for compile and debugging, obviously with 3rd party extensions.

    And the VSC release today now has an ARM supported version release too!
  • I'm back... It's been a while since I've been on the forums

    I got my P2 yesterday (8/27/2020)

    One thing I'm interested in is spin2 integration with Visual Studio Code; is any one working on it; if not, I'm interested in working on it.

    Jay
  • Cluso99Cluso99 Posts: 18,066
    I use VSC for all my P2 editing. It highlights most of the words, etc.

    But there is no integration with fastspin/pnut/PropTool for compiling.
    IMHO fastspin would be the preference for calling a compiler as it works on all platforms.

    Doing this would be great - I'm not really up to the task to do it. You can add a compile button to VSC according to recent docs.
Sign In or Register to comment.