Shop OBEX P1 Docs P2 Docs Learn Events
Visual Studio Code supports P2 development on Windows, Mac, Linux (yes, RPi) — Parallax Forums

Visual Studio Code supports P2 development on Windows, Mac, Linux (yes, RPi)

Stephen MoracoStephen Moraco Posts: 316
edited 2021-05-26 19:38 in Propeller 2

Visual Studio Code is an extendable code editor that runs natively on Windows, Linux (inclu. Raspberry Pi), and Macs. There are compilers for P2 Spin/Pasm for Windows (PNut and PropTool) and for Windows, Linux, and Macs (FlexProp).

In support of the P2, we developed a Spin2(Pasm2) extension which is currently in the VSCode marketplace which provides syntax and semantic highlighting for Spin2/Pasm2. This extension once installed will automatically notify you of new update availability whenever new updates are published.

Setting up to develop on your platform of choice is relatively simple:
The steps are explained in detail in the VSCode P2 QuickByte

Basically, they are:

  • Install VSCode
  • Install the Spin2 extension along with a couple more recommended extensions
  • Install your chosen compiler(s)
  • Configure your project (add compile and download steps for compiler your using)
  • Start iteratively developing and testing your spin2/pasm2 code

NOTE: the Spin2 extension is new since the Spin (for P1) extension was released. So if you want P1 and P2 support, install them both. Eventually, as I wrap up current projects I'll backport this latest extension to the P1 but this is likely months away...

«1345678

