Skip to content

Commit e12b3fc

Browse files
committed
lsp/ocamllsp.lua: use root_markers instead of root_dir
This drops the dependency on `lspconfig.util`, which appears deprecated. Signed-off-by: Edwin Török <[email protected]>
1 parent b3cce14 commit e12b3fc

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lsp/ocamllsp.lua

Lines changed: 19 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,30 @@ 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

2737
---@type vim.lsp.Config
2838
return {
2939
cmd = { 'ocamllsp' },
3040
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,
41+
root_markers = {
42+
{ 'dune-project', 'dune-workspace' },
43+
{ '*.opam', 'esy.json', 'package.json' },
44+
'.git',
45+
},
3546
get_language_id = get_language_id,
3647
}

0 commit comments

Comments
 (0)