Actually, I've already tried the `hare-ls`, but it doesn't work (maybe
too old and not updated). Here the steps I've tried:
1. Git clone the repo, installed `go` and ran `make` to create `hare-ls` binary.
2. Add the following lua code to launch `hare-ls` when opening `hare`
source file (for the `hare.json` just a temporary workaround, first
time to try neovim LSP API):
```lua
--[[
Load Hare LSP manually when opening `.ha` files
--]]
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'hare' },
callback = function()
local capabilities = Reload_package('cmp_nvim_lsp')
.default_capabilities(vim.lsp.protocol.make_client_capabilities())
-- local custom_lsp_attach = funciton()
-- local mapping_options = { noremap=true, silent=true }
-- vim.api.nvim_buf_set_keymap(0, 'n', 'gd', '<cmd>lua
vim.lsp.buf.definition()<CR>', mapping_options)
-- vim.api.nvim_buf_set_keymap(0, 'n', 'gD', '<cmd>lua
vim.lsp.buf.declaration()<CR>', mapping_options)
-- vim.api.nvim_buf_set_keymap(0, 'n', 'gr', '<cmd>lua
vim.lsp.buf.references()<CR>', mapping_options)
-- vim.api.nvim_buf_set_keymap(0, 'n', 'gi', '<cmd>lua
vim.lsp.buf.implementation()<CR>', mapping_options)
-- vim.api.nvim_buf_set_keymap(0, "n", "<leader>ff",
"<cmd>lua vim.lsp.buf.format( {async = true} )<CR>", mapping_options)
-- -- vim.api.nvim_buf_set_keymap(0, "n", "<leader>ff",
"<cmd>lua vim.lsp.buf.formatting({ tabSize = 4, insertSpaces = true
})<CR>", mapping_options)
-- vim.api.nvim_buf_set_keymap(0, 'n', 'K', '<cmd>lua
vim.lsp.buf.hover()<CR>', mapping_options)
-- vim.api.nvim_buf_set_keymap(0, 'n', 'rn', '<cmd>lua
vim.lsp.buf.rename()<CR>', mapping_options)
-- --vim.api.nvim_buf_set_keymap(0, 'n', 'se', '<cmd>lua
vim.diagnostic.setloclist()<CR>', mapping_options)
-- vim.api.nvim_buf_set_keymap(0, 'n', 'se',
'<cmd>Telescope diagnostics<CR>', mapping_options) --
vim.api.nvim_buf_set_keymap(0, 'n', '<c-n>', '<cmd>lua
vim.diagnostic.goto_next({popup_opts = {border = \'rounded\'}})<CR>',
mapping_options)
-- vim.api.nvim_buf_set_keymap(0, 'n', '<c-p>', '<cmd>lua
vim.diagnostic.goto_prev({popup_opts = {border = \'rounded\'}})<CR>',
mapping_options)
-- -- vim.api.nvim_buf_set_keymap(0, 'n', 'qf', '<cmd>lua
vim.lsp.buf.code_action({only = \'quickfix\'})<CR>', mapping_options)
-- vim.api.nvim_buf_set_keymap(0, 'n', 'ca', '<cmd>lua
vim.lsp.buf.code_action()<CR>', mapping_options)
-- end
-- print(">>> Hare LSP, capabilities: "..vim.inspect(capabilities ))
vim.lsp.start({
name = 'Hare LSP',
cmd = {'hare-ls'},
capabilities = capabilities,
-- on_attach = custom_lsp_attach,
root_dir = vim.fs.root(0, {'hare.json'}),
})
print(">>> Loaded Hare LSP")
end,
})
```
3. Then open neovim and open `main.ha`, run `LspInfo` to confirm
`hare-ls` has been loaded and attached:
```bash
Language client log: /home/fion/.local/state/nvim/lsp.log
Detected filetype: hare
1 client(s) attached to this buffer:
Client: Hare LSP (id: 1, bufnr: [1])
filetypes:
autostart: false
root directory: /home/fion/sbzi/hare/temp
cmd: hare-ls
```
4. But `LspLog` shows it crashes, and calls `lua vim.lsp.buf.hover()`
and `lua vim.lsp.buf.definition()` got nothing:)
```bash
[START][2024-07-12 10:28:12] LSP logging initiated
[ERROR][2024-07-12 10:28:12] .../vim/lsp/rpc.lua:770 "rpc" "hare-ls"
"stderr" "panic: runtime error: invalid memory address or nil pointer
dereference\n[signal SIGSEGV: segmentation violation code=0x1 addr=0x0
pc=0x4f3214]\n\ngoroutine 6
[running]:\nmain.(*Handler).Handle(0xc00011e000, {0x553c88, 0x6670e0},
0xc00012a000, 0xc0001003c0)\n\t/home/fion/temp/hare-ls/cmd/hare-ls/main.go:73
+0x694\ngithub.com/sourcegraph/jsonrpc2.(*Conn).readMessages(0xc00012a000,
{0x553c88, 0x6670e0})\n\t/home/fion/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.1.0/jsonrpc2.go:553
+0x2ea\ncreated by github.com/sourcegraph/jsonrpc2.NewConn in
goroutine 1\n\t/home/fion/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.1.0/jsonrpc2.go:334
+0x1e6\n"
```
Best wish
Fion