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