免责声明:我完全了解 VS Code,所以,请对我温柔一点。:-)
我正在尝试为C++设置VS Code。
但是,我明确希望对其进行设置,以便在处理 C++ 文件时使用语言服务器协议进行通信。clangd
我已经clangd在我的 (Ubuntu Linux) 系统上安装了 VS Code 市场的官方 “vscode-clangd”扩展,我还调整了它的设置,以便它clangd可以找到它。
然而,现在我迷路了。
当我打开一个*.cpp或*.hpp文件时,VS Code 向我推荐了一些其他扩展(例如支持 IntelliSense的官方 Microsoft “C/C++”扩展),但我根本看不到在哪里以及如何clangd帮助我。
使用 Microsoft 的“C/C++”扩展似乎开箱即用,但我该如何使用clangd?
谢谢你的帮助。
我是这个主题的新手,所以很有可能我弄错了一些关键术语。我想将打字稿文件解析为其组件符号。举一个我想象出来的非常粗略的例子,见下文:
// some ts file
export function yell(output: string) {
alert(output + "!!");
}
Run Code Online (Sandbox Code Playgroud)
会创建这样的东西:
{
symbols: [
{ type: "comment", text: "// some ts file" },
"\n",
{ type: "module", text: "export" },
" ",
{ type: "function", symbols: [
{ type: "name", text: "yell" },
... it goes on
]}
]
}
Run Code Online (Sandbox Code Playgroud)
我很确定这个符号化/标记化是语言服务器初始化阶段的一部分,试图从这个问题中收集信息(https://github.com/Microsoft/language-server-protocol/issues/33)。
但是我通读了有关 initialize ( https://microsoft.github.io/language-server-protocol/specification#initialize )的文档,但找不到 (ctrl-f) 任何有关返回的符号或令牌的信息。
不久前,我在摩纳哥工作,我知道语言服务器的重点主要是标准化代码的标记化和链接/导航,所以我很确定这是适合它的工具。但是文档非常密集,似乎更侧重于代码交互而不是代码解析。
如何使用语言服务器协议将 TS 解析为符号?
编辑:值得一提的是,如果这本身就是一个项目:我不是在寻找这个或任何东西的完整代码。只是对发生的事情的某种粗略概述,也许还有一些相关文档的链接/摘录。
编辑 2:我在这里发现了一个非常相似的问题(TypeScript: get syntax tree),但它没有提到语言服务器,而且似乎是在它们之前的时间出现的。
编辑 3:看来我正在寻找的正确术语是 AST。在网上找到了一个非常酷的 TypeScript …
存储库https://github.com/microsoft/vscode-extension-samples/tree/master/lsp-sample中的 lsp-sample显示了如何实现onCompletion
服务器只听字母 [az] 而不是句点 (.) 我已经看到这是用 控制的triggerCharacters,但我不清楚在哪里设置这些。这似乎需要在客户端部分完成,但似乎我只能注册另一个onCompletion处理程序。有人可以透露一些信息吗?
这是服务器端代码:
// This handler provides the initial list of the completion items.
connection.onCompletion(
(_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
// The pass parameter contains the position of the text document in
// which code complete got requested. For the example we ignore this
// info and always provide the same completion items.
return [
{
label: 'TypeScript',
kind: CompletionItemKind.Text,
data: 1
},
{
label: 'JavaScript',
kind: CompletionItemKind.Text, …Run Code Online (Sandbox Code Playgroud) visual-studio-code vscode-extensions language-server-protocol
当使用 Sublime text 3 时,我有SublimeLinter和SublimeLinter-eslint包,以及用于 JS 和 JSX 语法的eslint和babel-eslint全局节点模块。
切换到 Sublime 4 后,我决定尝试一下LSP。我安装了它,还安装了LSP-css(开箱即用)和LSP-eslint,但无法工作。
如果我检查 Sublime 的状态栏,我会看到语言服务器显然正在运行(?)

这是在一个具有自己的eslintrc.js配置文件的项目中,该文件在 VScode 中开箱即用。部分内容如下:
const RulesAirBnb = require("eslint-config-airbnb-base/rules/best-practices");
const RulesCRA = require("eslint-config-react-app");
module.exports = {
root: true,
parser: "babel-eslint",
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
ecmaFeatures: {
jsx: true,
generators: true,
},
},
extends: [
"airbnb", // Baseguide is AirBnB"s
"prettier",
"prettier/react",
],
Run Code Online (Sandbox Code Playgroud)
eslint eslint-config-airbnb language-server-protocol eslintrc sublimetext4
最近我遇到了无法解决的问题。这是关于 Elixir LS 的,当我运行语言服务器时,它显示以下消息:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Started ElixirLS v0.12.0","type":3}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"ElixirLS built with elixir \"1.14.2\" on OTP \"25\"","type":3}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Running on elixir \"1.14.2 (compiled with Erlang/OTP 25)\" on OTP \"25\"","type":3}}
{"jsonrpc":"2.0","method":"window/showMessage","params":{"message":"OTP compiled without EEP48 documentation chunks","type":2}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"OTP compiled without EEP48 documentation chunks. Language features for erlang modules will run in limited mode. Please reinstall or rebuild OTP with approperiate flags.","type":2}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Elixir sources not found (checking in /home/build/elixir). Code navigation to Elixir modules disabled.","type":3}}
Run Code Online (Sandbox Code Playgroud)
ElixirLS 无法正确编译,正如它所说,它在没有 EEP48 文档的情况下编译。我按照 ElixirLS 安装指南进行操作,但无法使其工作。Erlang 和 elixir 是随 asdf 安装的,我在 …
我当前正在编写语言服务器(在lsp4j之上),并且需要调试我的语言服务器。语言服务器协议服务器使用stdin和stdout与客户端进行通信。
现在,我想调试从客户端启动的服务器(VSCode),因此我为生成的JVM进程添加了调试标志:
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999
Run Code Online (Sandbox Code Playgroud)
突然执行此操作后,即使suspend = 0并且我确认端口已打开并且没有发生防火墙恶意代码,服务器也无法再工作。
我决定手动运行命令行,我看到一个进程在接收到调试参数后要做的第一件事就是向stdout输出以下内容:
Listening for transport dt_socket at address: 9999
Run Code Online (Sandbox Code Playgroud)
(发射时不带双引号)
我认为这是我无法调试语言服务器的原因,因为将任何不属于语言服务器协议规范的内容输出到stdout或stdin都会迫使客户端拒绝该服务器。
因此,我的问题是以一种绕道的方式询问是否可以通过另一个JVM参数使stdout,stdin,stderr上的内部JVM消息静默吗?
我正在努力实现的目标
我想一起使用 go-mode/lsp-mode 。我一开始就很难让 lsp-mode 执行,最后通过附加路径 :facepalm: 让它工作。
问题 现在的问题是,当 lsp-mode 为工作 golang 目录启动时,我收到此错误:
LSP :: Error from the Language Server: no views in the session (Unknown error) [3 times]
Run Code Online (Sandbox Code Playgroud)
我在互联网上搜索答案,但尚未找到与我的问题相关的任何内容。我正在向社区寻求一些指导。
go-mode.el
LSP :: Error from the Language Server: no views in the session (Unknown error) [3 times]
Run Code Online (Sandbox Code Playgroud)
lsp模式.el
(defun custom-go-mode ()
(display-line-numbers-mode 1))
(use-package go-mode
:defer t
:ensure t
:mode ("\\.go\\'" . go-mode)
:init
(setq compile-command "echo Building... && go build -v && echo Testing... && go test -v …Run Code Online (Sandbox Code Playgroud) 在语言服务器协议规范中,语义标记响应具有一个数据字段,该数据字段是标记的整数数组。
export interface SemanticTokens {
/**
* The actual tokens.
*/
data: uinteger[];
}
Run Code Online (Sandbox Code Playgroud)
在所有示例中,语义标记都是在客户端使用 SemanticTokensBuilder 完成的,SemanticTokensBuilder 为每个标记类型指定行和列范围。你如何做服务器端?当VSCode发送“textDocument/semanticTokens/full”方法时,语言服务器返回什么?
我试图包含lua_ls在我的 lspconfig 中,但收到此错误
[lspconfig] Cannot access configuration for lua_ls. Ensure this server is listed in `server_configurations.md` or added as a custom server.
lua_ls只有在我添加到ensured_installedon后才会出现mason-lspconfig。
我正在使用mason和lazy.nvim插件管理器。
这是我的 mason-lspconfig 设置
{
"williamboman/mason-lspconfig.nvim",
config = function()
require("mason-lspconfig").setup({
ensure_installed = {
"angularls",
"bashls",
"cssls",
"eslint",
"gopls",
"html",
"jsonls",
"lua_ls",
"rust_analyzer",
"svelte",
"tailwindcss",
"tsserver",
"yamlls",
},
})
end,
},
Run Code Online (Sandbox Code Playgroud) 我的 Eclipse '.metadata.log' 文件中出现以下异常,导致 CPU 使用率几乎达到 80%。有人知道这是什么意思吗?或者说需要如何修复?这是在 Eclipse 上安装 STS 插件后开始的。
`
java.util.concurrent.ExecutionException: org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: The pipe is being closed
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)
at org.eclipse.lsp4e.LanguageServerWrapper.lambda$13(LanguageServerWrapper.java:497)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: The pipe is being closed
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageConsumer.consume(StreamMessageConsumer.java:72)
at org.eclipse.lsp4e.LanguageServerWrapper.lambda$3(LanguageServerWrapper.java:265)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.request(RemoteEndpoint.java:161)
at org.eclipse.lsp4j.jsonrpc.services.EndpointProxy.invoke(EndpointProxy.java:91)
at jdk.proxy11/jdk.proxy11.$Proxy35.shutdown(Unknown Source)
at org.eclipse.lsp4e.LanguageServerWrapper.lambda$13(LanguageServerWrapper.java:495)
... 7 more
Run Code Online (Sandbox Code Playgroud)
`
这绝对会降低我的工作效率,而我这里有一台配置非常好的机器,Lenovo t495,配备完整 SSD 存储和 32 GB RAM。只是没有意义。检查“.metadata.log”文件并继续看到此异常。
我想编写一个 VSIX LSP 扩展。我希望它以最简单的方式工作 - 这似乎是使用“打开文件夹”功能来打开代码文件夹,然后做我的事情。
要启动 LSP 服务器,我需要知道打开的文件夹的目录。我如何知道 Visual Studio 是否处于“打开文件夹”模式(如果不是,则不应启动 LSP),以及如何知道该文件夹的路径(以便我可以启动 LSP 服务器)?
我发现https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivssolutionevents7?view=visualstudiosdk-2017这似乎很有希望,因为我可以在某些特定文件夹出现时进行注册打开 - 告诉我已使用“打开文件夹”功能的事件可能是完美的 - 如果打开文件夹,则启动该文件夹的 LSP。
vs-extensibility vsix visual-studio-extensions language-server-protocol
我尝试了几种方法来使它工作,但似乎没有简单的方法。是的,有大量的插件和配置。但根据 2019 年 10 月,它们无法正常工作。
所以这似乎 csharpers 应该去 VS(或 Rider),那是 MS 提出 LSP 的时候。你如何让 IDE 像 nvim 一样与 C# 一起工作?
基本上客户端应该像这样启动服务器并使用 LSP。
~/.cache/omnisharp-vim/omnisharp-roslyn/run -s <PATH TO SLN OR DIR>
Run Code Online (Sandbox Code Playgroud) 这是我的 vimrc 文件。我真的不知道是什么问题。我在这上面花了 3 个多小时,我已经完成了......
syntax on
set guicursor=
set relativenumber
set noerrorbells
set tabstop=2 softtabstop=2
set shiftwidth=2
set expandtab
set smartindent
set nu
set nowrap
set smartcase
set noswapfile
set nobackup
set undodir=~/.vim/undodir
set undofile
set incsearch
set cursorline
set cursorcolumn
set updatetime=50
call plug#begin('~/.vim/plugged')
Plug 'gruvbox-community/gruvbox'
Plug 'preservim/nerdtree'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'scrooloose/syntastic'
Plug 'scrooloose/nerdcommenter'
Plug 'majutsushi/tagbar'
Plug 'vim-airline/vim-airline'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'airblade/vim-gitgutter'
Plug 'blueyed/vim-diminactive'
Plug 'mattn/emmet-vim'
Plug 'junegunn/fzf', { 'do': { -> …Run Code Online (Sandbox Code Playgroud)