Skip to content

Conversation

nikkez
Copy link
Contributor

@nikkez nikkez commented Feb 23, 2025

Documentation added how to set up deno lsp when using the kickstart.nvim neovim configuration template and Mason LSP.

Copy link
Contributor

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@marvinhagemeister marvinhagemeister merged commit e1de22e into denoland:main Feb 23, 2025
2 checks passed
@evanlesmez
Copy link

Seems to be out of date https://github.com/mason-org/mason-lspconfig.nvim/releases/tag/v2.0.0.
I can't figure out how to get denols to stop over-eagerly attaching to every JS or TS file.
There is actually a StackOverflow thread on this https://stackoverflow.com/questions/79349248/why-are-both-denols-and-tsserver-attaching-to-the-same-typescript-project-in-neo but at this point that is also out of date.

If I figure out a solution I might post an edit.

@evanlesmez
Copy link

Oh also see nvim-lua/kickstart.nvim#1595

@evanlesmez
Copy link

evanlesmez commented Aug 1, 2025

The current nvim-lspconfig setup section of kickstart does not allow overrides to pass through to override LSP server configuration.
When this PR nvim-lua/kickstart.nvim#1590 goes through, kickstart.nvim users/beginners will have an LSP setup section that looks like this:

{
    -- Main LSP Configuration
    'neovim/nvim-lspconfig',
    dependencies = {
      -- Automatically install LSPs and related tools to stdpath for Neovim
      -- Mason must be loaded before its dependents so we need to set it up here.
      -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
      { 'mason-org/mason.nvim', opts = {} },
      'mason-org/mason-lspconfig.nvim',
      'WhoIsSethDaniel/mason-tool-installer.nvim',

      -- Useful status updates for LSP.
      { 'j-hui/fidget.nvim', opts = {} },

      -- Allows extra capabilities provided by blink.cmp
      'saghen/blink.cmp',
    },
    config = function()
      -- In general, you have a "server" which is some tool built to understand a particular
   
      -- ------------------------------
      --    SKIIPING TO CHANGES
      -- ------------------------------
     
      -- Language servers can broadly be installed in the following ways:
      --  1) via the mason package manager; or
      --  2) via your system's package manager; or
      --  3) via a release binary from a language server's repo that's accessible somewhere on your system.

      -- The servers table comprises of the following sub-tables:
      -- 1. mason
      -- 2. others
      -- Both these tables have an identical structure of language server names as keys and
      -- a table of language server configuration as values.
      ---@class LspServersConfig
      ---@field mason table<string, vim.lsp.Config>
      ---@field others table<string, vim.lsp.Config>
      local servers = {
        mason = {
          -- Add any additional override configuration in any of the following tables. Available keys are:
          --  - cmd (table): Override the default command used to start the server
          --  - filetypes (table): Override the default list of associated filetypes for the server
          --  - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
          --  - settings (table): Override the default settings passed when initializing the server.
          --        For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
          --
          --  Feel free to add/remove any LSPs here that you want to install via Mason. They will automatically be installed and setup.
          -- clangd = {},
          -- gopls = {},
          -- pyright = {},
          -- rust_analyzer = {},
          -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs

          -- Some languages (like typescript) have entire language plugins that can be useful:
          --    https://github.com/pmizio/typescript-tools.nvim
          -- But for many setups, the LSP (`ts_ls`) will work just fine
          --       ts_ls = {},
          denols = {
            workspace_required = true,
          },
          lua_ls = {
            -- cmd = { ... },
            -- filetypes = { ... },
            -- capabilities = {},
            settings = {
              Lua = {
                completion = {
                  callSnippet = 'Replace',
                },
                -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
                -- diagnostics = { disable = { 'missing-fields' } },
              },
            },
          },
          -- intelephense = {},
        },
        -- This table contains config for all language servers that are *not* installed via Mason.
        -- Structure is identical to the mason table from above.
        others = {
          -- dartls
        },
      }

      -- Ensure the servers and tools above are installed
      --
      -- To check the current status of installed tools and/or manually install
      -- other tools, you can run
      --    :Mason
      --
      -- You can press `g?` for help in this menu.
      --
      -- `mason` had to be setup earlier: to configure its options see the
      -- `dependencies` table for `nvim-lspconfig` above.
      --
      -- You can add other tools here that you want Mason to install
      -- for you, so that they are available from within Neovim.
      local ensure_installed = vim.tbl_keys(servers.mason or {})
      vim.list_extend(ensure_installed, {
        'stylua', -- Used to format Lua code
      })
      require('mason-tool-installer').setup { ensure_installed = ensure_installed }
      -- Either merge all additional server configs from the `servers.mason` and `servers.others` tables
      -- to the default language server configs as provided by nvim-lspconfig or
      -- define a custom server config that's unavailable on nvim-lspconfig.

      for server, config in pairs(vim.tbl_extend('keep', servers.mason, servers.others)) do
        if not vim.tbl_isempty(config) then
          vim.lsp.config(server, config)
        end
      end

      require('mason-lspconfig').setup {
        ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via masontool-installer)
        automatic_enable = true, -- automatically run vim.lsp.enable() for all servers that are installed via Mason
      }
      if not vim.tbl_isempty(servers.others) then
        vim.lsp.enable(vim.tbl_keys(servers.others))
      end
    end,
  }

So the handlers part of the previous mason-lspconfig setup will be replaced with direct call to vim.lsp.config .
That way, our overrides go through.
And now to make Deno only attach to Deno dirs where deno.json or something similar is present, just use workspace_required = true in the denols config.
To be honest though, I am not sure why that is not shipped as the default config for denols unless their is some limitation I am unaware of.

@evanlesmez
Copy link

So for ts and deno non-conflicting support, configuration would then look like this

         ts_ls = {
            workspace_required = true,
            root_markers = { 'package.json' },
          },
          denols = {
            workspace_required = true,
            root_markers = { 'deno.json', 'deno.jsonc' },
          }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants