Skip to content

Commit

Permalink
Cursorless in neovim / terminal (#2256)
Browse files Browse the repository at this point in the history
![neovim_take](https://github.com/cursorless-dev/cursorless/assets/387346/e72acd0d-fee2-4bae-a8b1-0cf8644c0ecf)

![neovim_clone_cut_post_drink](https://github.com/cursorless-dev/cursorless/assets/387346/20041f0d-8ff1-41b8-a2bd-02bc353ad8c5)

![neovim_terminal](https://github.com/cursorless-dev/cursorless/assets/387346/423b6d29-a1e4-4910-8a4e-32acd5dd3c5b)

# Repositories

This currently relies on:
* https://github.com/saidelike/cursorless/tree/nvim-talon (this PR) 
* compiled and pushed to
https://github.com/hands-free-vim/cursorless.nvim (neovim cursorless
plugin)
* https://github.com/saidelike/command-server/tree/neovim
  * compiled and pushed to cursorless mono repo
* https://github.com/hands-free-vim/talon.nvim (neovim talon plugin)
* https://github.com/hands-free-vim/neovim-talon (talon commands for
neovim: command-client, commands for navigating/editing/split/tabs in
editor. Deprecates https://github.com/fidgetingbits/talon-vim)

# Todo

- [x] hands-free-vim/neovim-talon#20
- [x] hands-free-vim/neovim-talon#24

# Checklist for pokey

The below list can be useful to review the code since some files are
based on vscode similar files.

- packages\cursorless-neovim-e2e\src\suite\recorded.neovim.test.ts
versus packages\cursorless-vscode-e2e\src\suite\recorded.vscode.test.ts
- packages\cursorless-neovim-e2e\src\endToEndTestSetup.ts versus
packages\cursorless-vscode-e2e\src\endToEndTestSetup.ts
- packages\cursorless-neovim\src\constructTestHelpers.ts versus
packages\cursorless-vscode\src\constructTestHelpers.ts
- packages\cursorless-neovim\src\extension.ts versus
packages\cursorless-vscode\src\extension.ts
- packages/cursorless-neovim/src/NeovimCommandServerApi.ts versus
https://github.com/pokey/command-server/blob/main/src/extension.ts#L32
- packages/cursorless-neovim/src/registerCommands.ts versus
packages/cursorless-vscode/src/registerCommands.ts
- packages\neovim-common\src\TestHelpers.ts versus
packages\vscode-common\src\TestHelpers.ts
- packages\neovim-common\src\getExtensionApi.ts versus
packages\vscode-common\src\getExtensionApi.ts
- packages\neovim-common\src\ide\neovim\NeovimCapabilities.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeCapabilities.ts
- packages/neovim-common/src/ide/neovim/NeovimClipboard.ts
 vs packages\cursorless-vscode\src\ide\vscode\VscodeClipboard.ts
- packages\neovim-common\src\ide\neovim\NeovimEdit.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeEdit.ts
- packages\neovim-common\src\ide\neovim\NeovimEvents.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeEvents.ts
- packages\neovim-common\src\ide\neovim\NeovimFileSystem.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeFileSystem.ts
- packages\neovim-common\src\ide\neovim\NeovimGlobalState.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeGlobalState.ts
- packages\neovim-common\src\ide\neovim\NeovimIDE.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeIDE.ts
- packages\neovim-common\src\ide\neovim\NeovimMessages.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeMessages.ts
- packages\neovim-common\src\ide\neovim\NeovimTextDocumentImpl.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeTextDocumentImpl.ts
- packages\neovim-common\src\ide\neovim\NeovimTextEditorImpl.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeTextEditorImpl.ts
- packages\neovim-common\src\ide\neovim\NeovimTextLineImpl.ts vs
packages\cursorless-vscode\src\ide\vscode\VscodeTextLineImpl.ts
- packages\neovim-common\src\ide\neovim\hats\NeovimHats.ts vs 
- packages\neovim-common\src\{neovimApi,neovimHelpers}.ts vs
https://code.visualstudio.com/api/references/vscode-api
- packages\neovim-common\src\runCommand.ts vs
packages\vscode-common\src\runCommand.ts
- packages\neovim-common\src\testUtil\openNewEditor.ts vs
packages\vscode-common\src\testUtil\openNewEditor.ts
- packages\test-harness\src\index.ts vs
packages\test-harness\src\runners\extensionTestsVscode.ts
- packages/test-harness/src/launchNeovimAndRunTests.ts vs
packages/test-harness/src/launchVscodeAndRunTests.ts
- packages/test-harness/src/scripts/runNeovimTestsCI.ts vs
packages/test-harness/src/scripts/runVscodeTestsCI.ts
- docs\contributing\cursorless-in-neovim.md vs
docs\contributing\CONTRIBUTING.md

---------

Co-authored-by: Cedric Halbronn <[email protected]>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: fidgetingbits <[email protected]>
Co-authored-by: Pokey Rule <[email protected]>
  • Loading branch information
5 people authored Jul 26, 2024
1 parent e81cd54 commit 17bfa0d
Show file tree
Hide file tree
Showing 101 changed files with 5,191 additions and 44 deletions.
11 changes: 8 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
* @pokey @AndreasArvidsson @phillco
* @cursorless-dev/code-owners

*keyboard* @pokey @AndreasArvidsson @phillco @josharian
*Keyboard* @pokey @AndreasArvidsson @phillco @josharian
*keyboard* @cursorless-dev/code-owners @josharian
*Keyboard* @cursorless-dev/code-owners @josharian

*neovim* @cursorless-dev/code-owners @saidelike @fidgetingbits
*Neovim* @cursorless-dev/code-owners @saidelike @fidgetingbits
*nvim* @cursorless-dev/code-owners @saidelike @fidgetingbits
*Nvim* @cursorless-dev/code-owners @saidelike @fidgetingbits
17 changes: 17 additions & 0 deletions .github/actions/test-neovim-lua/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Neovim Lua Tests"
description: "Set up Neovim Lua environment and run Busted tests"
runs:
using: "composite"
steps:
- uses: leafo/gh-actions-lua@v9
with:
luaVersion: "luajit-2.1.0-beta3"
- uses: leafo/gh-actions-luarocks@v4
- shell: bash
run: |
luarocks install busted
luarocks install luafilesystem
- shell: bash
run: |
cd cursorless.nvim
busted --run unit
35 changes: 35 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,41 @@ jobs:
registryUrl: https://marketplace.visualstudio.com
extensionFile: ${{ steps.publishToOpenVSX.outputs.vsixPath }}

publish-neovim-extension:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment: production
env:
CURSORLESS_REPO_ROOT: ${{ github.workspace }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.CURSORLESS_BOT_TOKEN }}
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm --color install
- run: pnpm --color compile
- run: pnpm --color --filter '!cursorless-org' --filter '!cursorless-org-*' build
env:
CURSORLESS_DEPLOY: true
- name: Configure GPG Key
run: |
echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --import
env:
GPG_SIGNING_KEY: ${{ secrets.CURSORLESS_BOT_GPG_SIGNING_KEY }}
- name: git config
run: |
git config user.name cursorless-bot
git config user.email [email protected]
git config user.signingkey A9387720AFC62221
git config commit.gpgsign true
- name: Push compiled files to cursorless.nvim plugin repo
run: bash -x scripts/deploy-cursorless-nvim.sh

push-cursorless-talon:
name: Push cursorless-talon subrepo
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm --color install
- uses: leafo/gh-actions-lua@v9
- uses: leafo/gh-actions-luarocks@v4
- uses: pre-commit/[email protected]
- uses: pre-commit-ci/[email protected]
if: always()
29 changes: 22 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
vscode_version: [stable]
app_version: [stable]
include:
- os: ubuntu-latest
vscode_version: legacy
app_version: legacy
runs-on: ${{ matrix.os }}
env:
VSCODE_VERSION: ${{ matrix.vscode_version }}
APP_VERSION: ${{ matrix.app_version }}
NEOVIM_VERSION: ${{ matrix.app_version == 'stable' && 'stable' || 'v0.10.0' }}
VSCODE_CRASH_DIR: ${{ github.workspace }}/artifacts/dumps
VSCODE_LOGS_DIR: ${{ github.workspace }}/artifacts/logs
CURSORLESS_REPO_ROOT: ${{ github.workspace }}
TEMP_DIR: ${{ github.workspace }}/temp
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm
- run: mkdir -p "${{ env.VSCODE_CRASH_DIR }}" "${{ env.VSCODE_LOGS_DIR }}"
- run: mkdir -p "${{ env.VSCODE_CRASH_DIR }}" "${{ env.VSCODE_LOGS_DIR }}" "${{ env.TEMP_DIR }}"
shell: bash
- run: pnpm --color install
- run: pnpm --color compile
Expand All @@ -43,9 +45,22 @@ jobs:
if: runner.os == 'Linux'
- run: pnpm --color test
if: runner.os != 'Linux'
- run: bash -x scripts/install-neovim-dependencies.sh
- uses: rhysd/action-setup-vim@v1
id: vim
with:
version: ${{ env.NEOVIM_VERSION }}
neovim: true
- name: Run neovim tests
run: xvfb-run -a pnpm -F @cursorless/test-harness test:neovim
if: runner.os == 'Linux'
env:
NEOVIM_PATH: ${{ steps.vim.outputs.executable }}
- uses: ./.github/actions/test-neovim-lua/
if: runner.os == 'Linux' && matrix.app_version == 'stable'
- name: Create vscode dist that can be installed locally
run: pnpm -F @cursorless/cursorless-vscode populate-dist --local-install
if: runner.os == 'Linux' && matrix.vscode_version == 'stable'
if: runner.os == 'Linux' && matrix.app_version == 'stable'
- name: Test create vsix
id: createVsix
uses: HaaLeo/publish-vscode-extension@v1
Expand All @@ -54,10 +69,10 @@ jobs:
packagePath: packages/cursorless-vscode/dist
dryRun: true
- run: mv ${{ steps.createVsix.outputs.vsixPath }} cursorless-development.vsix
if: runner.os == 'Linux' && matrix.vscode_version == 'stable'
if: runner.os == 'Linux' && matrix.app_version == 'stable'
- name: Upload vsix
uses: actions/upload-artifact@v4
if: runner.os == 'Linux' && matrix.vscode_version == 'stable'
if: runner.os == 'Linux' && matrix.app_version == 'stable'
with:
name: vsix
path: cursorless-development.vsix
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
*.vsix
/package-lock.json
*.DS_Store
.luacheckcache

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

Expand Down Expand Up @@ -43,5 +44,9 @@ next-env.d.ts
# test subset config
packages/test-harness/testSubsetGrep.properties

# cursorless-neovim
cursorless.nvim/node/cursorless-neovim
cursorless.nvim/node/test-harness

# nix
.direnv/
8 changes: 8 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
std = luajit
cache = true
codes = true
ignore = { "432" }

globals = {
"vim",
}
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ repos:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/lunarmodules/luacheck
rev: v1.2.0
hooks:
- id: luacheck
exclude: ^data/playground/lua/.*\.lua$
- repo: https://github.com/JohnnyMorganz/StyLua
rev: v0.20.0
hooks:
- id: stylua
exclude: ^data/playground/lua/.*\.lua$
6 changes: 4 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"jrieken.vscode-tree-sitter-query",
"wenkokke.tree-sitter-talon",
"usernamehw.commands"
"wenkokke.talonfmt-vscode",
"usernamehw.commands",
"sumneko.lua",
"JohnnyMorganz.stylua"
]
}
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@
]
},

