首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在windows上启动具有新内容的clangd lsp服务器

无法在windows上启动具有新内容的clangd lsp服务器
EN

Stack Overflow用户
提问于 2022-06-08 19:40:12
回答 1查看 1.4K关注 0票数 2

我正在尝试创建一个新的配置,允许我使用用cmake生成的c++项目。

我已经安装了nvim-lspconfig插件,我用VisualStudio2022安装程序安装了clang (两者都是声音,clang-cl and clang-compiler)。但是,当我在neovim中cd一个cmake根文件夹时,当我打开一个c++文件时,什么都不会发生。我连错误都看不见。就像服务器不工作一样。

为了使用Visual 2022附带的clang,我如何设置neovim?

这是我的init.lua

代码语言:javascript
复制
--- Require ---

local utils = require('utils') -- just to set some keys, not related to the clang problem.

--- Options ---

-- Add number to rows

utils.opt('o', 'number', true)

-- Set indentation of files
local indent = 2
utils.opt('b', 'expandtab', true)
utils.opt('b', 'shiftwidth', indent)
utils.opt('b', 'smartindent', true)
utils.opt('b', 'tabstop', indent)
utils.opt('b', 'autoindent', true)
utils.opt('o', 'smarttab', true)
utils.opt('b', 'softtabstop', indent)

-- Enable the mouse
utils.opt('o', 'mouse', 'a')

-- Set nocompatible mode for more powerful commands
utils.opt('o', 'compatible', false)

-- Set some search options
utils.opt('o', 'showmatch', true)
utils.opt('o', 'ignorecase', true)
utils.opt('o', 'hlsearch', true)
utils.opt('o', 'incsearch', true)

-- Set options for color scheme
utils.opt('o', 'termguicolors', true)

--- Keymappings ---

-- Remap jj to escape in insert mode
utils.map('i', 'jj', '<Esc>')
utils.map('n', 'JJJJ', '<Nop>')

-- Swap ; and :
utils.map('n', ':', ';')
utils.map('n', ';', ':')

-- Start plugin section. Use this section in order to install new plugins to
-- neovim.
--
-- In order to install a new plugin, you need to put in this section the
-- repository where it can be found, and then refresh the plugin list by
-- installing them with the command:
--
-- :PlugInstall

-- Auto install vim-plug that's a plugin manager
local vimplugrepository = ''
local installpath = vim.fn.stdpath('config')..'/autoload'
local vimpluginstallpath = installpath..'/plug.vim'
local vimplugrepository = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
if vim.fn.empty(vim.fn.glob(vimpluginstallpath)) > 0 then
  vim.api.nvim_command('!curl -flo '..vimpluginstallpath..' --create-dirs '..vimplugrepository)
  vim.cmd 'autocmd VimEnter * PlugInstall'
end
local Plug = vim.fn['plug#']

-- Put plugins in this section. Define a Plug with the repository of the plugin that you want

vim.call('plug#begin', installpath)

-- Vim airline. This plugin creates a nice status bar with more features than
-- standard one.
Plug 'https://github.com/vim-airline/vim-airline'

-- NerdTree is a plugin for showing a tree folder structure of the filesystem.
Plug 'https://github.com/preservim/nerdtree'

-- Vim color schemes
Plug 'https://github.com/rafi/awesome-vim-colorschemes'

-- Developer icons
Plug 'https://github.com/ryanoasis/vim-devicons'

-- Surrounding with parenthesis and xml tags with cs command and more
Plug 'https://github.com/tpope/vim-surround'

-- Show trailing whitespaces and use the command :StripWhitespace for removing
-- them
Plug 'https://github.com/ntpeters/vim-better-whitespace.git'

-- Install the LSP server for configuring it with clangd for code completition
-- in C++
Plug 'https://github.com/neovim/nvim-lspconfig'

-- An interesting theme
Plug 'https://github.com/Pocco81/Catppuccino.nvim'

-- CMake integration. It includes following commands:
-- :CMakeGenerate - it generates the project
-- :CMakeBuild - It builds the project.
-- :CMakeSwitch <config> - It switches between configurations
Plug 'https://github.com/cdelledonne/vim-cmake'

vim.call('plug#end')

--- PLUGINS CONFIGURATION ---

-- Nerdtree

-- Configure keys so with ctrlf go to the tree, with ctrl+n open the tree, and
-- ctrl+t toggle the tree
utils.map('n', '<C-f>', ':NERDTreeFocus<CR>')
utils.map('n', '<C-n>', ':NERDTree<CR>')
utils.map('n', '<C-t>', ':NERDTreeToggle<CR>')

--- LSP CONFIG ---

-- Main configuration
local lspremapopts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, lspremapopts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, lspremapopts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, lspremapopts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, lspremapopts)

-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
  -- Enable completition triggered by <c-x><c-o>
  vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings
  -- See ':help vim.lsp.*
  local bufopts = { noremap = true, silent = true, buffer = bufnr }
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
  vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
  vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
  vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
  vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
  vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
  vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
  vim.keymap.set('n', '<space>wl', function ()
    print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  end, bufopts)
  vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
  vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
  vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
  vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
  vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
end

-- Now the servers must be defined and set. In order to load them it's
-- convenient to define them in an array and use a loop.
local servers = { 'pyright', 'clangd' }
for _, lsp in pairs(servers) do
  require('lspconfig')[lsp].setup {
    on_attach = on_attach,
    flags = {
      debounce_text_changes = 150
    }
  }
end


--- COLOR SCHEME ---

vim.cmd[[colorscheme catppuccin]]
EN

回答 1

Stack Overflow用户

发布于 2022-08-10 15:31:24

您可以运行:LspInfo来查看客户端是否附加到缓冲区。如果是的话,您可以运行:LspLog来获得更多关于问题来源的信息。如果不是,则配置有问题。

LSP客户端需要能够找到clangd。因此,它要么需要在您的路径中,要么您需要完全指定路径。

VS安装的clang不在您的路径中。如果您从运行新from,它将添加到您的路径中(命令提示符\PowerShell)。

您还可以手动指定完整路径:

代码语言:javascript
复制
require('lspconfig')['clangd'].setup {
  on_attach = on_attach,
  cmd = { '<full path to clangd>' }
  flags = {
    debounce_text_changes = 150
  }
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72551333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档