- add the following to neovim's config
use("https://github.com/anthdono/tree-sitter-mercury")
- run
:PackerSync
in neovimon unix systems this should clone the repository to: ~/.local/share/nvim/site/pack/packer/start/tree-sitter-mercury
- as of writing, upstream vim does not recognise the mercury language and it's filetype. the default behaviour when opening a file with a .m extension is to set the filetype to matlab. this can be overcome by adding the following snippet to your neovim config:
-- introduce the mercury language and it's filetype to vim
vim.filetype.add({
extension = {
m = "mercury",
},
filename = {
[".m"] = "mercury",
},
pattern = {
["\\.m$"] = "mercury",
},
})
- similarly to vim, treesitter is unfamiliar with the mercury language and it's filetype. to overcome this the following snippet should be added to your neovim config:
-- register the mercury langauge and it's filetype with treesitter
vim.treesitter.language.register("mercury", "m")
- to add the mercury parser to treesitter, the following snippet should be added to neovim's config
require("nvim-treesitter.parsers").get_parser_configs().mercury = {
install_info = {
-- replace the following string with the local repository's path
url = "/Users/<username>/.local/share/nvim/site/pack/packer/start/tree-sitter-mercury",
files = { "src/parser.c" },
generate_requires_npm = false,
requires_generate_from_grammar = false,
},
filetype = "m",
}
- the parser is now installed, however nvim-treesitter lacks the neccesary highlight queries required to utilise the mercury treesitter parser for syntax highlighting. the tree-sitter-mercury repository contains custom nvim-treesitter highlight queries, which is best installed via symlinking. this can be done with the following bash command:
# locate the nvim-treesitter package, if installed with packer, it should be at:
# ~/.local/share/nvim/site/pack/packer/start/nvim-treesitter
# navigate to the directory where nvim-treesitter contains it's queries
cd ~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries
# create a symlink here that points to tree-sitter-mercury/queries/mercury
ln -s ~/.local/share/nvim/site/pack/packer/start/tree-sitter-mercury/queries/mercury
- run
:TSInstall mercury
within neovim.
:TSInstall mercury
will likely need to be rerun everytime tree-sitter-mercury is updated via:PackerSync
or equivalent