vscode languageserver node
release
该存储库包含以下 npm 模块的代码:
所有 npm 模块均使用一个 Azure Pipeline 构建。其状态是:
单击此处获取有关如何使用这些 npm 模块为 VSCode 实现语言服务器的详细文档。
克隆存储库后,运行npm install
以安装依赖项,并npm run symlink
将此存储库中的包相互指向。
5.5.x
20.9.0
和es2022
。另请参阅 TypeScript 的节点目标映射。vscode-jsonrpc
、 vscode-languageserver-protocol
、 vscode-languageclient
和vscode-languageserver
现在使用exports
属性,而不是main
和typings
属性。这可能需要在module
和moduleResolution
周围的 tsconfig.json 文件中采用。 LSP 库当前使用node16
作为这两个值。CancellationToken
以使其与其他中间件保持一致。这是一个重大更改,因为它添加了必需的参数。 client . getFeature ( lsclient . FoldingRangeRequest . method ) . getProvider ( document ) ?. provider ;
图书馆的具体变化是:
start
和stop
方法。这两个方法现在都返回一个承诺,因为这些方法是异步的。这是一个重大变化,因为 start 之前返回了一次性的。扩展现在应该在其扩展主文件中实现停用功能,并从停用调用正确返回stop
承诺。因此, onReady()
被删除,因为扩展现在可以等待start()
调用。像这样的旧代码 const client : LanguageClient = ... ;
client . start ( ) ;
await client . onReady ( ) ;
应该变成:
const client : LanguageClient = ... ;
await client . start ( ) ;
sendNotification
方法现在都返回一个承诺。返回承诺是必要的,因为将消息实际写入底层传输是异步的,并且客户端无法确定通知是否已传递给传输。这是一个重大变化,因为它可能会导致浮动承诺并可能被 linter 标记。handleFailedRequest
的行为已更改。当从服务器收到异常时,该方法不再返回默认值,而是重新抛出错误。这可确保使用 VS Code 对错误的默认行为。该方法还按以下方式处理RequestCancelled
和ServerCancelled
:ServerCancelled
并且客户端没有取消请求,也会抛出 CancellationError 来要求客户端重新运行请求。RequestCancelled
那么通常客户端应该取消请求并且代码将返回默认值(根据 3.16 规范的最佳解释)。如果客户端尚未取消,则将RequestCancelled
解释为ServerCancelled
。null
)取消,则客户端中间件的下一个处理程序现在会丢弃服务器结果。这是一个重大更改,因为在该库的早期版本中,中间件会看到 VS Code 也未使用的结果。进行此更改是为了通过不转换未使用的响应结果来节省 CPU 和内存。有关协议 3.16.0 版本中所做更改的详细列表,请参阅 3.16 规范的更改日志。
图书馆的具体变化是:
messages
属性重命名为registrationType
并返回相应的RegistrationType
。另外从register
方法中删除第一个参数。ErrorCodes
。 LSP 特定错误代码已移至新的命名空间LSPErrorCodes
。 jsonrpc
中的命名空间ErrorCodes
未正确保留用于 JSON RPC 特定错误代码。这是一个突破性的改变。要解决此问题,请改用LSPErrorCodes
。vscode-jsonrpc
为例:(a) import vscode-jsonrpc
只会导入公共代码,(b) import vscode-jsonrpcnode
将导入公共代码和节点代码,(c) import vscode-jsonrpcbrowser
将导入公共代码和浏览器代码。vscode-jsonrpc
中发送请求和通知时控制参数结构的支持。创建请求或通知类型时,或者使用sendRequest
或sendNotification
函数发送非类型化请求或通知时,可以使用附加的parameterStructures
参数来控制参数结构。默认值为ParameterStructures.auto
,它执行以下操作:byPosition
用于具有零个或大于一个参数的消息byName
作为对象文字参数。对所有其他参数使用byPosition
。 SelectionRangeRequest
协议:SelectionRange
SelectionRangeRequest
、 SelectionRangeParams
、 SelectionRangeClientCapabilities
、 SelectionRangeServerCapabilities
、 SelectionRangeProviderOptions
、vscode-languageserver-textdocument
提供了带有基本增量更新的标准文本文档实现。服务器现在需要预先安装此 npm 包。new TextDocuments
。以下是 TypeScript 和 JavaScript 中的示例 import { TextDocuments } from 'vscode-languageserver' ;
import { TextDocument } from 'vscode-languageserver-textdocument' ;
const documents = new TextDocuments ( TextDocument ) ;
const server = require ( "vscode-languageserver" ) ;
const textDocument = require ( "vscode-languageserver-textdocument" ) ;
const documents = new server . TextDocuments ( textDocument . TextDocument ) ;
RenameOptions
FoldingRangeRequestParam
重命名为“FoldingRangeParams”(仍提供FoldingRangeRequestParam
以实现向后兼容性)package.json
文件中的engines.vscode
中指定的预期客户端版本是否与客户端运行的 VS Code 版本匹配。Color
、 ColorInformation
、 ColorPresentation
移至 TypesFoldingRangeRequest
协议:FoldingRange
、 FoldingRangeKind
FoldingRangeRequest
、 FoldingRangeRequestParam
、 FoldingRangeClientCapabilities
、 FoldingRangeServerCapabilities
、 FoldingRangeProviderOptions
、CompletionItem
上preselect
属性的支持添加对诊断中相关信息的支持。
初始化异常被吞掉
VSCode 中仍未显示重命名错误
TerminateProcess.sh 未在 dist 包中提供
添加中间件拦截textDocument/publishDiagnostics
provideCompletionItem?: ( this : void , document : TextDocument , position : VPosition , token : CancellationToken , next : ProvideCompletionItemsSignature ) => ProviderResult < VCompletionItem [ ] | VCompletionList > ;
现在包含一个附加参数context
:
provideCompletionItem?: ( this : void , document : TextDocument , position : VPosition , context : VCompletionContext , token : CancellationToken , next : ProvideCompletionItemsSignature ) => ProviderResult < VCompletionItem [ ] | VCompletionList > ;
vscode-languageserver-protocol
,其中包含 TypeScript 中的协议定义。该模块现在在客户端和服务器之间共享。protocol
、 client
和server
npm 模块中添加了对提议协议的支持。即使提议的协议包含在稳定版本的 npm 模块中,也可能会发生变化。client/registerFeature
使用错误的名称:应该是client/registerCapability
WorkspaceEdit
符合 3.x 版本的规范并向后兼容 2.x 版本的库。RequestCancelled
错误代码。Files.uriToFilePath
转而使用 vscode-uri npm 模块,该模块为 VS Code 提供了更完整的 URI 实现。rootPath
设为可选,因为它在 3.x 中已弃用。client/registerCapability
和client/unregisterCapability
动态注册和取消注册功能处理程序。workspace/executeCommand
将命令执行委托给服务器。InsertTextFormat
let client = new LanguageClient ( ... ) ;
client . onReady ( ) . then ( ( ) => {
client . onNotification ( ... ) ;
client . sendRequest ( ... ) ;
) ;
// Old
import { Protocol2Code , ... } from 'vscode-languageclient' ;
Protocol2Code . asTextEdits ( edits ) ;
// New
let client = new LanguageClient ( ... ) ;
client . protocol2CodeConverter . asTextEdits ( edits ) ;
LanguageClient
在 VS Code 扩展中使用。您可以在此处找到有关如何将 VS Code 扩展升级到 TypeScript 2.xx 的详细步骤。activeSignature
和activeParameter
在SignatureHelp
中被错误地声明为可选。它们现在是强制性的。protocol.ts
文件在 2.x 中使用枚举类型。然而,协议本身是基于数字的,因为无法假设实现语言中是否存在枚举类型。为了更清楚地说明这一点,枚举被带有或文字类型定义的数字类型替换。如果在没有适当范围检查的情况下将数字直接分配给先前的枚举类型,则可能会导致编译错误。RequestType
或NotificationType
并添加void 作为注册选项类型。请记住在客户端和服务器端都更新此内容: // Old
export namespace MyRequest {
export const type : RequestType < MyParams , MyResult , void > = { get method ( ) { return 'myRequest' ; } } ;
}
export namespace MyNotification {
export const type : NotificationType < MyParams > = { get method ( ) { return 'myNotification' ; } } ;
}
// New
export namespace MyRequest {
export const type = new RequestType < MyParams , MyResult , void , void > ( 'myRequest' ) ;
}
export namespace MyNotification {
export const type = new NotificationType < MyParams , void > ( 'myNotification' ) ;
}
LanguageClientOptions.errorHandler
)。默认策略是重新启动服务器,除非最近 3 分钟内崩溃了 5 次或以上。麻省理工学院