extension.wit

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