neovim/nvim-lspconfig

Can't disable lsp even if root_dir is set to returning nil

glyh opened this issue · 1 comments

glyh commented

Description

here's my lua ls setup, based on nvchad's. And having read the discourse here.
I have root_dir set to returning nil whenever it finds the filename to match xmake.lua. But it still fires up lua_ls and formats my xmake.lua file.

local M = require "nvchad.configs.lspconfig"

lspconfig.lua_ls.setup {
  on_attach = M.on_attach,
  capabilities = M.capabilities,
  on_init = M.on_init,

  root_dir = function(filename, bufnr)
    local suf_xmake = "xmake.lua"
    if filename:sub(-#suf_xmake) == suf_xmake then
      print "wat"
      return nil
    end
    return require("lspconfig.server_configurations.lua_ls").default_config.root_dir(filename, bufnr)
  end,

  settings = {
    Lua = {
      diagnostics = {
        globals = { "vim" },
      },
      workspace = {
        library = {
          vim.fn.expand "$VIMRUNTIME/lua",
          vim.fn.expand "$VIMRUNTIME/lua/vim/lsp",
          vim.fn.stdpath "data" .. "/lazy/ui/nvchad_types",
          vim.fn.stdpath "data" .. "/lazy/lazy.nvim/lua/lazy",
          "${3rd}/luv/library",
        },
        maxPreload = 100000,
        preloadFileSize = 10000,
      },
    },
  },
}

single_file_support is true by default of luals so even there is no root it will spawn luals with single file mode. you can set to false.