01.11.2024
Enable Cypher Language Server for Neovim
This is the second part of my post about Cypher support in Neovim. If you missed the first one that shows the evolution of adding support, you’re welcome to read the first part. In this post I will focus on getting a Neovim environment from 0 to Cypher support (also with a pleasant visual improvement). This guide assumes that you don’t have anything configured right now. If you already have a plugin manager enabled or even language server plugins installed, you can happily skip those sections.
Requirements
There is not much that is needed to get the full Cypher support working. The only thing needed, besides Neovim obviously, is a current npm and nodejs version for the Cypher language server to be installed and run
Setting up the needed infrastructure
First ensure that your Neovim installation is on a version that has Cypher file support (v0.10.0+) by calling nvim -v
.
The output should contain something like
NVIM v0.10.2
Build type: Release
When opening a .cypher file it should look like this:
Because this guide starts with a fresh configuration, we need to add some boilerplate code to get a package manager running in Neovim.
I have chosen to use lazy.nvim and something similar to its default setup.
Which leads to a ~/.config/nvim/init.lua
like this,
require("config.lazy-bootstrap")
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
require("config.lazy")
one file called ~/.config/nvim/config/lazy-bootstrap.lua
for the initial installation of the package manager, if it does not exist,
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
and one called ~/.config/nvim/config/lazy.lua
for the initialization of the plugin manager including all needed plugins.
require("lazy").setup({
spec = {
-- here we will place the plugins
},
install = { colorscheme = { "habamax" } },
checker = { enabled = true },
})
When Neovim gets started now, we should see…nothing. This is due to the fact that there is no plugin defined yet, let’s change this.
Adding the needed plugins
To get the right language server support into Neovim, we need three plugin:
- nvim-lspconfig - required for having built-in LSP support (filetype association, start/stop, etc.)
- mason - handles the installation of LSPs, linters, etc.
- mason-lspconfig - bridges nvim-lspconfig with maven to have auto-installation etc. in place
More details on what those plugins do can be found in my older blog post .
Because the targeted setup is straight forward, those plugins can be added directly to the spec
section in the lazy setup:
require("lazy").setup({
spec = {
"neovim/nvim-lspconfig",
"williamboman/mason-lspconfig.nvim",
"williamboman/mason.nvim"
},
install = { colorscheme = { "habamax" } },
checker = { enabled = true },
})
require("config.lazy-bootstrap")
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
require("config.lazy")
require('lspconfig')['cypher_ls'].setup {}
When opening a .cypher file now, it will not just highlight the syntax but also show information on wrong usage.
Make it even nicer (optional and opinionated)
The current color scheme is using the default shell colors. It depends on the contrast, if the individual parts are recognizable. You know what makes the world a better place and also your Neovim and everything else much more enjoyable? The Catppuccin color palette. Luckily there is already a Neovim plugin that will help with the setup.
First the catpuccin Neovim plugin needs to be added to the list of plugins.
require("lazy").setup({
spec = {
"neovim/nvim-lspconfig",
"williamboman/mason-lspconfig.nvim",
"williamboman/mason.nvim",
{ "catppuccin/nvim", name = "catppuccin", priority = 1000 }
},
install = { colorscheme = { "habamax" } },
checker = { enabled = true },
})
The syntax looks a bit different for this plugin, but this is mostly due to the fact that otherwise it would have the default name nvim
, what’s for sure not the intention.
The priority (default 50) just says that this plugin should be loaded as late as possible on start, because it is not important for other plugins.
Having done this, let’s get back to the init.lua
and define the color scheme.
require("config.lazy-bootstrap")
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
require("config.lazy")
require('lspconfig')['cypher_ls'].setup {}
vim.cmd.colorscheme "catppuccin"
Et voilà, we have a much nicer color scheme. Head over to the color scheme’s documentation to get a taste for all the flavours that are offered ;)
Happy Cypher writing…