Skip to content

Commit 5f42ca1

Browse files
committed
add: some instructions for neovim testing
1 parent 0652a44 commit 5f42ca1

File tree

1 file changed

+96
-1
lines changed

1 file changed

+96
-1
lines changed

README.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,102 @@ Currently, it implements:
1111
* Document Symbols
1212
* Signature Help
1313

14-
## Setup
14+
## Setup - Neovim
15+
16+
1. Install the language server
17+
```
18+
python -m pip install nwscript-language-server
19+
```
20+
21+
1. Make sure ``nwscript-language-server`` is on your PATH!
22+
23+
1. Setup neovim config - Obviously people's tastes will differ here and not all of it is fully implemented.
24+
```lua
25+
require("config.lazy")
26+
27+
vim.api.nvim_exec(
28+
[[
29+
autocmd FileType nwscript setlocal lsp
30+
]],
31+
false
32+
)
33+
34+
local lspconfig = require("lspconfig")
35+
local configs = require("lspconfig.configs")
36+
37+
if not configs.nwscript_language_server then
38+
configs.nwscript_language_server = {
39+
default_config = {
40+
cmd = { "nwscript-language-server" },
41+
filetypes = { "nwscript" },
42+
root_dir = lspconfig.util.root_pattern(".git", "nasher.cfg"),
43+
},
44+
}
45+
end
46+
47+
lspconfig.nwscript_language_server.setup({
48+
on_attach = function(client, bufnr)
49+
-- Custom on_attach function (optional)
50+
print("nwscript language server attached!")
51+
52+
require("lsp_signature").on_attach({
53+
bind = true, -- This is mandatory, otherwise border config won't get registered.
54+
handler_opts = {
55+
border = "rounded",
56+
},
57+
}, bufnr)
58+
59+
-- Enable snippet support (if your completion plugin supports snippets)
60+
vim.bo[bufnr].expandtab = false
61+
vim.bo[bufnr].shiftwidth = 4
62+
end,
63+
settings = {
64+
["nwscript-language-server"] = {
65+
disableSnippets = "on",
66+
},
67+
},
68+
})
69+
70+
-- Global mappings.
71+
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
72+
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float)
73+
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
74+
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
75+
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist)
76+
77+
-- Use LspAttach autocommand to only map the following keys
78+
-- after the language server attaches to the current buffer
79+
vim.api.nvim_create_autocmd("LspAttach", {
80+
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
81+
callback = function(ev)
82+
-- Enable completion triggered by <c-x><c-o>
83+
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
84+
85+
-- Buffer local mappings.
86+
-- See `:help vim.lsp.*` for documentation on any of the below functions
87+
local opts = { buffer = ev.buf }
88+
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
89+
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
90+
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
91+
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
92+
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
93+
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
94+
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
95+
vim.keymap.set("n", "<space>wl", function()
96+
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
97+
end, opts)
98+
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
99+
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
100+
vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts)
101+
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
102+
vim.keymap.set("n", "<space>f", function()
103+
vim.lsp.buf.format({ async = true })
104+
end, opts)
105+
end,
106+
})
107+
```
108+
109+
## Setup - VS Code Extension debug mode
15110

16111
### Install Server Dependencies
17112

0 commit comments

Comments
 (0)