Add label_for_completion
to extension API (#10175)
This PR adds the ability for extensions to implement `label_for_completion` to customize completions coming back from the language server. We've used the Gleam extension as a motivating example, adding `label_for_completion` support to it. Release Notes: - N/A --------- Co-authored-by: Max <max@zed.dev> Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
parent
0f1c2e6f2b
commit
d306b531c7
18 changed files with 1124 additions and 252 deletions
120
crates/extension_api/wit/since_v0.0.6/extension.wit
Normal file
120
crates/extension_api/wit/since_v0.0.6/extension.wit
Normal file
|
@ -0,0 +1,120 @@
|
|||
package zed:extension;
|
||||
|
||||
world extension {
|
||||
import lsp;
|
||||
|
||||
use lsp.{completion};
|
||||
|
||||
export init-extension: func();
|
||||
|
||||
record github-release {
|
||||
version: string,
|
||||
assets: list<github-release-asset>,
|
||||
}
|
||||
|
||||
record github-release-asset {
|
||||
name: string,
|
||||
download-url: string,
|
||||
}
|
||||
|
||||
record github-release-options {
|
||||
require-assets: bool,
|
||||
pre-release: bool,
|
||||
}
|
||||
|
||||
enum os {
|
||||
mac,
|
||||
linux,
|
||||
windows,
|
||||
}
|
||||
|
||||
enum architecture {
|
||||
aarch64,
|
||||
x86,
|
||||
x8664,
|
||||
}
|
||||
|
||||
enum downloaded-file-type {
|
||||
gzip,
|
||||
gzip-tar,
|
||||
zip,
|
||||
uncompressed,
|
||||
}
|
||||
|
||||
variant language-server-installation-status {
|
||||
none,
|
||||
downloading,
|
||||
checking-for-update,
|
||||
failed(string),
|
||||
}
|
||||
|
||||
/// Gets the current operating system and architecture
|
||||
import current-platform: func() -> tuple<os, architecture>;
|
||||
|
||||
/// Get the path to the node binary used by Zed.
|
||||
import node-binary-path: func() -> result<string, string>;
|
||||
|
||||
/// Gets the latest version of the given NPM package.
|
||||
import npm-package-latest-version: func(package-name: string) -> result<string, string>;
|
||||
|
||||
/// Returns the installed version of the given NPM package, if it exists.
|
||||
import npm-package-installed-version: func(package-name: string) -> result<option<string>, string>;
|
||||
|
||||
/// Installs the specified NPM package.
|
||||
import npm-install-package: func(package-name: string, version: string) -> result<_, string>;
|
||||
|
||||
/// Gets the latest release for the given GitHub repository.
|
||||
import latest-github-release: func(repo: string, options: github-release-options) -> result<github-release, string>;
|
||||
|
||||
/// Downloads a file from the given url, and saves it to the given path within the extension's
|
||||
/// working directory. Extracts the file according to the given file type.
|
||||
import download-file: func(url: string, file-path: string, file-type: downloaded-file-type) -> result<_, string>;
|
||||
|
||||
/// Makes the file at the given path executable.
|
||||
import make-file-executable: func(filepath: string) -> result<_, string>;
|
||||
|
||||
/// Updates the installation status for the given language server.
|
||||
import set-language-server-installation-status: func(language-server-name: string, status: language-server-installation-status);
|
||||
|
||||
type env-vars = list<tuple<string, string>>;
|
||||
|
||||
record command {
|
||||
command: string,
|
||||
args: list<string>,
|
||||
env: env-vars,
|
||||
}
|
||||
|
||||
resource worktree {
|
||||
read-text-file: func(path: string) -> result<string, string>;
|
||||
which: func(binary-name: string) -> option<string>;
|
||||
shell-env: func() -> env-vars;
|
||||
}
|
||||
|
||||
export language-server-command: func(language-server-id: string, worktree: borrow<worktree>) -> result<command, string>;
|
||||
export language-server-initialization-options: func(language-server-id: string, worktree: borrow<worktree>) -> result<option<string>, string>;
|
||||
|
||||
record code-label {
|
||||
/// The source code to parse with Tree-sitter.
|
||||
code: string,
|
||||
spans: list<code-label-span>,
|
||||
filter-range: range,
|
||||
}
|
||||
|
||||
variant code-label-span {
|
||||
/// A range into the parsed code.
|
||||
code-range(range),
|
||||
literal(code-label-span-literal),
|
||||
}
|
||||
|
||||
record code-label-span-literal {
|
||||
text: string,
|
||||
highlight-name: option<string>,
|
||||
}
|
||||
|
||||
record range {
|
||||
start: u32,
|
||||
end: u32,
|
||||
}
|
||||
|
||||
export labels-for-completions: func(language-server-id: string, completions: list<completion>) -> result<list<option<code-label>>, string>;
|
||||
}
|
44
crates/extension_api/wit/since_v0.0.6/lsp.wit
Normal file
44
crates/extension_api/wit/since_v0.0.6/lsp.wit
Normal file
|
@ -0,0 +1,44 @@
|
|||
interface lsp {
|
||||
/// An LSP completion.
|
||||
record completion {
|
||||
label: string,
|
||||
detail: option<string>,
|
||||
kind: option<completion-kind>,
|
||||
insert-text-format: option<insert-text-format>,
|
||||
}
|
||||
|
||||
variant completion-kind {
|
||||
text,
|
||||
method,
|
||||
function,
|
||||
%constructor,
|
||||
field,
|
||||
variable,
|
||||
class,
|
||||
%interface,
|
||||
module,
|
||||
property,
|
||||
unit,
|
||||
value,
|
||||
%enum,
|
||||
keyword,
|
||||
snippet,
|
||||
color,
|
||||
file,
|
||||
reference,
|
||||
folder,
|
||||
enum-member,
|
||||
constant,
|
||||
struct,
|
||||
event,
|
||||
operator,
|
||||
type-parameter,
|
||||
other(s32),
|
||||
}
|
||||
|
||||
variant insert-text-format {
|
||||
plain-text,
|
||||
snippet,
|
||||
other(s32),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue