From 9af1d6146f8614157b25d96fc2f548cf7a6d8a38 Mon Sep 17 00:00:00 2001 From: Török Edwin Date: Thu, 25 Sep 2025 00:29:46 +0100 Subject: feat(lsp/ocamllsp.lua): use root_markers instead of root_dir #4098 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This drops the dependency on the deprecated `lspconfig.util`. Signed-off-by: Edwin Török --- lsp/ocamllsp.lua | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'lsp') 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, } -- cgit v1.2.3-70-g09d2