aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2025-05-19 07:56:31 +0200
committerGitHub <noreply@github.com>2025-05-19 07:56:31 +0200
commit1d6730459c42f591602500da994f01ae43a97dbc (patch)
treec78417dd383456d2ef8a00600375534d17a9cd45
parentchore: fix references to williamboman/mason.nvim (#542) (diff)
downloadmason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.gz
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.bz2
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.lz
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.xz
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.zst
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.zip
perf: host pre-compiled filetype mappings (#555)
Generating the filetype mappings by accessing `vim.lsp.config` turns out to be a bad idea because: 1) performance 2) some `lsp/` configurations in nvim-lspconfig execute code immediately (see angularls) 3) accessing `vim.lsp.config[server_name]` seems to populate `:checkhealth vim.lsp`
-rw-r--r--.github/workflows/autogenerate.yml42
-rw-r--r--.github/workflows/selene.yml2
-rw-r--r--lua/mason-lspconfig/filetype_mappings.lua249
-rw-r--r--lua/mason-lspconfig/mappings.lua17
-rw-r--r--scripts/lua/mason-scripts/mason-lspconfig/generate.lua42
-rw-r--r--scripts/lua/mason-scripts/utils.lua40
-rwxr-xr-xscripts/nvim.sh14
-rw-r--r--tests/mason-lspconfig/api/api_spec.lua15
-rw-r--r--tests/mason-lspconfig/api/command_spec.lua4
9 files changed, 403 insertions, 22 deletions
diff --git a/.github/workflows/autogenerate.yml b/.github/workflows/autogenerate.yml
new file mode 100644
index 0000000..a6167ab
--- /dev/null
+++ b/.github/workflows/autogenerate.yml
@@ -0,0 +1,42 @@
+name: Autogenerate code
+
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: "0 10 * * *"
+
+jobs:
+ autogenerate:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: rhysd/action-setup-vim@v1
+ with:
+ neovim: true
+ version: v0.11.0
+
+ - name: make generate
+ run: make generate
+
+ - name: Create Pull Request
+ id: cpr
+ uses: peter-evans/create-pull-request@v4
+ with:
+ token: ${{ secrets.PAT }}
+ author: "William Botman <william+bot@redwill.se>"
+ committer: "William Botman <william+bot@redwill.se>"
+ add-paths: lua/mason-lspconfig
+ commit-message: "chore: update generated code"
+ branch: chore/generate
+ branch-suffix: short-commit-hash
+ delete-branch: true
+ labels: automerge
+ title: "chore: update generated code"
+
+ - name: Enable Pull Request Automerge
+ if: steps.cpr.outputs.pull-request-operation == 'created'
+ uses: peter-evans/enable-pull-request-automerge@v2
+ with:
+ token: ${{ secrets.PAT }}
+ pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
+ merge-method: squash
diff --git a/.github/workflows/selene.yml b/.github/workflows/selene.yml
index fb87d50..1486c9c 100644
--- a/.github/workflows/selene.yml
+++ b/.github/workflows/selene.yml
@@ -16,5 +16,5 @@ jobs:
with:
# token is needed because the action allegedly downloads binary from github releases
token: ${{ secrets.GITHUB_TOKEN }}
- args: lua/ tests/
+ args: lua/ tests/ scripts/
version: 0.25.0
diff --git a/lua/mason-lspconfig/filetype_mappings.lua b/lua/mason-lspconfig/filetype_mappings.lua
new file mode 100644
index 0000000..1db0de6
--- /dev/null
+++ b/lua/mason-lspconfig/filetype_mappings.lua
@@ -0,0 +1,249 @@
+-- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.
+-- stylua: ignore start
+return {
+ ["BUILD.bazel"] = { "starlark_rust" },
+ OpenFOAM = { "foam_ls" },
+ PKGBUILD = { "pkgbuild_language_server" },
+ antlers = { "antlersls" },
+ arduino = { "arduino_language_server" },
+ asm = { "asm_lsp" },
+ aspnetcorerazor = { "tailwindcss", "htmx" },
+ astro = { "astro", "stylelint_lsp", "tailwindcss", "unocss", "biome", "emmet_ls", "eslint", "htmx" },
+ ["astro-markdown"] = { "tailwindcss", "htmx" },
+ automake = { "autotools_ls" },
+ awk = { "awk_ls" },
+ bash = { "bashls" },
+ bazelrc = { "bazelrc_lsp" },
+ bean = { "beancount" },
+ beancount = { "beancount" },
+ bib = { "ltex_plus", "ltex", "texlab" },
+ bicep = { "bicep" },
+ blade = { "stimulus_ls", "tailwindcss", "htmx" },
+ brs = { "bright_script" },
+ bsl = { "bsl_ls" },
+ bzl = { "bzl", "starlark_rust", "starpls" },
+ c = { "ast_grep", "clangd", "harper_ls" },
+ cairo = { "cairo_ls" },
+ clar = { "clarity_lsp" },
+ clarity = { "clarity_lsp" },
+ clojure = { "tailwindcss", "clojure_lsp", "htmx" },
+ cmake = { "cmake", "neocmake", "harper_ls" },
+ cobol = { "cobol_ls" },
+ comp = { "glsl_analyzer", "glslls" },
+ config = { "autotools_ls" },
+ context = { "ltex_plus", "ltex" },
+ coq = { "coq_lsp" },
+ cpp = { "ast_grep", "clangd", "harper_ls" },
+ crystal = { "crystalline" },
+ cs = { "harper_ls", "csharp_ls", "omnisharp_mono", "omnisharp" },
+ css = { "ast_grep", "stylelint_lsp", "tailwindcss", "unocss", "biome", "emmet_language_server", "emmet_ls", "cssls", "css_variables" },
+ cucumber = { "cucumber_language_server" },
+ cuda = { "clangd" },
+ cue = { "dagger" },
+ cypher = { "cypher_ls" },
+ d = { "serve_d" },
+ dart = { "ast_grep", "harper_ls" },
+ dhall = { "dhall_lsp_server" },
+ ["django-html"] = { "tailwindcss", "htmx" },
+ dockerfile = { "dockerls" },
+ dot = { "dotls" },
+ dts = { "ginko_ls" },
+ dune = { "ocamllsp" },
+ earthfile = { "earthlyls" },
+ edge = { "tailwindcss", "htmx" },
+ edn = { "clojure_lsp" },
+ eelixir = { "tailwindcss", "elixirls", "nextls", "lexical", "htmx" },
+ ejs = { "tailwindcss", "unocss", "htmx" },
+ elixir = { "tailwindcss", "elixirls", "nextls", "lexical", "htmx" },
+ elm = { "elmls" },
+ erb = { "tailwindcss", "unocss", "htmx" },
+ erg = { "erg_language_server" },
+ erlang = { "elp", "erlangls" },
+ eruby = { "stimulus_ls", "tailwindcss", "emmet_language_server", "emmet_ls", "ruby_lsp", "steep", "htmx" },
+ fennel = { "fennel_language_server", "fennel_ls" },
+ flux = { "flux_lsp" },
+ foam = { "foam_ls" },
+ fortran = { "fortls" },
+ frag = { "glsl_analyzer", "glslls" },
+ fsd = { "facility_language_server" },
+ fsharp = { "fsautocomplete" },
+ genie = { "vala_ls" },
+ geom = { "glsl_analyzer", "glslls" },
+ gitcommit = { "ltex_plus", "ltex", "harper_ls" },
+ glsl = { "glsl_analyzer", "glslls" },
+ go = { "ast_grep", "snyk_ls", "harper_ls", "gopls", "golangci_lint_ls" },
+ gohtml = { "tailwindcss", "htmx" },
+ gohtmltmpl = { "tailwindcss", "htmx" },
+ gomod = { "snyk_ls", "gopls", "golangci_lint_ls" },
+ gotmpl = { "gopls" },
+ gowork = { "gopls" },
+ graphql = { "biome", "dprint", "graphql" },
+ groovy = { "groovyls", "gradle_ls" },
+ haml = { "tailwindcss", "unocss", "htmx" },
+ handlebars = { "tailwindcss", "ember", "htmx" },
+ haskell = { "harper_ls", "hls" },
+ hbs = { "tailwindcss", "unocss", "htmx" },
+ heex = { "tailwindcss", "elixirls", "nextls", "lexical", "htmx" },
+ helm = { "snyk_ls", "helm_ls" },
+ hlsl = { "slangd" },
+ hoon = { "hoon_ls" },
+ html = { "ast_grep", "stimulus_ls", "stylelint_lsp", "tailwindcss", "unocss", "emmet_language_server", "emmet_ls", "ltex_plus", "ltex", "lwc_ls", "html", "harper_ls", "angularls", "antlersls", "superhtml", "htmx" },
+ ["html-eex"] = { "tailwindcss", "htmx" },
+ htmlangular = { "tailwindcss", "emmet_language_server", "emmet_ls", "angularls", "htmx" },
+ htmldjango = { "tailwindcss", "emmet_language_server", "emmet_ls", "htmx" },
+ hyprlang = { "hyprls" },
+ jade = { "tailwindcss", "htmx" },
+ java = { "java_language_server", "ast_grep", "jdtls", "harper_ls" },
+ javascript = { "oxlint", "ast_grep", "vtsls", "denols", "tailwindcss", "ts_ls", "unocss", "quick_lint_js", "biome", "ember", "rome", "snyk_ls", "lwc_ls", "harper_ls", "eslint", "dprint", "cssmodules_ls", "htmx" },
+ ["javascript.glimmer"] = { "ember" },
+ ["javascript.jsx"] = { "oxlint", "ast_grep", "vtsls", "denols", "ts_ls", "eslint" },
+ javascriptreact = { "oxlint", "ast_grep", "vtsls", "denols", "tailwindcss", "ts_ls", "unocss", "biome", "emmet_language_server", "emmet_ls", "rome", "eslint", "dprint", "cssmodules_ls", "graphql", "htmx" },
+ jinja = { "jinja_lsp" },
+ jq = { "jqls" },
+ json = { "biome", "rome", "snyk_ls", "jsonls", "spectral", "dprint" },
+ ["json.openapi"] = { "vacuum" },
+ jsonc = { "biome", "jsonls", "dprint" },
+ julia = { "julials" },
+ just = { "just" },
+ kcl = { "kcl" },
+ kotlin = { "ast_grep", "kotlin_language_server" },
+ leaf = { "tailwindcss", "htmx" },
+ less = { "stylelint_lsp", "tailwindcss", "unocss", "emmet_language_server", "emmet_ls", "cssls", "css_variables" },
+ lhaskell = { "hls" },
+ liquid = { "tailwindcss", "shopify_theme_ls", "theme_check", "htmx" },
+ llw = { "lelwel_ls" },
+ lua = { "ast_grep", "emmylua_ls", "lua_ls", "harper_ls" },
+ luau = { "luau_lsp" },
+ mail = { "ltex_plus", "ltex" },
+ make = { "autotools_ls" },
+ markdown = { "tailwindcss", "unocss", "vale_ls", "remark_ls", "zk", "ltex_plus", "ltex", "markdown_oxide", "marksman", "harper_ls", "prosemd_lsp", "dprint", "grammarly", "htmx" },
+ ["markdown.mdx"] = { "marksman" },
+ mdx = { "tailwindcss", "ltex_plus", "mdx_analyzer", "htmx" },
+ menhir = { "ocamllsp" },
+ meson = { "swift_mesonls", "mesonlsp" },
+ ["metamath-zero"] = { "mm0_ls" },
+ motoko = { "motoko_lsp" },
+ move = { "move_analyzer" },
+ mustache = { "tailwindcss", "htmx" },
+ muttrc = { "mutt_ls" },
+ mysql = { "sqlls", "sqls" },
+ ncl = { "nickel_ls" },
+ neomuttrc = { "mutt_ls" },
+ nextflow = { "nextflow_ls" },
+ nginx = { "nginx_language_server" },
+ nickel = { "nickel_ls" },
+ nim = { "nim_langserver", "nimls" },
+ nix = { "nil_ls", "rnix", "harper_ls" },
+ njk = { "tailwindcss", "htmx" },
+ nunjucks = { "tailwindcss", "htmx" },
+ objc = { "clangd" },
+ objcpp = { "clangd" },
+ ocaml = { "ocamllsp" },
+ ocamlinterface = { "ocamllsp" },
+ ocamllex = { "ocamllsp" },
+ odin = { "ols" },
+ opencl = { "opencl_ls" },
+ openscad = { "openscad_lsp" },
+ org = { "ltex_plus", "ltex", "textlsp" },
+ os = { "bsl_ls" },
+ p8 = { "pico8_ls" },
+ pandoc = { "ltex_plus", "ltex" },
+ perl = { "perlnavigator" },
+ pest = { "pest_ls" },
+ php = { "intelephense", "phpactor", "stimulus_ls", "tailwindcss", "unocss", "harper_ls", "psalm", "htmx" },
+ plaintex = { "ltex_plus", "ltex", "texlab" },
+ postcss = { "tailwindcss", "unocss" },
+ prisma = { "prismals" },
+ proto = { "buf_ls", "clangd", "pbls", "protols" },
+ ps1 = { "powershell_es" },
+ pug = { "emmet_language_server", "emmet_ls" },
+ puppet = { "puppet" },
+ purescript = { "purescriptls" },
+ python = { "ast_grep", "basedpyright", "pyre", "pyright", "pylsp", "snyk_ls", "jedi_language_server", "ruff", "harper_ls", "pylyzer", "dprint" },
+ quarto = { "r_language_server", "ltex_plus", "ltex" },
+ query = { "ts_query_ls" },
+ r = { "r_language_server", "air" },
+ raku = { "raku_navigator" },
+ razor = { "tailwindcss", "htmx" },
+ reason = { "tailwindcss", "reason_ls", "ocamllsp", "htmx" },
+ rego = { "regal", "regols" },
+ requirements = { "snyk_ls" },
+ rescript = { "tailwindcss", "unocss", "rescriptls", "htmx" },
+ rmd = { "r_language_server", "ltex_plus", "ltex" },
+ rnoweb = { "ltex_plus", "ltex" },
+ robot = { "robotframework_ls" },
+ roslyn = { "dprint" },
+ rst = { "vale_ls", "ltex_plus", "ltex", "esbonio" },
+ ruby = { "standardrb", "stimulus_ls", "rubocop", "ruby_lsp", "solargraph", "steep", "harper_ls", "sorbet" },
+ rust = { "ast_grep", "unocss", "rust_analyzer", "harper_ls", "dprint" },
+ sass = { "tailwindcss", "unocss", "emmet_language_server", "emmet_ls", "somesass_ls" },
+ scss = { "stylelint_lsp", "tailwindcss", "unocss", "emmet_language_server", "emmet_ls", "somesass_ls", "cssls", "css_variables" },
+ sh = { "bashls" },
+ shaderslang = { "slangd" },
+ slim = { "tailwindcss", "htmx" },
+ slint = { "slint_lsp" },
+ sls = { "salt_ls" },
+ smithy = { "smithy_ls" },
+ sml = { "millet" },
+ solidity = { "solidity_ls", "solang", "solidity", "solidity_ls_nomicfoundation", "solc" },
+ sql = { "sqlls", "sqls", "postgres_lsp" },
+ ss = { "snakeskin_ls" },
+ star = { "starlark_rust" },
+ stylus = { "tailwindcss", "unocss" },
+ sugarss = { "stylelint_lsp", "tailwindcss" },
+ superhtml = { "superhtml" },
+ surface = { "elixirls", "nextls", "lexical" },
+ svelte = { "svelte", "tailwindcss", "unocss", "biome", "emmet_ls", "eslint", "htmx" },
+ svg = { "lemminx" },
+ swift = { "harper_ls" },
+ systemd = { "systemd_ls" },
+ systemverilog = { "svlangserver", "svls", "verible", "hdl_checker" },
+ teal = { "teal_ls" },
+ templ = { "tailwindcss", "html", "htmx", "templ" },
+ terraform = { "terraformls", "snyk_ls", "tflint" },
+ ["terraform-vars"] = { "terraformls", "snyk_ls" },
+ tesc = { "glsl_analyzer", "glslls" },
+ tese = { "glsl_analyzer", "glslls" },
+ tex = { "vale_ls", "ltex_plus", "ltex", "texlab", "textlsp" },
+ text = { "vale_ls", "ltex_plus", "ltex", "textlsp" },
+ thrift = { "thriftls" },
+ toml = { "taplo", "harper_ls", "dprint" },
+ twig = { "tailwindcss", "twiggy_language_server", "htmx" },
+ typescript = { "oxlint", "ast_grep", "vtsls", "denols", "tailwindcss", "ts_ls", "unocss", "quick_lint_js", "biome", "ember", "rome", "snyk_ls", "harper_ls", "eslint", "dprint", "cssmodules_ls", "angularls", "htmx" },
+ ["typescript.glimmer"] = { "ember" },
+ ["typescript.tsx"] = { "oxlint", "ast_grep", "vtsls", "denols", "ts_ls", "biome", "rome", "eslint", "angularls" },
+ typescriptreact = { "oxlint", "ast_grep", "vtsls", "denols", "tailwindcss", "ts_ls", "unocss", "biome", "emmet_language_server", "emmet_ls", "rome", "harper_ls", "eslint", "dprint", "cssmodules_ls", "graphql", "angularls", "htmx" },
+ typespec = { "tsp_server" },
+ typst = { "ltex_plus", "tinymist", "harper_ls" },
+ v = { "v_analyzer", "vls" },
+ vala = { "vala_ls" },
+ vb = { "omnisharp_mono", "omnisharp" },
+ verilog = { "svlangserver", "svls", "verible", "hdl_checker" },
+ vert = { "glsl_analyzer", "glslls" },
+ veryl = { "veryl_ls" },
+ vhd = { "vhdl_ls" },
+ vhdl = { "vhdl_ls", "hdl_checker" },
+ vim = { "vimls" },
+ visualforce = { "visualforce_ls" },
+ vlang = { "vls" },
+ vmasm = { "asm_lsp" },
+ vsh = { "v_analyzer" },
+ vue = { "vuels", "volar", "stylelint_lsp", "tailwindcss", "unocss", "biome", "emmet_ls", "eslint", "htmx" },
+ ["vue-html"] = { "unocss" },
+ vv = { "v_analyzer" },
+ wgsl = { "wgsl_analyzer" },
+ wxss = { "stylelint_lsp" },
+ xhtml = { "ltex_plus", "ltex" },
+ xml = { "lemminx" },
+ xsd = { "lemminx" },
+ xsl = { "lemminx" },
+ xslt = { "lemminx" },
+ yaml = { "azure_pipelines_ls", "gh_actions_ls", "yamlls", "snyk_ls", "spectral", "hydra_lsp" },
+ ["yaml.ansible"] = { "ansiblels" },
+ ["yaml.docker-compose"] = { "docker_compose_language_service", "yamlls" },
+ ["yaml.gitlab"] = { "gitlab_ci_ls", "yamlls" },
+ ["yaml.openapi"] = { "vacuum" },
+ yml = { "spectral" },
+ zig = { "zls" },
+ zir = { "zls" }
+} \ No newline at end of file
diff --git a/lua/mason-lspconfig/mappings.lua b/lua/mason-lspconfig/mappings.lua
index 2523aed..c40853f 100644
--- a/lua/mason-lspconfig/mappings.lua
+++ b/lua/mason-lspconfig/mappings.lua
@@ -20,22 +20,7 @@ function M.get_mason_map()
end
function M.get_filetype_map()
- local server_names = vim.tbl_keys(M.get_mason_map().lspconfig_to_package)
-
- ---@type table<string, string[]>
- local filetype_map = {}
- for _, server_name in ipairs(server_names) do
- local filetypes = vim.tbl_get(vim.lsp.config, server_name, "filetypes")
- if filetypes then
- for _, filetype in ipairs(filetypes) do
- if not filetype_map[filetype] then
- filetype_map[filetype] = {}
- end
- table.insert(filetype_map[filetype], server_name)
- end
- end
- end
- return filetype_map
+ return require "mason-lspconfig.filetype_mappings"
end
function M.get_all()
diff --git a/scripts/lua/mason-scripts/mason-lspconfig/generate.lua b/scripts/lua/mason-scripts/mason-lspconfig/generate.lua
new file mode 100644
index 0000000..75584aa
--- /dev/null
+++ b/scripts/lua/mason-scripts/mason-lspconfig/generate.lua
@@ -0,0 +1,42 @@
+local Optional = require "mason-core.optional"
+
+local _ = require "mason-core.functional"
+local a = require "mason-core.async"
+local path = require "mason-core.path"
+local script_utils = require "mason-scripts.utils"
+
+local MASON_LSPCONFIG_DIR = path.concat { "lua", "mason-lspconfig" }
+
+require("mason").setup()
+local registry = require "mason-registry"
+registry.refresh()
+
+---@async
+local function create_lspconfig_filetype_map()
+ local lspconfig_servers =
+ _.filter_map(_.compose(Optional.of_nilable, _.path { "neovim", "lspconfig" }), registry.get_all_package_specs())
+ ---@type table<string, string[]>
+ local filetype_map = {}
+
+ for _, server_name in ipairs(lspconfig_servers) do
+ local filetypes = vim.tbl_get(vim.lsp.config, server_name, "filetypes")
+ if filetypes then
+ for _, filetype in ipairs(filetypes) do
+ if not filetype_map[filetype] then
+ filetype_map[filetype] = {}
+ end
+ table.insert(filetype_map[filetype], server_name)
+ end
+ end
+ end
+
+ script_utils.write_file(
+ path.concat { MASON_LSPCONFIG_DIR, "filetype_mappings.lua" },
+ "return " .. vim.inspect(filetype_map),
+ "w"
+ )
+end
+
+a.run_blocking(function()
+ create_lspconfig_filetype_map()
+end)
diff --git a/scripts/lua/mason-scripts/utils.lua b/scripts/lua/mason-scripts/utils.lua
new file mode 100644
index 0000000..ee6ab10
--- /dev/null
+++ b/scripts/lua/mason-scripts/utils.lua
@@ -0,0 +1,40 @@
+local _ = require "mason-core.functional"
+local fs = require "mason-core.fs"
+
+local M = {}
+
+---@async
+---@param path string
+---@param contents string
+---@param flags string?
+function M.write_file(path, contents, flags)
+ local header = _.cond({
+ {
+ _.matches "%.lua$",
+ _.always {
+ "-- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.",
+ "-- stylua: ignore start",
+ },
+ },
+ {
+ _.matches "%.md$",
+ _.always {
+ "<!--- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY. -->",
+ },
+ },
+ {
+ _.matches "doc/.+%.txt$",
+ _.always {},
+ },
+ {
+ _.T,
+ _.always {
+ "# THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.",
+ },
+ },
+ }, path)
+
+ fs.async.write_file(path, table.concat(_.concat(header, { contents }), "\n"), flags)
+end
+
+return M
diff --git a/scripts/nvim.sh b/scripts/nvim.sh
new file mode 100755
index 0000000..c2dcb6b
--- /dev/null
+++ b/scripts/nvim.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+set -exuo pipefail
+
+declare -x DEPENDENCIES="${PWD}/dependencies"
+declare -x MASON_DIR="$PWD"
+declare -x MASON_SCRIPT_DIR="${PWD}/scripts"
+
+nvim -u NONE -E -R --headless \
+ --cmd "set rtp^=${MASON_SCRIPT_DIR},${MASON_DIR}" \
+ --cmd "set packpath^=${DEPENDENCIES}" \
+ --cmd "packloadall" \
+ --cmd "luafile $1" \
+ --cmd "q"
diff --git a/tests/mason-lspconfig/api/api_spec.lua b/tests/mason-lspconfig/api/api_spec.lua
index 53b3a27..e0a189e 100644
--- a/tests/mason-lspconfig/api/api_spec.lua
+++ b/tests/mason-lspconfig/api/api_spec.lua
@@ -1,4 +1,7 @@
+local stub = require "luassert.stub"
+
local _ = require "mason-core.functional"
+local mappings = require "mason-lspconfig.mappings"
local mason_lspconfig = require "mason-lspconfig"
describe("mason-lspconfig API", function()
@@ -16,6 +19,10 @@ describe("mason-lspconfig API", function()
end)
it("should return all available servers for given filetype", function()
+ stub(mappings, "get_filetype_map", {
+ ["dummylang"] = { "dummylsp" },
+ })
+
assert.same(
{ "dummylsp" },
_.sort_by(
@@ -28,11 +35,9 @@ describe("mason-lspconfig API", function()
end)
it("should return all available servers for given filetypes", function()
- vim.lsp.config("dummylsp", {
- filetypes = { "dummylang" },
- })
- vim.lsp.config("dummy2lsp", {
- filetypes = { "madeuplang" },
+ stub(mappings, "get_filetype_map", {
+ ["dummylang"] = { "dummylsp" },
+ ["madeuplang"] = { "dummy2lsp" },
})
assert.same(
{ "dummy2lsp", "dummylsp" },
diff --git a/tests/mason-lspconfig/api/command_spec.lua b/tests/mason-lspconfig/api/command_spec.lua
index 3cd6679..7b39c59 100644
--- a/tests/mason-lspconfig/api/command_spec.lua
+++ b/tests/mason-lspconfig/api/command_spec.lua
@@ -4,6 +4,7 @@ local stub = require "luassert.stub"
local Pkg = require "mason-core.package"
local api = require "mason-lspconfig.api.command"
+local mappings = require "mason-lspconfig.mappings"
local registry = require "mason-registry"
describe(":LspInstall", function()
@@ -23,6 +24,9 @@ describe(":LspInstall", function()
local dummy = registry.get_package "dummy"
spy.on(Pkg, "install")
stub(vim.ui, "select")
+ stub(mappings, "get_filetype_map", {
+ ["dummylang"] = { "dummylsp" },
+ })
vim.ui.select.invokes(function(items, opts, callback)
callback "dummylsp"
end)