模块“未找到 lspconfig”

问题描述 投票:0回答:1

我正在使用 Neovim、Lua 和 Lazy.nvim。我已经安装了 nvim-lspconfig,如下截图所示: Proof

无论如何,我想在 Neovim 中使用 GDScript,这就是我最终所做的:

 -- General lsp setups for Language servers not supported by Mason.

local lsp = require("lspconfig")

lsp.godot.setup {
  cmd = { "nc", "localhost", "6008" },
  filetypes = { "gd", "gdscript", "gdscript3" },
  root_dir = function(startpath)
    return M.search_ancestors(startpath, matcher)
  end
}

我重新启动一切,然后出现错误。 这是典型的“找不到模块”错误: error

它也破坏了我的配置,没有命令(除了 Neovim 附带的命令之外)工作。

问题是,我明确安装了

nvim-lspconfig
这是我的lspconfig.lua文件


return  {
    -- LSP Configuration & Plugins
    'neovim/nvim-lspconfig',
    dependencies = {
      -- Automatically install LSPs to stdpath for neovim
      {'williamboman/mason.nvim', config = true},
      'williamboman/mason-lspconfig.nvim',

      -- Useful status updates for LSP
      -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
      { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },

      -- Additional lua configuration, makes nvim stuff amazing!
      'folke/neodev.nvim',
    },
    config = function ()
      local on_attach = function(_, bufnr)
      -- NOTE: Remember that lua is a real programming language, and as such it is possible
      -- to define small helper and utility functions so you don't have to repeat yourself
      -- many times.
      --
      -- In this case, we create a function that lets us more easily define mappings specific
      -- for LSP related items. It sets the mode, buffer and description for us each time.
      local nmap = function(keys, func, desc)
        if desc then
          desc = 'LSP: ' .. desc
        end
      
        vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
      end
      

      nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
      nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')

      nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
      nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
      nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
      nmap('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
      nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
      nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')

      -- See `:help K` for why this keymap
      nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
      nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')

      -- Lesser used LSP functionality
      nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
      nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
      nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
      nmap('<leader>wl', function()
        print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
        end, '[W]orkspace [L]ist Folders')
      -- Create a command `:Format` local to the LSP buffer
      vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
        vim.lsp.buf.format()
      end, { desc = 'Format current buffer with LSP' })
    end
    end

}

获得形式启动。

我尝试询问 ChatGPT,但 ChatGPT 似乎无法正确回答我(它的所有解决方案似乎都与 Vim-Plug 相关)所以我决定只在 Stack Overflow 上询问,也许已经解决了这个问题的人可以提供帮助。

lazy-evaluation neovim liskov-substitution-principle nvim-lspconfig
1个回答
0
投票

虽然我不回答你的问题,但为了避免此类问题, 如果您使用 mason.nvim 和 lspconfig,建议您使用 [mason-lspconfig.nvim] 1,特别是如果您使用的是 Windows。

© www.soinside.com 2019 - 2024. All rights reserved.