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