Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add tasks for debugging neovim on linux #8

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@
"tell app \"Terminal\" to do script \"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.sh ${workspaceFolder} development\" activate"
]
},
// TODO: Add linux
"linux": {
"command": "packages/cursorless-neovim/scripts/linux-terminal.sh",
"args": [
"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.sh ${workspaceFolder} development"
]
},
"group": "build",
"options": {
"env": {
Expand Down Expand Up @@ -233,7 +238,12 @@
"tell app \"Terminal\" to do script \"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.sh ${workspaceFolder} test\" activate"
]
},
// TODO: Add linux
"linux": {
"command": "packages/cursorless-neovim/scripts/linux-terminal.sh",
"args": [
"${workspaceFolder}/packages/cursorless-neovim/scripts/debug-neovim.sh ${workspaceFolder} test"
]
},
"group": "build",
"options": {
"env": {
Expand Down
3 changes: 2 additions & 1 deletion docs/contributing/cursorless-in-neovim.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Note that the `C:\path\to\cursorless` path above should match your cloned cursor

## Running / testing extension locally

In order to test out your local version of the extension or to run unit tests locally, you need to run the extension in debug mode. To do so you need to run the `workbench.action.debug.selectandstart` command in VSCode and then select either "Run neovim extension" or "Run neovim extension tests".
In order to test out your local version of the extension or to run unit tests locally, you need to run the extension in
debug mode. To do so you need to run the `workbench.action.debug.selectandstart` (aka `Debug: Select and Start Debugging`) command in VSCode and then select either "Neovim: Run" or "Neovim: Test".

The debug logs are written in `C:\path\to\cursorless\packages\cursorless-neovim\out\nvim_node.log`.

Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 43 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
description = "A Nix-flake-based development environment for Cursorless";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};

outputs =
{ self, nixpkgs }:
Expand All @@ -13,7 +15,43 @@
"aarch64-darwin"
];
forEachSupportedSystem =
f: nixpkgs.lib.genAttrs supportedSystems (system: f { pkgs = import nixpkgs { inherit system; }; });
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
f {
pkgs = import nixpkgs {
inherit system;
overlays = [
# https://github.com/NixOS/nixpkgs/pull/317333
(final: prev: {
nodePackages = prev.nodePackages // {
neovim = prev.buildNpmPackage rec {
pname = "neovim-node-client";
version = "5.1.1-dev.0";
src = prev.fetchFromGitHub {
owner = "neovim";
repo = "node-client";
rev = "d99ececf115ddc8ade98467417c1bf0120b676b5";
hash = "sha256-eiKyhJNz7kH2iX55lkn7NZYTj6yaSZLMZxqiqPxDIPs=";
};
npmDeps = prev.fetchNpmDeps {
inherit src;
hash = "sha256-UoMq+7evskxtZygycxLBgeUtwrET8jYKeZwMiXdBMAw=";
};
postInstall = ''
mkdir -p $out/bin
ln -s $out/lib/node_modules/neovim/node_modules/.bin/neovim-node-host $out/bin
'';
};
};
neovim = prev.neovim.override { withNodeJs = true; };

})

];
};
}
);
pythonVersion = builtins.replaceStrings [ "py" ] [
"python"
] (nixpkgs.lib.importTOML ./pyproject.toml).tool.ruff.target-version;
Expand All @@ -37,17 +75,18 @@
--set PYTHONPATH $PYTHONPATH
'';
}))

python
pkgs.neovim
];
# To prevent weird broken non-interactive bash terminal
buildInputs = [ pkgs.bashInteractive ];
shellHook = ''
if [ ! -f .git/hooks/pre-commit ]; then
echo "You can run 'pre-commit install' to install git commit hooks if you want them."
fi

pnpm install

PATH=${pkgs.lib.getBin pkgs.neovim}/bin:$PATH}
'';
};
}
Expand Down
3 changes: 3 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ require("lazy").setup({
})

local repo_root = os.getenv("CURSORLESS_REPO_ROOT")
if not repo_root then
error("CURSORLESS_REPO_ROOT is not set. Run via debug-neovim.sh script.")
end
vim.opt.runtimepath:append(repo_root .. "/cursorless.nvim")

require("talon").setup()
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-neovim/scripts/debug-neovim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export NVIM_NODE_LOG_FILE="${workspaceFolder}/packages/cursorless-neovim/out/nvi
export NVIM_NODE_LOG_LEVEL="info"
export CURSORLESS_MODE="${cursorless_mode}"

nvim -u "${workspaceFolder}/init.lua"
command nvim -u "${workspaceFolder}/init.lua"
saidelike marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions packages/cursorless-neovim/scripts/linux-terminal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# shellcheck disable=SC2068
set -euo pipefail

if command -v gnome-terminal &>/dev/null; then
# FIXME: Possibly have to use ;exec bash to not auto-close the terminal
gnome-terminal -- $@
elif command -v gnome-console &>/dev/null; then
gnome-console -- $@
elif command -v konsole &>/dev/null; then
konsole --hold -e $@
elif command -v xfce4-terminal &>/dev/null; then
xfce4-terminal --hold -e $@
elif command -v kitty &>/dev/null; then
kitty -1 --hold $@
elif command -v alacritty &>/dev/null; then
alacritty --hold -e $@
elif command -v wezterm &>/dev/null; then
wezterm --config "exit_behavior='Hold'" start --always-new-process $@
else
echo "No supported terminal emulator found. File an issue to get it added."
exit 1
fi
3 changes: 3 additions & 0 deletions packages/cursorless-neovim/scripts/populate-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
set -euo pipefail

echo "Populating dist directory..."
if [ ! -e "${CURSORLESS_REPO_ROOT-nonexistent}" ]; then
saidelike marked this conversation as resolved.
Show resolved Hide resolved
CURSORLESS_REPO_ROOT=$(git rev-parse --show-toplevel)
fi
echo "CURSORLESS_REPO_ROOT: $CURSORLESS_REPO_ROOT"
cursorless_nvim_dir="$CURSORLESS_REPO_ROOT/cursorless.nvim"
cursorless_neovim_node_in_dir="$CURSORLESS_REPO_ROOT/packages/cursorless-neovim"
Expand Down
Loading