Comments

  • Update, here's what I'm working on... (in between my RGB LED Matrix driver efforts)

    - (1) Language syntax highlighting - our SPIN2/PASM2 languages together have some 800ish keywords... I'm only partway done adding them. I have created the definition for the autoclose behavior for this language and that's working well. Work in progress

    - (2) Outline navigation of the current file does not work for SPIN/PASM. I've started to add it but my initial attempt is not yet working. I found an example project to start from. This will probably be one, maybe two, pages of code. This is not a large effort. (it's written in TypeScript). Work in progress

    - (3) I've been playing with packaging the extensions. I finally know how to, and have successfully generated my first .vsix files. These are what get distributed to the marketplace, eventually, but for now, I'll just post them here when we have updates. Work in Progress

    - (4) The theme needs to be updated once the syntax highlighting is working as that creates the names of objects that can be colored. Work in progress

    - (5) We need to add the compile and download mechanism yet. Setting it up and testing - Work in Progress. I've worked in vscode environments where it watches for file saves and then automatically compiles. This seems like what we want, right? (with downloads only attempted when compile succeeds, of course.)

    I just wanted to indicate that progress is being made. If any of you happen to have experience building vscode extensions or happen to know someone that does that would be willing to help, please contact me. I'd welcome the help! Of course, I'll keep pushing on this.

    I'm planning on doing the next release for us all to play with when I get (1) further along and (4) sync'd to it.

    After that, I'll push new updates when we fix things we've found and/or as (2) and (5) get completed.

    I'm using what I have so far, daily! It is getting better... it's just taking time!

    Regards,
    Stephen
  • Cluso99Cluso99 Posts: 18,069
    Nice work Stephen :)
  • Well, things have progressed well.
    I'm attaching the latest vscode extension. It's a zip file. Download it and unzip it.

    Then you can do a manual install by using the command-line shown in these INSTALL instructions

    You may want to review what vscode extensions you have installed and then remove any earlier versions. (They are likely "spin1", "spin2", and "spin-theme" in your extensions directory.)

    Please let me know what you think of this so far. This should work pretty well with your favorite theme. I have included the "Spin2 IronSheep" theme which is what I use during verification of the work. It's pretty colorful so I can tell quickly which parts are working. However, this is what I'm also using day-2-day so it functions well.

    Once you have this installed, then please take the time to find it in your list of installed extensions. Once you find it, you'll see three tabs on that page, please review them as I'll change the content there with each new release. They are "Details", "Feature Contributions" and "Changelog". Details has operational notes for you while the Changelog has specifics about what's working, what's not, problems we already know of, etc. Also, you'll see a list of things we are next working on. See it is things you'll want to review each time, right?

    Alright. Enjoy! Please let me know if you like the progress so far and where it's heading.

    Regards,
    Stephen
  • You guys are now on the hook for a quick demo of VSC at a future P2 Live Forum.

    Ken Gracey
  • Here's a quick intro to the new Spin2/Pasm2 VSCode Extension:



    Enjoy!
  • Cluso99Cluso99 Posts: 18,069
    TIA Stephen. This is a great step forward :)

    I'll let you know how it goes but it will not be until mid-week as I have to concentrate on getting some other things done while fitting in with work.
  • Nice Stephen!
  • That’s fantastic! (Good to know it runs on Mac! LOL)
  • Ok, time to put this to work!

    This new version v0.2.0 complete's the Pasm2 and Spin2 language definition as well as add all Streamer constants and SmartPin constants.

    Let's exercise this and please let me know if you see things that could/should be improved.

    I'm taking a break now since this is fully functional to get back to my RGB LED Matrix driver and hopefully scheduling PCB production.

    Meanwhile, you can advise what you think the priority for my next efforts on this extension should be from amongst items that are shown in the ChangeLog "Unreleased" section.

    Please tell me which are most important to you in how you use vscode! If I'm missing something important, please note that for me too!

    Regards,
    Stephen
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-11-10 23:04
    Congratulations Stephen :smiley:
    works nicely, outline is a great feature too!

    Windows installation notes

    Unzip file
    Unzip the zip file to extract "spin2-?.?.?.vsix" and copy/move it to your windows %userprofile% folder (ie C:\Users\<username>\ so mine is C:\Users\Ray\ )

    Install vscode extension (manually)
    Open a windows command prompt (Start | Windows System | Command Prompt)
    C:\Users\Ray>
    enter "code --install-extension spin2-?.?.?.vsix" without the double-quotes (replace the '?' wildcards with the version number)

    Close the command prompt window and we're done.

    Here is the command prompt dialog (note the warning)
    Microsoft Windows [Version 10.0.18363.1139]
    (c) 2019 Microsoft Corporation. All rights reserved.
    
    C:\Users\Ray>code --install-extension spin2-0.2.0.vsix
    Installing extensions...
    (node:7652) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
    Extension 'spin2-0.2.0.vsix' was successfully installed.
    
    C:\Users\Ray>
    
    vsc-spin2-0.2.0.jpg
    852 x 708 - 147K
  • Cluso99Cluso99 Posts: 18,069
    Stephen,
    Just noticed that some color formatting is being lost, possibly due to nested if statements. See the attached jonnymac serial driver from line 398 onwards.
  • Stephen MoracoStephen Moraco Posts: 316
    edited 2020-11-17 05:26
    Cluso99 wrote: »
    Just noticed that some color formatting is being lost, possibly due to nested if statements. See the attached jonnymac serial driver from line 398 onwards.

    Thanks for the heads up! I've also found a couple of things. Give me a couple of days and I'll roll in updates... And by all means, keep reporting anything any of you find!
  • Cluso99 wrote: »
    Just noticed that some color formatting is being lost, possibly due to nested if statements. See the attached jonnymac serial driver from line 398 onwards.

    Well, that's a challenging case!

    The issue is that "\" is recognized as a start of a string with a contained \" (escaped double quote) so the end of the string is not matched. I'm looking to see if I can build a stronger definition of strings that wouldn't suffer this issue. We'll see.

  • Stephen MoracoStephen Moraco Posts: 316
    edited 2020-11-25 21:17
    Ok, I adjusted the string recognizer to not look for escape sequences for now. I'll review how the spin language supports escape sequences and then try to match it.

    For now, this gets us past the issue. v0.2.1 attached!
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-11-28 23:42
    Thanks Stephen :)
    Installed v0.2.1 today.
    Noticed this problem - maybe another case of "\" ???

    VSC-spin2-v0.2.1-bug.jpg
    '+-----------------------------------------------------------------------------+
    go_command  mov     priv_bufad,   ##DISK_BUFF         ' ensure correct hub buffer
                setq    #3-1
                wrlong  priv_copy,    ##mbox_copy         ' give aux/sector/bufad to SD mailbox
                wrbyte  priv_command, ##mbox_command      ' give command to SD Driver
    .wait       rdbyte  tmp,          ##mbox_command  wz  ' wait until cleared ie done
        if_nz   jmp     #.wait                            '
                rdbyte  priv_status,  ##mbox_status   wz  ' get status
                setq    #3-1
                rdlong  priv_copy,    ##mbox_copy         ' get  aux/sector/bufad from SD mailbox
                wrbyte  #0,           ##mbox_status       ' clear status
        if_z    RET                                       ' return with "Z"=success
    
                mov     lmm_p,        ##str_sd_err
                call    #\_hubTxStr
                mov     lmm_x,        priv_command
                call    #\_hubTx
                call    #\_hubTxCR
                call    #\_hubMonitor
                RET                                       ' permit monitor to continue
    '+-----------------------------------------------------------------------------+
    
    '+-----------------------------------------------------------------------------+
    '+ print_msg  Prints a string according to the number in lmm_lc                +
    '+ input:   lmm_lc = msg number to be printed                                  +
    '+ returns: lmm_p  = ptr to next string                                        +
    '+ uses:    lmm_x  = unknown                                                   +
    '+-----------------------------------------------------------------------------+
    print_msg00 mov     lmm_p,      ##@msg00        ' message list in hub
    print_msg   mov     lmm_lp2,    lmm_lc      wz  ' copy message#
        if_z    jmp     #.found                     ' j if message# =0
    .look       rdbyte  lmm_x,      lmm_p       wz  ' end of string?
                add     lmm_p,      #1              ' addr++
        if_nz   jmp     #.look                      ' keep looking
                djnz    lmm_lp2,    #.look          ' found the right message# ?
    .found      call    #\_hubTxStr                 ' print message#
                RET                             wcz ' & restore flags
    '+-----------------------------------------------------------------------------+
    
    846 x 746 - 146K
  • Buck RogersBuck Rogers Posts: 2,185
    edited 2020-11-29 05:53
    Good catch. I wanted to include something else, but, ah, I changed my mind and removed it.

    ---
    No mascot today.


    Erco why is there a mountain lion studying your car?

  • Cluso99 wrote: »
    Noticed this problem - maybe another case of "\" ???

    I'll bet you are correct! Sigh...

    This will be a couple of days. I'm trying to get my Hub75 driver into P2 Obex later this week. I'll look at this after.

    Thanks for the testing, use, and heads up! Please keep reporting anything you find.

  • Here's another small update - added missing named unary/binary operators to spin2


    Enjoy!
  • Cluso99Cluso99 Posts: 18,069
    Thanks Stephen - just installed :)
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-12-04 22:37
    Stephen, just noticed this - the comment on the pub line is white ie not colored
    con { cluso's hub dump routines }
    pub hubdump(addr1, addr2) | addr, addrend, i, j                             ' format and print set(s) of 4 longs from hub (16 byte boundaries)
      addr := addr1 & $ffff0                                                    ' round down to 16 byte boundary
      if addr2 == 0
        addrend := addr                                                         ' default 1 line (16 bytes)
      else
        addrend := addr2 & $ffff0                                               ' round down to 16 byte boundary
    

    and just this line
    PUB main()                                                      ' The main (top level) routine
    
  • @Cluso99 not sure if this will still reach you but I'm now using a P2 and a P1 with VSC and the FlexProp tools. I have a code highlighter (entomy.spin) extension that works for .spin files and I'm searching around the web and forums for a way to also link the .spin2 filetype. It's confusing so far. I don't think you do it in the extension itself. Any ideas on that? I read something about adding to a settings.json file entry but couldn't get to the details.
  • Cluso99Cluso99 Posts: 18,069
    edited 2021-01-12 09:00
    IIRC there is a link in the first post to how i did it although i built on top of another’s work. But what Stephen has done is much better. Just go back thru this thread. I don’t recall much anymore.
  • @Cluso99
  • @Cluso99 - I found the place for that language association setting. Just stumbled onto it after a lot of online searching failed me. At the lower right of the screen there's a little area for notifications, tweeting, choosing encoding modes, etc. In there is a selector for language association. I now have .spin2 files matched up with .spin so the code highlighter extension works for both. Maybe others already know this but it took me a while to find it.
  • Cluso99Cluso99 Posts: 18,069
    edited 2021-01-12 20:36
    We have used a different set of selections for spin vs spin2 as the languages are different.

    Thanks for posting what you’re finding :)

    Have you tried Stephens addon? Works nicely. It would be good to extend this to add the compilation options/button. Stephen is a bit preoccupied with the LED panels currently.
  • I haven't tried Stephen's add-on. I just took the one that popped up from the market place in the software and it seems to highlight the keywords, code blocks and maybe a couple other things, which seemed to be what I wanted. I added my own compile/run shell files to the VSC tasks and it seems to do just what I want. I guess I don't know what I'm missing, if anything. Plus I added the .spin to .spin2 connection I mentioned above.

  • Cluso99Cluso99 Posts: 18,069
    Is the marketplace Spin2 v0.2.2 from IronSheep? If so, that is Stephen's extension.
    I didn't realise it didn't do .spin files as I just tried.

    Perhaps you could detail how you added the compile/run tasks here please :)
  • Here's the first part of the tasks.json file from my VSC workspace. You're probably familiar with that, or can find it. "RunSpin" is what shows up in the pop up menu of tasks when you're working, and assigning to a keystroke. "flexrun.sh" is my UNIX shell command to do the compiling and running from the command line, and it receives the filename without extension from that ${} parameter in here. Let me know of any other questions. Some of those other parameters in there don't seem important, or even to do anything in my testing.

    The spin extension I have from the Marketplace is by Entomy. I don't see any others. The one you mentioned involves getting from github and installing I guess. I didn't want to get into that level of learning yet. I'm finding enough to learn just patching together miscellaneous stuff to get software going for my P2 board.

    My post a couple back shows how to add .spin2 recognition to the .spin VSC extension, but I also found where that is in the settings files, too, if you need that method.

    Now (minor annoyance, not problem) I'm looking for a way to add recognition of __asm { } to the C/C++ extension I have from Microsoft. I get squiggly line warnings of non-recognition even though the actual code is fine. I've been poking around VSC and the internet with no luck so far. The __asm { } thing is a feature of Eric's FlexProp and not known by Microsoft's extension of course. So it's up to a wanna be gearhead to patch things together. Fun, but ......

    {
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
    {
    "label": "RunSpin",
    "type": "shell",
    "command": "flexrun.sh ${fileBasenameNoExtension}",
    "presentation": {
    "echo": true,
    "reveal": "always",
    "focus": true,
    "panel": "shared",
    "showReuseMessage": false,
    "clear": false
    },
    "problemMatcher": []
    },
    {
    "label": "RunSpin2",
    "type": "shell",
    "command": "flexrun2.sh ${fileBasenameNoExtension}",
    "presentation": {
    "echo": true,
    "reveal": "always",
    "focus": true,
    "panel": "shared",
    "showReuseMessage": false,
    "clear": false
    },
    "problemMatcher": []
    },
  • Here's the previous tip so you don't have to dig it out.

    At the lower right of the screen there's a little area for notifications, tweeting, choosing encoding modes, etc. In there is a selector for language association. I now have .spin2 files matched up with .spin so the code highlighter extension works for both.

    Otherwise you can (Cmd-P on Mac) search for "language specific settings" and get into this .json, which is where it put my additional association apparently.

    {
    "workbench.colorTheme": "Default Light+",
    "files.autoSave": "off",
    "explorer.confirmDelete": false,
    "files.associations": {
    "*.spin2": "spin"
    },
    "[c]": {

    "editor.wordBasedSuggestions": false,
    "editor.suggest.insertMode": "replace",
    "editor.semanticHighlighting.enabled": true
    }
    }
  • In this posting: https://forums.parallax.com/discussion/comment/1513993/#Comment_1513993 I described a tasks.json that does not require a flexrun.sh type of script. You do have to edit it a bit to customize it for your system, but should work without adding any scripts to your flexprop directory.

    dgately
Sign In or Register to comment.