extension.wit

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