extension.wit

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