aboutsummaryrefslogtreecommitdiffstats
path: root/lsp
diff options
context:
space:
mode:
authorTörök Edwin <edwintorok@users.noreply.github.com>2025-09-25 00:29:46 +0100
committerGitHub <noreply@github.com>2025-09-24 16:29:46 -0700
commit9af1d6146f8614157b25d96fc2f548cf7a6d8a38 (patch)
tree0fa0a4e1e2404a6815ec2aa785703dc10c90036e /lsp
parentci: bump leafo/gh-actions-luarocks from 5 to 6 (#4096) (diff)
downloadnvim-lspconfig-9af1d6146f8614157b25d96fc2f548cf7a6d8a38.tar
nvim-lspconfig-9af1d6146f8614157b25d96fc2f548cf7a6d8a38.tar.gz
nvim-lspconfig-9af1d6146f8614157b25d96fc2f548cf7a6d8a38.tar.bz2
nvim-lspconfig-9af1d6146f8614157b25d96fc2f548cf7a6d8a38.tar.lz
nvim-lspconfig-9af1d6146f8614157b25d96fc2f548cf7a6d8a38.tar.xz
nvim-lspconfig-9af1d6146f8614157b25d96fc2f548cf7a6d8a38.tar.zst
nvim-lspconfig-9af1d6146f8614157b25d96fc2f548cf7a6d8a38.zip
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 <edwin@etorok.net>
Diffstat (limited to 'lsp')
-rw-r--r--lsp/ocamllsp.lua28
1 files changed, 20 insertions, 8 deletions
diff --git a/lsp/ocamllsp.lua b/lsp/ocamllsp.lua
index 505e982d..f6f793ae 100644
--- a/lsp/ocamllsp.lua
+++ b/lsp/ocamllsp.lua
@@ -9,8 +9,6 @@
--- opam install ocaml-lsp-server
--- ```
-local util = require 'lspconfig.util'
-
local language_id_of = {
menhir = 'ocaml.menhir',
ocaml = 'ocaml',
@@ -20,17 +18,31 @@ local language_id_of = {
dune = 'dune',
}
-local get_language_id = function(_, ftype)
- return language_id_of[ftype]
+local language_id_of_ext = {
+ mll = language_id_of.ocamllex,
+ mly = language_id_of.menhir,
+ mli = language_id_of.ocamlinterface,
+}
+
+local get_language_id = function(bufnr, ftype)
+ if ftype == 'ocaml' then
+ local path = vim.api.nvim_buf_get_name(bufnr)
+ local ext = vim.fn.fnamemodify(path, ':e')
+ return language_id_of_ext[ext] or language_id_of.ocaml
+ else
+ return language_id_of[ftype]
+ end
end
+local root_markers1 = { 'dune-project', 'dune-workspace' }
+local root_markers2 = { '*.opam', 'opam', 'esy.json', 'package.json' }
+local root_markers3 = { '.git' }
+
---@type vim.lsp.Config
return {
cmd = { 'ocamllsp' },
filetypes = { 'ocaml', 'menhir', 'ocamlinterface', 'ocamllex', 'reason', 'dune' },
- root_dir = function(bufnr, on_dir)
- local fname = vim.api.nvim_buf_get_name(bufnr)
- on_dir(util.root_pattern('*.opam', 'esy.json', 'package.json', '.git', 'dune-project', 'dune-workspace')(fname))
- end,
+ root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers1, root_markers2, root_markers3 }
+ or vim.list_extend(vim.list_extend(root_markers1, root_markers2), root_markers3),
get_language_id = get_language_id,
}