Skip to content

Commit 9af1d61

Browse files
authored
feat(lsp/ocamllsp.lua): use root_markers instead of root_dir #4098
This drops the dependency on the deprecated `lspconfig.util`. Signed-off-by: Edwin Török <[email protected]>
1 parent 2c1ebfe commit 9af1d61

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

lsp/ocamllsp.lua

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
--- opam install ocaml-lsp-server
1010
--- ```
1111

12-
local util = require 'lspconfig.util'
13-
1412
local language_id_of = {
1513
menhir = 'ocaml.menhir',
1614
ocaml = 'ocaml',
@@ -20,17 +18,31 @@ local language_id_of = {
2018
dune = 'dune',
2119
}
2220

23-
local get_language_id = function(_, ftype)
24-
return language_id_of[ftype]
21+
local language_id_of_ext = {
22+
mll = language_id_of.ocamllex,
23+
mly = language_id_of.menhir,
24+
mli = language_id_of.ocamlinterface,
25+
}
26+
27+
local get_language_id = function(bufnr, ftype)
28+
if ftype == 'ocaml' then
29+
local path = vim.api.nvim_buf_get_name(bufnr)
30+
local ext = vim.fn.fnamemodify(path, ':e')
31+
return language_id_of_ext[ext] or language_id_of.ocaml
32+
else
33+
return language_id_of[ftype]
34+
end
2535
end
2636

37+
local root_markers1 = { 'dune-project', 'dune-workspace' }
38+
local root_markers2 = { '*.opam', 'opam', 'esy.json', 'package.json' }
39+
local root_markers3 = { '.git' }
40+
2741
---@type vim.lsp.Config
2842
return {
2943
cmd = { 'ocamllsp' },
3044
filetypes = { 'ocaml', 'menhir', 'ocamlinterface', 'ocamllex', 'reason', 'dune' },
31-
root_dir = function(bufnr, on_dir)
32-
local fname = vim.api.nvim_buf_get_name(bufnr)
33-
on_dir(util.root_pattern('*.opam', 'esy.json', 'package.json', '.git', 'dune-project', 'dune-workspace')(fname))
34-
end,
45+
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers1, root_markers2, root_markers3 }
46+
or vim.list_extend(vim.list_extend(root_markers1, root_markers2), root_markers3),
3547
get_language_id = get_language_id,
3648
}

0 commit comments

Comments
 (0)