1package zed:extension;
2
3world extension {
4 import github;
5 import http-client;
6 import platform;
7 import process;
8 import nodejs;
9
10 use common.{env-vars, range};
11 use lsp.{completion, symbol};
12 use process.{command};
13 use slash-command.{slash-command, slash-command-argument-completion, slash-command-output};
14
15 /// Initializes the extension.
16 export init-extension: func();
17
18 /// The type of a downloaded file.
19 enum downloaded-file-type {
20 /// A gzipped file (`.gz`).
21 gzip,
22 /// A gzipped tar archive (`.tar.gz`).
23 gzip-tar,
24 /// A ZIP file (`.zip`).
25 zip,
26 /// An uncompressed file.
27 uncompressed,
28 }
29
30 /// The installation status for a language server.
31 variant language-server-installation-status {
32 /// The language server has no installation status.
33 none,
34 /// The language server is being downloaded.
35 downloading,
36 /// The language server is checking for updates.
37 checking-for-update,
38 /// The language server installation failed for specified reason.
39 failed(string),
40 }
41
42 record settings-location {
43 worktree-id: u64,
44 path: string,
45 }
46
47 import get-settings: func(path: option<settings-location>, category: string, key: option<string>) -> result<string, string>;
48
49 /// Downloads a file from the given URL and saves it to the given path within the extension's
50 /// working directory.
51 ///
52 /// The file will be extracted according to the given file type.
53 import download-file: func(url: string, file-path: string, file-type: downloaded-file-type) -> result<_, string>;
54
55 /// Makes the file at the given path executable.
56 import make-file-executable: func(filepath: string) -> result<_, string>;
57
58 /// Updates the installation status for the given language server.
59 import set-language-server-installation-status: func(language-server-name: string, status: language-server-installation-status);
60
61 /// A Zed worktree.
62 resource worktree {
63 /// Returns the ID of the worktree.
64 id: func() -> u64;
65 /// Returns the root path of the worktree.
66 root-path: func() -> string;
67 /// Returns the textual contents of the specified file in the worktree.
68 read-text-file: func(path: string) -> result<string, string>;
69 /// Returns the path to the given binary name, if one is present on the `$PATH`.
70 which: func(binary-name: string) -> option<string>;
71 /// Returns the current shell environment.
72 shell-env: func() -> env-vars;
73 }
74
75 /// A Zed project.
76 resource project {
77 /// Returns the IDs of all of the worktrees in this project.
78 worktree-ids: func() -> list<u64>;
79 }
80
81 /// A key-value store.
82 resource key-value-store {
83 /// Inserts an entry under the specified key.
84 insert: func(key: string, value: string) -> result<_, string>;
85 }
86
87 /// Returns the command used to start up the language server.
88 export language-server-command: func(language-server-id: string, worktree: borrow<worktree>) -> result<command, string>;
89
90 /// Returns the initialization options to pass to the language server on startup.
91 ///
92 /// The initialization options are represented as a JSON string.
93 export language-server-initialization-options: func(language-server-id: string, worktree: borrow<worktree>) -> result<option<string>, string>;
94
95 /// Returns the workspace configuration options to pass to the language server.
96 export language-server-workspace-configuration: func(language-server-id: string, worktree: borrow<worktree>) -> result<option<string>, string>;
97
98 /// A label containing some code.
99 record code-label {
100 /// The source code to parse with Tree-sitter.
101 code: string,
102 /// The spans to display in the label.
103 spans: list<code-label-span>,
104 /// The range of the displayed label to include when filtering.
105 filter-range: range,
106 }
107
108 /// A span within a code label.
109 variant code-label-span {
110 /// A range into the parsed code.
111 code-range(range),
112 /// A span containing a code literal.
113 literal(code-label-span-literal),
114 }
115
116 /// A span containing a code literal.
117 record code-label-span-literal {
118 /// The literal text.
119 text: string,
120 /// The name of the highlight to use for this literal.
121 highlight-name: option<string>,
122 }
123
124 export labels-for-completions: func(language-server-id: string, completions: list<completion>) -> result<list<option<code-label>>, string>;
125 export labels-for-symbols: func(language-server-id: string, symbols: list<symbol>) -> result<list<option<code-label>>, string>;
126
127 /// Returns the completions that should be shown when completing the provided slash command with the given query.
128 export complete-slash-command-argument: func(command: slash-command, args: list<string>) -> result<list<slash-command-argument-completion>, string>;
129
130 /// Returns the output from running the provided slash command.
131 export run-slash-command: func(command: slash-command, args: list<string>, worktree: option<borrow<worktree>>) -> result<slash-command-output, string>;
132
133 /// Returns the command used to start up a context server.
134 export context-server-command: func(context-server-id: string, project: borrow<project>) -> result<command, string>;
135
136 /// Returns a list of packages as suggestions to be included in the `/docs`
137 /// search results.
138 ///
139 /// This can be used to provide completions for known packages (e.g., from the
140 /// local project or a registry) before a package has been indexed.
141 export suggest-docs-packages: func(provider-name: string) -> result<list<string>, string>;
142
143 /// Indexes the docs for the specified package.
144 export index-docs: func(provider-name: string, package-name: string, database: borrow<key-value-store>) -> result<_, string>;
145}