This PR exposes context server settings to extensions.
Extensions can use `ContextServerSettings::for_project` to get the
context server settings for the current project.
The `experimental.context_servers` setting has been removed and replaced
with the `context_servers` setting (which is now an object instead of an
array).
Release Notes:
- N/A
---------
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This PR adds support for context servers provided by extensions.
To provide a context server from an extension, you need to list the
context servers in your `extension.toml`:
```toml
[context_servers.my-context-server]
```
And then implement the `context_server_command` method to return the
command that will be used to start the context server:
```rs
use zed_extension_api::{self as zed, Command, ContextServerId, Result};
struct ExampleContextServerExtension;
impl zed::Extension for ExampleContextServerExtension {
fn new() -> Self {
ExampleContextServerExtension
}
fn context_server_command(&mut self, _context_server_id: &ContextServerId) -> Result<Command> {
Ok(Command {
command: "node".to_string(),
args: vec!["/path/to/example-context-server/index.js".to_string()],
env: Vec::new(),
})
}
}
zed::register_extension!(ExampleContextServerExtension);
```
Release Notes:
- N/A
This PR makes `zed_extension_api` use the WIT types from v0.2.0 of
extension API.
A follow-up from #17795, since I had forgotten to do it there.
Release Notes:
- N/A
This PR forks a new version of the `zed_extension_api` in preparation
for new changes.
Release Notes:
- N/A
---------
Co-authored-by: Max <max@zed.dev>
This PR starts a list of pending changes for the Zed extension API.
We'll want to keep this list updated as we note things that we want to
change in the next version of the extension API. This will help with
batching breaking changes together so that we're not constantly creating
new versions of the extension API for one-off changes.
Release Notes:
- N/A
* renames `/tabs` to `/tab`
* allows to insert multiple tabs when fuzzy matching by the names
* improve slash command completion API, introduce a notion of multiple
arguments
* properly fire off commands on arguments' completions with
`run_command: true`
Release Notes:
- N/A
---------
Co-authored-by: Marshall Bowers <marshall@zed.dev>
This PR adds an `HttpRequestBuilder` to the extension API to allow for a
more ergonomic way for constructing HTTP requests within extensions.
The HTTP client functionality is now also exposed via the
`zed_extension_api::http_client` module instead of top-level.
Release Notes:
- N/A
This PR changes v0.0.7 of the extension API to v0.1.0.
We had a false-start in releasing v0.0.7, which has since been yanked,
so we need a new version number. We'll publish v0.1.0 to crates.io once
the Preview build is out tomorrow.
We're incrementing the minor version so that we have some leeway in
putting out patch releases of the crate within a given extension API
release.
Release Notes:
- N/A
# HTTP Client Improvements for Extension API
This PR enhances the HTTP client functionality in the Zed extension API,
providing more control over requests and allowing for streaming
responses.
## Key Changes
1. Extended `HttpRequest` struct:
- Added `method` field to specify HTTP method
- Added `headers` field for custom headers
- Added optional `body` field for request payload
2. Introduced `HttpMethod` enum for supported HTTP methods
3. Updated `HttpResponse` struct:
- Added `headers` field to access response headers
- Changed `body` type from `String` to `Vec<u8>` for binary data support
4. Added streaming support:
- New `fetch_stream` function to get a response stream
- Introduced `HttpResponseStream` resource for chunked reading
5. Updated internal implementations to support these new features
6. Modified the Gleam extension to use the new API structure
## Motivation
These changes provide extension developers with more flexibility and
control over HTTP requests. The streaming support is particularly useful
for handling large responses efficiently or ideally streaming into the
UI.
## Testing
- [x] Updated existing tests
- [ ] Added new tests for streaming functionality
## Next Steps
- Consider adding more comprehensive examples in the documentation
- Evaluate performance impact of streaming for large responses
Please review and let me know if any adjustments are needed.
Release Notes:
- N/A
---------
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This PR updates the extension API to make the `worktree` argument to
`run_slash_command` optional.
We may not always have a worktree, and not all slash commands need them,
so by making it optional we can allow individual slash commands to
decide what to do when there is no worktree.
Release Notes:
- N/A
This PR updates the extension API to use structured slash command
completions instead of plain strings.
This allows slash commands defined in extensions to take advantage of
the improvements made in #13876.
Release Notes:
- N/A
This PR adds a new `fetch` function to the `zed_extension_api` to allow
fetching a URL through the Wasm host.
Currently we only support GET requests and return the response body as a
string.
Release Notes:
- N/A
This PR extends the interface for slash commands defined in extensions
to have them return `SlashCommandOutput`.
This allows for slash commands to return multiple output sections for a
single piece of generated text.
Note that we don't allow specifying the icon to display in the
placeholder, as we don't want to commit to that in our API at the
moment.
Release Notes:
- N/A
This PR adds a default implementation for the `language_server_command`
method on the `Extension` trait.
This will allow for extensions to be defined without having to implement
this method, which will be useful for extensions that may just want to
provide slash commands.
Release Notes:
- N/A
This PR adds a temporary block on publishing v0.0.7 of the
`zed_extension_api`.
We have breaking changes to the extension API that are currently staged
on `main` and are still being iterated on, so we don't want to publish
again until we're ready to commit to the new API.
This change is intended to prevent accidental publishing of the crate
before we're ready.
Release Notes:
- N/A
- Confirming a completion now runs the command immediately
- Hitting `enter` on a line with a command now runs it
- The output of commands gets folded away and replaced with a custom
placeholder
- Eliminated ambient context
<img width="1588" alt="image"
src="https://github.com/zed-industries/zed/assets/482957/b1927a45-52d6-4634-acc9-2ee539c1d89a">
Release Notes:
- N/A
---------
Co-authored-by: Nathan Sobo <nathan@zed.dev>
This PR adds initial support for defining slash commands for the
Assistant from extensions.
Slash commands are defined in an extension's `extension.toml`:
```toml
[slash_commands.gleam-project]
description = "Returns information about the current Gleam project."
requires_argument = false
```
and then executed via the `run_slash_command` method on the `Extension`
trait:
```rs
impl Extension for GleamExtension {
// ...
fn run_slash_command(
&self,
command: SlashCommand,
_argument: Option<String>,
worktree: &zed::Worktree,
) -> Result<Option<String>, String> {
match command.name.as_str() {
"gleam-project" => Ok(Some("Yayyy".to_string())),
command => Err(format!("unknown slash command: \"{command}\"")),
}
}
}
```
Release Notes:
- N/A
This PR adds a new `github_release_by_tag_name` method to the
`zed_extension_api` to allow for retrieving a GitHub release by its tag
name.
Release Notes:
- N/A
This PR forks a new version of the `zed_extension_api` in preparation
for some upcoming changes that require breaking changes to the WIT.
Release Notes:
- N/A
---------
Co-authored-by: Max <max@zed.dev>
Improves documentation for `CodeLabel.filter_range` in
`zed_extension_api` by clarifying that it's a range of only the text
displayed in the label, *not* the `code` field.
Release Notes:
- N/A
This PR updates the README of the `zed_extension_api` crate to show the
compatibility between different versions of `zed_extension_api` and Zed.
Release Notes:
- N/A
This PR adds the ability for extensions to implement
`language_server_workspace_configuration` to provide workspace
configuration to the language server.
We've used the Dart extension as a motivating example for this, pulling
it out into an extension in the process.
Release Notes:
- Removed built-in support for Dart, in favor of making it available as
an extension. The Dart extension will be suggested for download when you
open a `.dart` file.
---------
Co-authored-by: Max <max@zed.dev>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This PR adds more documentation for various constructs in the
`zed_extension_api` crate.
`wit_bindgen` is able to generate doc comments on the Rust constructs
using the the doc comments in the WIT files, so we're able to leverage
that for the majority of the constructs that we expose.
Release Notes:
- N/A
This PR adds `label_for_symbol` to the extension API.
As a motivating example, we implemented `label_for_symbol` for the
Haskell extension.
Release Notes:
- N/A
Co-authored-by: Max <max@zed.dev>
This PR adds the ability for extensions to implement
`label_for_completion` to customize completions coming back from the
language server.
We've used the Gleam extension as a motivating example, adding
`label_for_completion` support to it.
Release Notes:
- N/A
---------
Co-authored-by: Max <max@zed.dev>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This PR adds a new function, `make-file-executable`, to the Zed
extension API that can be used to mark a given file as executable
(typically the language server binary).
This is available in v0.0.5 of the `zed_extension_api` crate.
We also reworked how we represent the various WIT versions on disk to
make it a bit clearer what the version number entails.
Release Notes:
- N/A
---------
Co-authored-by: Max <max@zed.dev>
We're doing it. Svelte support is moving into an extension. This PR
fixes some issues that came up along the way.
Notes
* extensions need to be able to retrieve the path the `node` binary
installed by Zed
* previously we were silently swallowing any errors that occurred while
loading a grammar
* npm commands ran by extensions weren't run in the right directory
* Tree-sitter's WASM stdlib didn't support a C function (`strncmp`)
needed by the Svelte parser's external scanner
* the way that LSP installation status was reported was unnecessarily
complex
Release Notes:
- Removed built-in support for the Svelte and Gleam languages, because
full support for those languages is now available via extensions. These
extensions will be suggested for download when you open a `.svelte` or
`.gleam` file.
---------
Co-authored-by: Marshall <marshall@zed.dev>
Our goal is to extract Svelte support into an extension, since we've
seen problems with the Tree-sitter Svelte parser crashing due to bugs in
the external scanner. In order to do this, we need a couple more
capabilities in LSP extensions:
* [x] `initialization_options` - programmatically controlling the JSON
initialization params sent to the language server
* [x] `prettier_plugins` - statically specifying a list of prettier
plugins that apply for a given language.
* [x] `npm_install_package`
Release Notes:
- N/A
---------
Co-authored-by: Marshall <marshall@zed.dev>
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
In this PR, we've added two new methods that LSP extensions can call:
* `shell_env()`, for retrieving the environment variables set in the
user's default shell in the worktree
* `which(command)`, for looking up paths to an executable (accounting
for the user's shell env in the worktree)
To test this out, we moved the `uiua` language support into an
extension. We went ahead and removed the built-in support, since this
language is extremely obscure. Sorry @mikayla-maki. To continue coding
in Uiua in Zed, for now you can `Add Dev Extension` from the extensions
pane, and select the `extensions/uiua` directory in the Zed repo. Very
soon, we'll support publishing these extensions so that you'll be able
to just install it normally.
Release Notes:
- N/A
---------
Co-authored-by: Marshall <marshall@zed.dev>
This PR provides WASM extensions with write access to their own specific
working directory under the Zed `extensions` dir. This directory is set
as the extensions `current_dir` when they run. Extensions can return
relative paths from the `Extension::language_server_command` method, and
those relative paths will be interpreted relative to this working dir.
With this functionality, most language servers that we currently build
into zed can be installed using extensions.
Release Notes:
- N/A
This PR moves the Clippy configuration up to the workspace level.
We're using the [`lints`
table](https://doc.rust-lang.org/cargo/reference/workspaces.html#the-lints-table)
to configure the Clippy ruleset in the workspace's `Cargo.toml`.
Each crate in the workspace now has the following in their own
`Cargo.toml` to inherit the lints from the workspace:
```toml
[lints]
workspace = true
```
This allows for configuring rust-analyzer to show Clippy lints in the
editor by using the following configuration in your Zed `settings.json`:
```json
{
"lsp": {
"rust-analyzer": {
"initialization_options": {
"check": {
"command": "clippy"
}
}
}
}
```
Release Notes:
- N/A
This PR adds **internal** ability to run arbitrary language servers via
WebAssembly extensions. The functionality isn't exposed yet - we're just
landing this in this early state because there have been a lot of
changes to the `LspAdapter` trait, and other language server logic.
## Next steps
* Currently, wasm extensions can only define how to *install* and run a
language server, they can't yet implement the other LSP adapter methods,
such as formatting completion labels and workspace symbols.
* We don't have an automatic way to install or develop these types of
extensions
* We don't have a way to package these types of extensions in our
extensions repo, to make them available via our extensions API.
* The Rust extension API crate, `zed-extension-api` has not yet been
published to crates.io, because we still consider the API a work in
progress.
Release Notes:
- N/A
---------
Co-authored-by: Marshall <marshall@zed.dev>
Co-authored-by: Nathan <nathan@zed.dev>
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>