Picaxe with Visual Studio Code

Flenser

Senior Member
shon242,

I don't remember how this worked when I first tried VS code several years ago but with the v1.73.1 version of VS code neither the syntax highlighting nor the F4, F5 & F6 keybindings work and this is because in the current version of VS code the default language for files with the ".bas" extension is now set to Visual Basic.

Provided that you have followed the instructions on the Visual Studio Code - Software - PICAXE page to install the picaxe extensions then you can set the file association for ".bas" files permanently to "PICAXE Basic" in v1.73.1 this way:
Open a file with the ".bas" extension
Press ctrl-k, m to bring up a pulldown list named "Select Language Mode". (press ctrl-k, release the keys and then press m)
Choose the option "Configure File Association for '.bas'...". This will give you another pulldown list to choose from.
Scroll down and select "PICAXE Basic". If you type the first few characters of "picaxe" it will filter the list to just those options that start with "pic".


Hippy,

I recently setup Visual Studio Code to try it out. The VS code interface has changed such that the instructions on the Visual Studio Code - Software - PICAXE page to setup Keybidings are out-of-date.

These are the existing "Setup Keybindings" instructions:

Select the File, Open File menu option, and select the keybindings/keybindings.json file downloaded and unzipped earlier.
Select the File, Preferences, Keyboard Shortcuts menu option.
This will bring up two additional "keybindings.json" edit windows. The middle one is the global bindings, the one on the right are personal bindings.
Copy the keybindings.json contents from the left window into the personal bindings to the right hand edit window.

Close and save the right hand personal bindings window, close the other two windows.

This is the process I needed to use to setup the keybindings in the current v1.73.1 version of VS code:

Select the File, Open File menu option, and select the keybindings/keybindings.json file downloaded and unzipped earlier.
Select the File, Preferences, Keyboard Shortcuts menu option.
This will bring up the Keyboard Shortcuts Window.
Choose the Show User Keybindings command from the More Actions (...) menu in the top left-hand corner of the Keyboard Shortcuts Window. The firast time you alter these it will bring up a window with an empty User Keybindints json file.
Copy the keybindings.json contents from the left window into the right-hand User Keybindings window.
Close and save the right-hand User Keybindings window, close the other two windows.

NOTE: After you have updated the User Keybindings json file choosing Show User Keybindings command from the More Actions (...) menu will display a list of editable keybindings, not the json file.
To configure keyboard shortcuts through the JSON file, open Keyboard Shortcuts editor and click the Open Keyboard Shortcuts (JSON) button on the right of the editor title bar.
 
Last edited:

hippy

Ex-Staff (retired)
This is the process I needed to use to setup the keybindings in the current v1.73.1 version of VS code:
Many thanks for the tips. I must admit I haven't used VS Code for quite a few years so guess I'll have to give it another go and see what can be done about updating any out of date instructions.
 

Flenser

Senior Member
I forgot to add that you can also enable syntax checking for include files by opening a file with the ".basinc" extension and following the same procedure.
 

shon242

New Member
Choose the Show User Keybindings command from the More Actions (...) menu in the top left-hand corner of the Keyboard Shortcuts Window. The firast time you alter these it will bring up a window with an empty User Keybindints json file.
Copy the keybindings.json contents from the left window into the right-hand User Keybindings window.
Close and save the right-hand User Keybindings window, close the other two windows.

NOTE: After you have updated the User Keybindings json file choosing Show User Keybindings command from the More Actions (...) menu will display a list of editable keybindings, not the json file.
To configure keyboard shortcuts through the JSON file, open Keyboard Shortcuts editor and click the Open Keyboard Shortcuts (JSON) button on the right of the editor title bar.


I think I've done all of this. But pressing F4 does nothing. Visual Studio reads the PICAXE Basic file, but I feel like I missed a step or two, but I don't know where else to look. Can you help?

Also my tasks file seem to be empty.... :(
 

Attachments

shon242

New Member
Hi again,

I got it working :) :)!

I did not realize that the tasks.json was hidden inside of the zip file provided by picaxe. Silly mistake. I moved it over and chaged the path to my folder to where i put the compilers.

Question: Do I need to change the "command" path whenever I use a different chip? In other words I need to change the command path to the correct compiler for each chip..
 

Attachments

Flenser

Senior Member
As you have noticed the tasks.json file has the path to a single compiler.
e.g. On the RevEd web page https://picaxe.com/software/third-party/visual-studio-code/index.html#download
in the section "Setup tasks" they give an example with the full path to the picaxe08m2.exe compiler.

The extra bit of information you need is that VSCode can be used for a lot of different languages so they need a way to switch the keybindings when you change which project you are working on.
I'm don't use VSCode, so don't take what I say as fact, but it appears that you choose a folder to specify which language you are working with.

We can use this to compile programs for different chips without needing to edit the tasks.json file.

If you create a directory structure with one Keybindings directory for each PICAXE chip that has a .vscode directory with the tasks.json file edited to have the compiler for that chip, somethine like this:
25697

Then, when you want to compile for the 14m2 choose "Open Folder" and choose the "14m2 Keybindings" folder.
Then any program you compile will use the 14m2 compiler until you open a different Keybindings folder
25694

If you open a program with the directive for another chip, like #PICAXE 08M2 then it will still use the 14M2 compiler until you change the Keybindings folder.
25695

Open the 08M2 Keybindings folder to change the tasks.json file:
25696
 
Last edited:

shon242

New Member
Hi,

I finally had some time to try this out. So I copied the keybindings into .vscode and the tasks.json(modified to point to each individual executable), then I copied the hidden .vscode folder into my working directory and that seemed to work.

So for me I just copied the .vscode folder into my directory where I am writing the code.

I will say I have to restructure my directory to separate the .bas files based on compiler, but maybe that is not a bad thing.

Thank you for your time @Flenser .
 

Flenser

Senior Member
I will say I have to restructure my directory to separate the .bas files based on compiler
shon242, That is not necessary. Your choice of which keybindings folder you use (and which compiler will be used) is completely seperate from where you store your programs.

The multiple keybindings folders are intended to operate as closely as possible as the"PICAXE Type" field in PE.

The .bas file you open in PE will be verified or compiled by the compiler you have selected in the "PICAXE Type" field.
- If your program has a different chip specified with a #PICAXE directive then PE will prompt you to change the PICAXE Type.
The .bas file you open in VS Code will be verified or compiled by the compiler in the keybindings folder you have opened.
- If your program has a different chip specified with a #PICAXE directive then your verify or compile will fail and you will have to open a different keybindings folder to change the PICAXE Type.

If you have a closer look at the screen capture of the directories in my post #8:
- There is one copy of the .bas test files in the folder Picaxe_programs
- There are the two keybindings folders "08m2 Keybindings" and "14m2 Keybindings" in the folder Picaxe_programs.

Open the file Picaxe_programs/test2.bas. This program has the compiler directive "#PICAXE 08M2'
Open the folder Picaxe_programs/08m2 Keybindings
Press F4 and test2.bas is successfully verified using the 08m2 compiler
Open the folder Picaxe_programs/14m2 Keybindings
Press F4 and test2.bas now fails verification using the 14m2 compiler with the error "#picaxe 08M2 - invalid type for this compiler!"

I put the two test programs in the parent folder Picaxe_programs but you can put them anywhere you like.
I might create a set of project folders under the parent folder Picaxe_programs , something like this:
25752

The .bas files in my project folders can be for any chip. There is no need to separate the .bas files based on compiler.
 
Top