📝

mason.nvim でインストールした実行ファイルのパス

に公開

Neovim 0.11 が出たので lsp 周りの設定を見直しておったのですが、mason から cmd を取り出したくなった。

従来は以下のようにできたらしい。

local mason_registry = require("mason-registry")
local pkg = mason_registry.get_package("lua-language-server")
local path = pkg:get_install_path()

mason-2.0 (2025/05/06) で breaking change が来ていた

以下のようにすることで得ることができた。

local path = vim.fn.exepath "lua-language-server"

  vim.lsp.config["luals"] = {
    cmd = { vim.fn.exepath "lua-language-server" }, -- 👈
    filetypes = { "lua" },
    root_markers = { ".luarc.json", ".luarc.jsonc", ".git" },
    settings = {
      -- https://zenn.dev/uga_rosa/articles/afe384341fc2e1
      Lua = {
        runtime = {
          version = "LuaJIT",
          pathStrict = true,
          path = { "?.lua", "?/init.lua" },
        },
        workspace = {
          library = vim.list_extend(vim.api.nvim_get_runtime_file("lua", true), {
            "${3rd}/luv/library",
            "${3rd}/busted/library",
            "${3rd}/luassert/library",
          }),
          checkThirdParty = "Disable",
        },
      },
    },
  }

  -- 有効にする(中で nvim_create_autocmd('FileType') するぽい)
  vim.lsp.enable "luals"

masonvim.fn.exepath を拡張しているようで、簡単に書けるようになっている。

Discussion