// Neovim launch configs
{
"name": "Neovim: Run",
"request": "attach",
"continueOnAttach": true,
"skipFiles": ["<node_internals>/**"],
"preLaunchTask": "Neovim: Build extension",
"type": "node"
},
{
"name": "Neovim: Test",
"request": "attach",
"continueOnAttach": true,
"skipFiles": ["<node_internals>/**"],
"preLaunchTask": "Neovim: Build extension and tests",
"type": "node"
},

// Talon launch configs
{
"name": "Talon: Test",
Expand Down
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
"files.eol": "\n",
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.workingDirectories": [{ "pattern": "packages/*/" }]
"eslint.workingDirectories": [{ "pattern": "packages/*/" }],
"Lua.runtime.version": "Lua 5.1",
"Lua.diagnostics.globals": ["vim", "talon", "it", "describe"],
"Lua.diagnostics.ignoredFiles": "Disable",
"Lua.workspace.ignoreDir": ["data/playground/lua/"],
"[lua]": {
"editor.defaultFormatter": "JohnnyMorganz.stylua"
},
"files.associations": {
".busted": "lua"
}
}
146 changes: 146 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,152 @@
"group": "test"
},

// Neovim tasks
{
"label": "Neovim: Build extension",
"dependsOn": [
"Neovim: Launch neovim",
"Neovim: ESBuild",
"Neovim: Populate dist"
],
"group": "build"
},
{
"label": "Neovim: Build extension and tests",
"dependsOn": [
"Neovim: Launch neovim (test)",
"Neovim: ESBuild",
"Neovim: Populate dist",
"TSBuild",
"Build test harness"
],
"group": "build"
},
{
"label": "Neovim: ESBuild",
"type": "npm",
"script": "esbuild",
"path": "packages/cursorless-neovim",
"dependsOn": ["Generate grammar"],
"presentation": {
"reveal": "silent"
},
"group": "build"
},
{
"label": "Neovim: Populate dist",
"type": "npm",
"script": "populate-dist",
"path": "packages/cursorless-neovim",
"presentation": {
"reveal": "silent"
},
"options": {
"env": {
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
}
},
"group": "build"
},
{
"label": "Neovim: Launch neovim",
"type": "process",
"command": "packages/cursorless-neovim/scripts/linux-terminal.sh",
"args": [
"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.sh ${workspaceFolder} development"
],
"osx": {
"command": "osascript",
"args": [
"-e",
"tell app \"Terminal\" to do script \"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.sh ${workspaceFolder} development\" activate"
]
},
"windows": {
"command": "powershell",
"args": [
"(New-Object -ComObject WScript.Shell).Run(\"\"\"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.bat\"\"\", 1, $false)"
]
},
"group": "build",
"presentation": {
"reveal": "silent"
},
"options": {
"env": {
"CURSORLESS_REPO_ROOT": "${workspaceFolder}",
"NVIM_NODE_HOST_DEBUG": "1",
"NVIM_NODE_LOG_FILE": "${workspaceFolder}/packages/cursorless-neovim/out/nvim_node.log",
"NVIM_NODE_LOG_LEVEL": "info",
"CURSORLESS_MODE": "development"
}
}
},
{
"label": "Neovim: Launch neovim (test)",
"type": "process",
"command": "packages/cursorless-neovim/scripts/linux-terminal.sh",
"args": [
"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.sh ${workspaceFolder} test"
],
"osx": {
"command": "osascript",
"args": [
"-e",
"tell app \"Terminal\" to do script \"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.sh ${workspaceFolder} test\" activate"
]
},
"windows": {
"command": "powershell",
"args": [
"(New-Object -ComObject WScript.Shell).Run(\"\"\"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.bat\"\"\", 1, $false)"
]
},
"group": "build",
"presentation": {
"reveal": "silent"
},
"options": {
"env": {
"CURSORLESS_REPO_ROOT": "${workspaceFolder}",
"NVIM_NODE_HOST_DEBUG": "1",
"NVIM_NODE_LOG_FILE": "${workspaceFolder}/packages/cursorless-neovim/out/nvim_node.log",
"NVIM_NODE_LOG_LEVEL": "info",
"CURSORLESS_MODE": "test"
}
}
},
{
"label": "Neovim: Show logs",
"type": "shell",
"command": "packages/cursorless-neovim/scripts/show-logs.sh",
"problemMatcher": [],
"isBackground": true,
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": false,
"clear": true
},
"options": {
"env": {
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
}
}
// NOTE: We don't have a way on Windows atm due to command with argument inside Run() not working
// so we need to show logs outside of vscode (see #2454)
},
{
"label": "Neovim: Launch neovim (lua test)",
"type": "shell",
"command": "busted --run unit",
"options": {
"cwd": "cursorless.nvim"
}
},

// cursorless.org
{
"label": "Serve cursorless.org",
Expand Down
Loading

0 comments on commit 17bfa0d

Please sign in to comment.