Files
nicole mazzucaandChandler Carruth a898454807 Fix the nvim-carbon integration (#7822)
As I was starting to try to play around with carbon, I wanted nvim
integration. Unfortunately, a lot of the code in the integration had
bitrotted, but not unbearably so, so I updated it 😄

It works now! Syntax highlighting and the LSP work out of the box with
nvim 0.12 (and should also work on nvim 0.11)

Hopefully all good that I did All The Commits, I come from the school of
"every commit should do one thing"

Closes #7821

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2026-09-28 20:20:13 +00:00

36 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set -euo pipefail
if ! command -v tree-sitter >/dev/null 2>&1; then
echo "tree-sitter command not found" >&2
echo "please run npm install -g tree-sitter-cli" >&2
exit 1
fi
DIR="$(dirname -- "$(readlink -f -- "$0")")"
ROOT="$(git -C "$DIR" rev-parse --show-toplevel)"
mkdir -p ~/.config/nvim/{lua,parser,queries}
echo "Linking carbon queries and carbon.lua to neovim's configuration..." >&2
[ -e ~/.config/nvim/queries/carbon ] && unlink ~/.config/nvim/queries/carbon
ln -sf "$ROOT/utils/tree_sitter/queries" ~/.config/nvim/queries/carbon
[ -e ~/.config/nvim/lua/carbon.lua ] && unlink ~/.config/nvim/lua/carbon.lua
ln -sf "$ROOT/utils/nvim/carbon.lua" ~/.config/nvim/lua/carbon.lua
# load carbon.lua on startup
echo "Adding \`require \"carbon\"\` to init.lua..." >&2
grep 'require "carbon"' ~/.config/nvim/init.lua >/dev/null || echo 'require "carbon"' >> ~/.config/nvim/init.lua
# build tree_sitter
echo "Building and copying in tree-sitter binary..." >&2
(cd "$ROOT" && bazel build //utils/tree_sitter:parser_shared -c opt --action_env=PATH)
cp "$ROOT/bazel-bin/utils/tree_sitter/carbon.so" ~/.config/nvim/parser/carbon.so
# bazel builds read-only binaries
chmod +w ~/.config/nvim/parser/carbon.so