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