Workspace folders
Workspace folders 请求
从版本 3.6.0 开始
许多工具支持每个工作区使用多个根文件夹。例如,VS Code 的多根支持、Atom 的项目文件夹支持或 Sublime 的项目支持。如果客户端工作区由多个根组成,则服务器通常需要了解这一点。到目前为止,该协议假定一个根文件夹,该文件夹由 InitializeParams
的 rootUri
属性向服务器宣布。如果客户端支持工作区文件夹,并通过相应的 workspaceFolders
客户端功能宣布它们,则 InitializeParams
在服务器启动时包含一个附加属性 workspaceFolders
,其中包含配置的工作区文件夹。
请求从服务器发送到客户端,以获取当前打开的工作区文件夹列表。如果在工具中仅打开单个文件,则在响应中返回 null
。如果工作区处于打开状态但未配置文件夹,则返回空数组。
客户端能力(Client capability):
- 属性路径:
workspace.workspaceFolders
- 属性类型:
boolean
服务端能力(Server capability):
- 属性路径:
workspace.workspaceFolders
- 属性类型:
WorkspaceFoldersServerCapabilities
, 定义如下:
export interface WorkspaceFoldersServerCapabilities {
/**
* The server has support for workspace folders
*/
supported?: boolean;
/**
* Whether the server wants to receive workspace folder
* change notifications.
*
* If a string is provided, the string is treated as an ID
* under which the notification is registered on the client
* side. The ID can be used to unregister for these events
* using the `client/unregisterCapability` request.
*/
changeNotifications?: string | boolean;
}
请求(Request):
- method: "workspace/workspaceFolders"
- params: none
响应(Response):
- result:
WorkspaceFolder[] | null
, 定义如下:
export interface WorkspaceFolder {
/**
* The associated URI for this workspace folder.
*/
uri: URI;
/**
* The name of the workspace folder. Used to refer to this
* workspace folder in the user interface.
*/
name: string;
}
- error:
code
和message
,以防在请求期间发生异常。
DidChangeWorkspaceFolders 通知
从版本 3.6.0 开始
workspace/didChangeWorkspaceFolders
通知从客户端发送到服务器,以通知服务器有关工作区文件夹配置更改的信息。
服务端能力(Server capability):
- 属性路径:
workspace.workspaceFolders.changeNotifications
- 属性类型:
string | boolean
, 如果提供了字符串,则该字符串将被视为在客户端注册通知的 ID。该 ID 可用于通过client/unregisterCapability
请求取消注册这些事件。
注册选项(Registration Options): undefined
通知(Notification):
- method: "workspace/didChangeWorkspaceFolders"
- params:
DidChangeWorkspaceFoldersParams
, 定义如下:
export interface DidChangeWorkspaceFoldersParams {
/**
* The actual workspace folder change event.
*/
event: WorkspaceFoldersChangeEvent;
}
/**
* The workspace folder change event.
*/
export interface WorkspaceFoldersChangeEvent {
/**
* The array of added workspace folders
*/
added: WorkspaceFolder[];
/**
* The array of the removed workspace folders
*/
removed: WorkspaceFolder[];
}