From cc48a46524c7f80b5e203c1aab58826cdb4e5df1 Mon Sep 17 00:00:00 2001 From: Török Edwin Date: Tue, 3 May 2022 00:41:12 +0100 Subject: ocamllsp: add support for the dune filetype (#1884) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ocamllsp: add dune as supported language ocaml-lsp-server-1.11.3 enables 'dune' rpc integration (you need a running `dune build --watch` command which provides the RPC server). This allows to reformat `dune` files, and to see `dune` and other build errors as soon as you change a file (e.g. quite useful on newly created files which would otherwise show an LSP error until first build). Signed-off-by: Edwin Török * ocamllsp: dune-project and dune-workspace also mark roots Although most dune projects will also have a *.opam file, this file might be generated by the build system. Newer versions of dune have a dune-project file to mark the root though, and users can create a dune-workspace file as well. Note that `dune` files themselves do NOT mark the root: they can be present in subdirs too. The rules on how `dune` itself finds the root are documented here: https://dune.readthedocs.io/en/stable/usage.html#finding-the-root "The root of the current workspace is determined by looking up a dune-workspace or dune-project file in the current directory and its parent directories. Dune requires at least one of these two files to operate." Signed-off-by: Edwin Török --- lua/lspconfig/server_configurations/ocamllsp.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/server_configurations/ocamllsp.lua b/lua/lspconfig/server_configurations/ocamllsp.lua index 15284716..6cff66b6 100644 --- a/lua/lspconfig/server_configurations/ocamllsp.lua +++ b/lua/lspconfig/server_configurations/ocamllsp.lua @@ -6,6 +6,7 @@ local language_id_of = { ocamlinterface = 'ocaml.interface', ocamllex = 'ocaml.ocamllex', reason = 'reason', + dune = 'dune' } local get_language_id = function(_, ftype) @@ -15,8 +16,8 @@ end return { default_config = { cmd = { 'ocamllsp' }, - filetypes = { 'ocaml', 'ocaml.menhir', 'ocaml.interface', 'ocaml.ocamllex', 'reason' }, - root_dir = util.root_pattern('*.opam', 'esy.json', 'package.json', '.git'), + filetypes = { 'ocaml', 'ocaml.menhir', 'ocaml.interface', 'ocaml.ocamllex', 'reason', 'dune' }, + root_dir = util.root_pattern('*.opam', 'esy.json', 'package.json', '.git', 'dune-project', 'dune-workspace'), get_language_id = get_language_id, }, docs = { @@ -32,7 +33,7 @@ opam install ocaml-lsp-server ``` ]], default_config = { - root_dir = [[root_pattern("*.opam", "esy.json", "package.json", ".git")]], + root_dir = [[root_pattern("*.opam", "esy.json", "package.json", ".git", "dune-project", "dune-workspace")]], }, }, } -- cgit v1.2.3-70-g09d2