extension.wit

 1package zed:extension;
 2
 3world extension {
 4    use github.{github-release, github-release-options};
 5    use platform.{os, architecture};
 6
 7    export init-extension: func();
 8
 9    enum downloaded-file-type {
10        gzip,
11        gzip-tar,
12        zip,
13        uncompressed,
14    }
15
16    variant language-server-installation-status {
17        none,
18        downloading,
19        checking-for-update,
20        failed(string),
21    }
22
23    /// Gets the current operating system and architecture
24    import current-platform: func() -> tuple<os, architecture>;
25
26    /// Get the path to the node binary used by Zed.
27    import node-binary-path: func() -> result<string, string>;
28
29    /// Gets the latest version of the given NPM package.
30    import npm-package-latest-version: func(package-name: string) -> result<string, string>;
31
32    /// Returns the installed version of the given NPM package, if it exists.
33    import npm-package-installed-version: func(package-name: string) -> result<option<string>, string>;
34
35    /// Installs the specified NPM package.
36    import npm-install-package: func(package-name: string, version: string) -> result<_, string>;
37
38    /// Gets the latest release for the given GitHub repository.
39    import latest-github-release: func(repo: string, options: github-release-options) -> result<github-release, string>;
40
41    /// Downloads a file from the given url, and saves it to the given path within the extension's
42    /// working directory. Extracts the file according to the given file type.
43    import download-file: func(url: string, file-path: string, file-type: downloaded-file-type) -> result<_, string>;
44
45    /// Makes the file at the given path executable.
46    import make-file-executable: func(filepath: string) -> result<_, string>;
47
48    /// Updates the installation status for the given language server.
49    import set-language-server-installation-status: func(language-server-name: string, status: language-server-installation-status);
50
51    type env-vars = list<tuple<string, string>>;
52
53    record command {
54        command: string,
55        args: list<string>,
56        env: env-vars,
57    }
58
59    resource worktree {
60        read-text-file: func(path: string) -> result<string, string>;
61        which: func(binary-name: string) -> option<string>;
62        shell-env: func() -> env-vars;
63    }
64
65    record language-server-config {
66        name: string,
67        language-name: string,
68    }
69
70    export language-server-command: func(config: language-server-config, worktree: borrow<worktree>) -> result<command, string>;
71    export language-server-initialization-options: func(config: language-server-config, worktree: borrow<worktree>) -> result<option<string>, string>;
72}