-
Notifications
You must be signed in to change notification settings - Fork 375
feat: add docs for neovim setup #3322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,3 +145,85 @@ opam user-setup install | |
| - Type `:MerlinTypeOf` and press <kbd>Enter</kbd>. | ||
| - The type information will be displayed in the command bar. | ||
| Other Merlin commands for Vim are available and you can checkout their usage on the [Merlin official documentation for Vim](https://ocaml.github.io/merlin/editor/vim/). | ||
|
|
||
| ## Neovim | ||
|
|
||
| Neovim comes with an LSP client. | ||
|
|
||
| One note here is that is that `ocaml-lsp-server` is sensitive to versioning, and often does not play well with the sometimes outdated sources in Mason, a popular package manager for language services. We recommend you install the LSP server directly in the switch, and pointing your Neovim config to use that. | ||
|
|
||
| To install the LSP server and the formatter, run the following. | ||
| ```shell | ||
| opam install ocaml-lsp-server ocamlformat | ||
| ``` | ||
|
|
||
| There are two main ways to install and manage LSP servers. | ||
| - A newer, more recommended way is to use the new Neovim LSP API for versions newer than v0.11.0 via `vim.lsp`. | ||
| - A more traditional way is to use `nvim-lspconfig`. For more info, `kickstart.nvim` has a great example setup. | ||
|
|
||
| ### Using vim.lsp: | ||
|
|
||
| Add this to your toplevel `init.lua`. | ||
| ```lua | ||
| vim.lsp.config['ocamllsp'] = { | ||
| cmd = { 'ocamllsp' }, | ||
| filetypes = { 'ocaml', 'ocaml.interface', 'ocaml.menhir', 'reason' }, | ||
| root_markers = { { 'dune-project', 'dune-workspace' }, '.git' }, | ||
| settings = {}, | ||
| } | ||
|
|
||
| vim.lsp.enable 'ocamllsp' | ||
| ``` | ||
|
|
||
| You can also use `vim.lsp` with a modular config. | ||
|
|
||
| Assume that your config has the following structure. The internal structure of `lua` does not matter much. | ||
| ```text | ||
| . | ||
| ├── init.lua | ||
| └── lua | ||
| ├── custom | ||
| │ └── plugins | ||
| │ └── some-plugin.lua | ||
| └── kickstart | ||
| ├── health.lua | ||
| └── plugins | ||
| └── some-plugin.lua | ||
| ``` | ||
|
|
||
| Then run the following at the root of your config. | ||
| ```text | ||
| mkdir lsp | ||
| touch lsp/ocamllsp.lua | ||
| ``` | ||
|
|
||
| We now add our LSP configs to `lsp/ocamllsp.lua`... | ||
| ```lua | ||
| return { | ||
| cmd = { 'ocamllsp' }, | ||
| filetypes = { 'ocaml', 'ocaml.interface', 'ocaml.menhir', 'reason' }, | ||
|
||
| root_markers = { { 'dune-project', 'dune-workspace' }, '.git' }, | ||
| settings = {}, | ||
| } | ||
| ``` | ||
|
|
||
| ...and import them in the toplevel `init.lua`. | ||
|
||
| ```lua | ||
| vim.lsp.enable 'ocamllsp' | ||
| ``` | ||
|
|
||
| ### Using nvim-lspconfig | ||
|
|
||
| Add this to your `nvim-lspconfig` setup. | ||
| ```lua | ||
| { | ||
| 'neovim/nvim-lspconfig', | ||
| config = function() | ||
| -- rest of config... | ||
|
|
||
| -- add this line specifically for OCaml | ||
| require('lspconfig').ocamllsp.setup {} | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
| end, | ||
| }, | ||
| ``` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ocamllsp.luafromnvim-lspconfigalso addsocaml.ocamllex, andduneto this list, but it does it in an awkward way, the filetype is actually calledocamlinterfaceand it gets mapped toocaml.interfaceusingget_language_id.