README.md
1# Neovim configuration guide for SPIR-V disassembly files
2
3This directory holds instructions to configure Neovim for SPIR-V assembly files (`.spvasm`)
4
5At the end, Neovim should support:
6* Syntax highlighting
7* Jump to definition
8* Find all references
9* Symbol renaming
10* Operand hover information
11* Formatting
12* Completion suggestions for all Opcodes and Ids
13
14While the instructions here are specifically for Neovim, they should translate easily to vim.
15
16## Dependencies
17
18In order to build and install the Visual Studio Code language server extension, you will need to install and have on your `PATH` the following dependencies:
19* [`golang 1.16+`](https://golang.org/)
20
21## File type detection
22
23Neovim's default config location is typically `~/.config/nvim` so the rest of the instructions assume that but it will need to be changed if your system is different.
24
25Tell neovim that `*.spvasm` files should be treated as `spvasm` filetype
26```bash
27echo "au BufRead,BufNewFile *.spvasm set filetype=spvasm" > ~/.config/nvim/ftdetect/spvasm.vim
28```
29
30## Syntax Highlighting
31
32### Generate the syntax highlighting file
33```bash
34cd <spirv-tools dir>
35mkdir -p build && cd build
36# Any platform is fine, ninja is used an as example
37cmake -G Ninja ..
38ninja spirv-tools-vimsyntax
39```
40
41### Copy the syntax file
42```bash
43cp spvasm.vim ~/.config/nvim/syntax/spvasm.vim
44```
45
46## Language Server
47
48### Building the LSP (masOS / Linux)
49
50Run `build_lsp.sh`
51Copy `spirvls` and `spirv.json` to a location in `$PATH`
52
53```bash
54cd <spirv-tools dir>/utils/vscode
55./build_lsp.sh
56sudo cp spirvls/* /usr/local/bin/
57```
58
59### Building the LSP (Windows)
60
61TODO
62
63### Configuring Neovim
64
65Configuration will depend a lot on your installed plugins but assuming you are using [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) the following should be sufficient.
66
67```lua
68local lspconfig = require 'lspconfig'
69local configs = require 'lspconfig.configs'
70
71if not configs.spvasm then
72 configs.spvasm = {
73 default_config = {
74 cmd = { 'spirvls' },
75 filetypes = { 'spvasm' },
76 root_dir = function(fname)
77 return '.'
78 end,
79 settings = {},
80 },
81 }
82end
83
84lspconfig.spvasm.setup {
85 capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()),
86}
87```
88