NvChad / NvChad

Blazing fast Neovim config providing solid defaults and a beautiful UI, enhancing your neovim experience.
https://nvchad.com/
GNU General Public License v3.0
24.14k stars 2.1k forks source link

Question: Where to plug in Per File/Per Path LSP Configurations? #725

Closed erwin closed 2 years ago

erwin commented 2 years ago

Describe the bug

I have the folke/lua-dev package setup to make my Lua config editing more pleasant, however, I only want it to activate when the actual file being edited is inside of ~/.config/nvim.

Unfortunately, inside of custom.plugins.lspconfig -> M.setup_lsp -> lsp_installer.on_server_ready() we can't use vim.fn.expand("%:p") to get the path to the buffer being edited.

nogweii @ lua-dev.nvim posted about exactly how to apply this to nvim generally:

https://github.com/folke/lua-dev.nvim/issues/12#issuecomment-1000062991

So if we can't get access to the current file inside of custom.plugins.lspconfig, then where would we insert something like this?

For reference I'm trying to do:

local M = {}

M.setup_lsp = function(attach, capabilities)
    local lsp_installer = require "nvim-lsp-installer"

    lsp_installer.on_server_ready(function(server)
      local opts = {
         on_attach = attach,
         capabilities = capabilities,
         flags = {
            debounce_text_changes = 150,
         },
         settings = {},
      }

      local cfgpath = vim.fn.resolve(vim.fn.stdpath("config"))
      -- Problem is here...
      local bufpath = vim.fn.expand("%:p")
      -- `expand("%:p")` comes back empty...
      if server.name == "sumneko_lua" then
        if string.sub(bufpath, 1, string.len(cfgpath)) == cfgpath then
          opts.settings = require("lua-dev").setup().settings
        end
      end

      server:setup(opts)
      vim.cmd [[ do User LspAttachBuffers ]]
    end)
end

return M

Thanks so much for taking the time to read though this!

siduck commented 2 years ago

@erwin https://github.com/NvChad/NvChad/issues/748