Vscode + Leo
Vscode + Leo
Sunday, July 5, 2020
1:16 PM
Winget based recipe
winget install vscode
winget install vscode-python
gitclone --depth=500 --no-single-branch https://github.com/leo-editor/leo-editor
cd leo-editor
pipx install .
pipx inject leo websockets
Pipx lets us use Leo as a regular program, bypassing needing to setup a custom Conda environment etc.
────────────────────────────────────────────────────────────────────────────────
Older recipe
I now use winget and Micromamba instead of Chocolatey and Miniconda.
Chocolatey and Miniconda/Anaconda setup recipe for leointeg, a plugin to enable Visual Studio Code to use Leo Editor as an engine for working with outlines and nodes and clones.
Starting point: a Win10 admin command prompt with Chocolatey installer, Conda, and Git in PATH. I pinned python to 3.6 as that is Leo's current minimum python version. Adjust to suit your preference.
Admin prompt
:: Install Visual Studio Code & python support, Node.js
choco install vscode vscode-python nodejs
Normal command prompt:
:: Create anaconda environment for Leo & Leo-integ
conda create -n vscode-leo
conda activate vscode-leo
conda install python=3.6
:: Install Leo & dependencies
pushd code
pip install --editor .\leo-editor
:: Install Leointeg python dependencies
pip install websockets
:: Install Leointeg & Node.js dependencies
git clone https://github.com/boltex/leointeg
cd leointeg
npm install
npm audit fix
Run vscode
Open Folder >> path\to\leointeg
"This workspace has extension recommendations" >> Install All
Open command pallete [Ctrl-Shift-P]
- type "select inter" and chose "Python: Select interpreter" from the list. Status bar will indicate search for and caching of python environments, followed by list of conda environments. >> Choose the leointeg one, e.g.
c:\tools\miniconda3\envs\vscode-leo\python.exe
- Using same technique, change 'Default Terminal' to Command Prompt instead of Powershell. (Apparently if you use Powershell there's more manual things to do.)
Run Extension
- [Ctrl-Shift-D] to open debugger side panel, then
- Press play button (right pointing green triangle) - [F5]
Vscode will open a new window in foreground. The background vscode window should have a highlighted bottom status bar and show the leointeg conda python environment.
The foreground window should be titled "Extension Development Host". From it Open Folder and point to your Leo stuff. A "Welcome to Leointeg" page opens.
Switch back to the original vscode window. Open a terminal in vscode [Ctrl-Shift-`] and start the leobridge server manually.
python leobridgeserver.py
Now switch to the dev host and in left hand menu >> Leo Integration >> [Connect to Server].
When connection is established an [Open Leo File] button should replace [Connect to Server].
….
When things don't work, look to the [Debug Console] panel in the original Vscode window.
What seems to be needed in every new vscode session:
- Selecting the python interpreter
- Running "python leobridgsever.py"
I'm confident there's a way to automate this, somewhere.
Sources
- How to run the Leointeg extension: https://github.com/boltex/leointeg/blob/master/CONTRIBUTING.md
- Setting and using Python environments in Vscode: https://code.visualstudio.com/docs/python/environments
Created with OneNote.