Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可以请教下如何设置 pyright LSP吗 #2

Closed
NoirJ0e opened this issue Dec 22, 2021 · 2 comments
Closed

可以请教下如何设置 pyright LSP吗 #2

NoirJ0e opened this issue Dec 22, 2021 · 2 comments

Comments

@NoirJ0e
Copy link

NoirJ0e commented Dec 22, 2021

非常感谢分享nvim lua的设置,很多资料看的是一头雾水。

我按照你在知乎上分享的步骤一路走下来,现在打算配置一下 pyright 的lsp
我创建了 lua/lsp/pyrght.lua, 文件的内容是从 nvim-lspconfig 那里抄来的

require'lspconfig'.pyright.setup{}

然后我在setup.lua下添加了这个配置,现在这个文件是这样的:

setup.lua
local lsp_installer = require "nvim-lsp-installer"
-- 安装列表
-- https://github.com/williamboman/nvim-lsp-installer#available-lsps
-- { key: 语言 value: 配置文件 }
local servers = {
    sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua
    rust_analyzer = require "lsp.rust",
    pyright = require "lsp.pyright",
  }
  
  -- 自动安装 LanguageServers
  for name, _ in pairs(servers) do
    local server_is_found, server = lsp_installer.get_server(name)
    if server_is_found then
      if not server:is_installed() then
        print("Installing " .. name)
        server:install()
      end
    end
end

lsp_installer.on_server_ready(function(server)
    local opts = servers[server.name]
    if opts then
      opts.on_attach = function(_, bufnr)
        local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
        -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
        -- 绑定快捷键
        require('keybinds').maplsp(buf_set_keymap)
      end
      opts.flags = {
        debounce_text_changes = 150,
      }
      server:setup(opts)
    end
  end)

这样子启动之后可以正常实现报错和补全,但是初次启动的时候一直有一个报错如下:
image

请问这个报错有什么办法可以判决吗

@nshen
Copy link
Owner

nshen commented Dec 22, 2021

@NoirJ0e 把 pyrght.lua 内容改成 return {} 应该就好了。
我那个 setup.lua 里会统一调用 setup方法,配置文件只要 return 配置 就行。如果没有就 return {}

@NoirJ0e
Copy link
Author

NoirJ0e commented Dec 22, 2021

改成这样后就可以了,非常感谢

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

No branches or pull requests

2 participants