You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
插件后端通过插件函数协议读取打开的文档和选区、做版本化编辑、打开和定位文件、打开 HTML 预览或外部浏览器,并在编辑器里注册自己的动作和语言功能 Provider(定义、悬浮、补全等),还能把没有对应文件的文档(例如反编译出的库类源码)按 URI scheme 交给宿主打开。这些都是宿主方法,由 Rust Core 按权限校验、宿主执行;插件不直接操作编辑器。
Through the plugin-function protocol, a plugin backend reads open documents and selections, applies versioned edits, opens and reveals files, opens an HTML preview or an external browser, and registers its own editor actions and language-feature providers (definition, hover, completion, and so on). It can also serve documents that have no file (such as the decompiled source of a library class) to the host as a URI scheme. These are host methods: Rust Core checks permissions and the host executes them. The plugin never drives the editor directly.
Item
Value
Manifest field
None of its own; use backend with the permissions below
Checks the document version; refused during IME composition and on read-only documents; one batch is one undo step
editor/open, editor/reveal
editor.open
API-15
Returns documentID and version; a range only places the caret at its start
preview/openHTML
preview.open
API-16
editorAndPreview or previewOnly
browser/openExternal
browser.open
API-16
An HTTP(S) URL or saved HTML
editor/registerActions
editor.actions + documents.read
API-27
Discover it with getCapabilities, then register per workspace context; actions bind ordinary functions and file scopes, independent of LSP, build, or run. An action can carry multiple icons, up to 4 alternatives, and a click result reveal; the host declares the usable icons in services.editor.options.actionIcons
editor/registerProviders
editor.providers + documents.read
API-25
Discover the method and services.editor.options.providerTypes with getCapabilities, then register per workspace context; binds the 7 types definition, hover, completion, codeLens, foldingRange, semanticTokens, and documentLink to ordinary functions, and a type outside providerTypes returns unsupportedOption; language-server results come first and plugin results only add to them; the host sets the budgets
Every method takes context: {contextID, generation}; except for documents/registerContentProvider, a remote workspace context returns plugin.host.authorityUnsupported. documents/registerContentProvider is described in the next section.
Editor actions and language-feature providers
Topic
Rule
Action shape
The backend's collection function returns {actions: [{id, range, title, icon, invoke}]}: positions are one-based UTF-16, ranges are half-open and cannot split a surrogate pair; at most 1000 actions and 1 MiB serialized, and a malformed answer is refused whole; actions on the same line share one menu
Icons
icon is a presentation token the host declares; an icon names a picture, not an operation: a test icon does not make the action a test, and the host never starts anything because of an icon
Collection and click
Collection is read-only, with no network request or business execution; an edit invalidates the old actions immediately and cancels older collection; a click makes the host validate document, context, session, and registration again. A click that runs or debugs code should use run/start and debug/start once getCapabilities lists them, so the run appears in the host's Run and Debug windows; see Debug adapters
Action validation
The shared Core command plugins.editorActions.decode; its request carries version (must be 0), kind (registration, actions, or invokeResult), and the host-declared icons and sourceBytes
Provider merging
Language-server results come first: hover sections and completion items follow the server's, definitions add plugin locations to the server's, code lenses, folding ranges, and links are added, and semantic tokens apply only to files whose language server has none; the merge is the Core command plugins.editorProviders.decode with kind: "mergeDefinitions", so every host merges alike
Budgets
Hover and completion 400 ms, definition 1500 ms, the rest 2000 ms; a late answer, or one for an older document version, is dropped without an error; a registration cannot set its own budget
A host without these methods
A host whose getCapabilities does not list editor/registerActions or editor/registerProviders presents no such feature, and the plugin keeps its own command and window entry points; a host that does not recognize the editor.actions or editor.providers permission refuses the package instead of granting it silently
Content providers (API-12)
A language server may hand out documents that have no file (such as the decompiled source of a library class). The plugin serves them as a URI scheme with documents/registerContentProvider, granted by documents.contentProvider (needs backend).
Method
Permission
API
Params
Result
documents/registerContentProvider
documents.contentProvider
API-12
{context, scheme, function}
{subscriptionID}
Registration only records the binding and never calls the backend; function must already be registered on the session. Withdraw it with the existing subscriptions/dispose.
scheme is 1 to 64 lowercase ASCII letters, digits, +, -, or ., and starts with a letter. The schemes the host or the platform resolves are refused: about, blob, data, file, ftp, http, https, javascript, lithe, mailto, untitled, ws, and wss. A malformed or reserved scheme, or a function that is not a function ID, returns plugin.host.invalidParams.
A scheme has one provider per workspace window; registering it again returns plugin.host.preconditionFailed.
When a document whose URI has that scheme is opened, the host calls the function through lithe/function/invoke with the workspace context and {uri}. The function answers a string, or {content: string}, of at most 1 MiB, and the document opens read-only. Any other answer, a failure, or a timeout (the host waits 30 seconds) shows the user an error and opens nothing.
The provider is the only source of the text: the host keeps no copy once the document closes and asks again when it is reopened. Ending the session or closing the context withdraws the provider.
Only documents.contentProvider grants this method; the aggregate service name documents and other grants do not, and return plugin.host.permissionDenied (-32010).
Host status
Host
Status
Lithe desktop
Declares backend. The methods a backend can call are whatever getCapabilities returns, which lists only methods the permissions allow and the host has registered a handler for. The desktop provides documents, editor reads and edits, open and reveal, browser/openExternal (HTTP and HTTPS only), content providers, editor actions, and language-feature providers; it does not provide preview/openHTML. The capability list is in the desktop source
Core cases for registrations and results: 6 registration cases (selector and type validation, unsupportedOption) and 11 result cases (result shapes for the 7 types, and dropped results)
Canonical requests and replies for editor/applyEdits and editor/registerActions, plus host failure codes such as versionConflict and readOnly; also the documents/registerContentProvider cases: it needs the documents.contentProvider grant, the aggregate documents name is not enough, reserved schemes, an uppercase or digit-first scheme, a malformed function name, and a missing context