VSCode uses a regular expressions engine that is based on Ruby for syntax highlighting.
This Rubular site is good site to test and try out these regular expressions because it uses Ruby which supports oniguruma
flavor of regular expressions.
We pretty much followed these instructions for building this extension. And this link for packaging the extension.
To summarize, the steps were:
npm install -g yo generator-code
yo code
- choose "New Language Support" and fill out the rest of the questions
npm install -g vsce
- update the
README.md
andpackage.json
vsce package
code --install-extension vscode-nushell-lang-0.0.2.vsix
(Alternatively, you can do Ctrl/Cmd-Shift-P and type "Extensions:Install From VSIX...")
If you have all these tools already installed, you should be able to clone this repo and just run vsce package
to get a .vsix
file that you can install in vscode.
- Clone this repo
- In repo folder
npm install
- Hit F5 to start debugging (or Run->Start Debugging menu item)
- Go to settings with
Ctrl ,
orCmd ,
- In the settings tree on the left, go to Extensions->Nushell IDE Support and make sure
Nushell Executable Path
is pointing at where you have nu/nu.exe installed. (It must be version 0.79.0 or greater) - Open a nushell script and in a moment you should see inlays and see the full functionality
- To see the Language Server debug messages hit
Ctrl ~
- Go to the output tab
- In the combo box on the right, choose
Nushell Language Server
. You should now see debug messaging as the client and server communicate
TIL - VSCode uses regexes for language syntax highlighting in *.tmLanguage.json files. Those regexes and json are based on Textmate, which uses (and here is the secret-sauce) oniguruma
flavor of syntax. See the cheat-sheet for the syntax here. Also there's a rust-crate called onig
or rust-onig
if we wanted to write something to help create compatible regular expressions.
glcraft wrote a fancy program to create regexes for the extension. Here's the steps to use it.
- clone and cargo install the tool. https://github.com/glcraft/list-to-tree
- on windows create a set of commands.
scope commands | where type == built-in or type == keyword or type == plugin | get name | to text | save win-cmds_20240923.txt
- on linux create a set of commands.
scope commands | where type == built-in or type == keyword or type == plugin | get name | to text | save lin-cmds_20240923.txt
- combine these two files, sort, and uniq them.
open win-cmds_20230919.txt | lines | append (open lin-cmds_20230919.txt | lines) | sort | uniq | save cmds_20230919.txt
- run list-to-tree
list-to-tree --input cmds_20230919.txt --format regex
- copy-n-paste the results to the
nushell.tmLanguage.json
file in the appropriate place (search for "list-to-tree"). Be careful, this can be tricky. - test out the changes with F5 and viewing some scripts.