Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: biomejs/biome-zed
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.4
Choose a base ref
...
head repository: biomejs/biome-zed
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.1.3
Choose a head ref

Commits on Apr 18, 2024

  1. chore: add lock file

    ematipico committed Apr 18, 2024
    Copy the full SHA
    75c14dc View commit details
  2. ci: add CI to run on main branch (#8)

    ematipico authored Apr 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    37cf01b View commit details
  3. chore: update README.md

    ematipico committed Apr 18, 2024
    Copy the full SHA
    83e7ed7 View commit details
  4. fix: format files, again

    ematipico committed Apr 18, 2024
    Copy the full SHA
    d3c031a View commit details
  5. chore: include logo in the README.md

    ematipico committed Apr 18, 2024
    Copy the full SHA
    3165b53 View commit details

Commits on Apr 20, 2024

  1. Use the LSP from workspace (#9)

    * Use local LSP first
    
    * Check LSP cached path
    
    * Remove server path caching
    
    * Flip condition
    
    * Workaround local server check
    
    * Fixed typo
    
    * Cleanup code
    
    * Refactor
    
    * Check `package.json` instead
    chungweileong94 authored Apr 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    f526cb9 View commit details

Commits on Apr 22, 2024

  1. chore: Bump to 0.0.5

    ematipico committed Apr 22, 2024
    Copy the full SHA
    ff9aba1 View commit details
  2. chore: Bump to 0.0.6

    ematipico committed Apr 22, 2024
    Copy the full SHA
    f92da81 View commit details
  3. fix release workflow

    ematipico committed Apr 22, 2024
    Copy the full SHA
    3cb4cec View commit details

Commits on Jun 6, 2024

  1. feat: add support for the CSS language (#17)

    nhedger authored Jun 6, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3fe28d4 View commit details
  2. feat: use lsp settings to configure custom biome binary (#19)

    * feat: use lsp settings to configure custom biome binary
    
    * Add custom binary guide to contributing.md
    luckydye authored Jun 6, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b28e3c6 View commit details
  3. 0.0.7

    ematipico committed Jun 6, 2024
    Copy the full SHA
    0615437 View commit details

Commits on Jun 21, 2024

  1. ci: add workflow to lint PR title (#21)

    ematipico authored Jun 21, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a04d6ff View commit details

Commits on Jun 25, 2024

  1. feat: add support to configure --config-path through settings (#23)

    * feat: add support to configure `--config-path` through settings
    
    * chore: code cleanup
    
    * fix: dont unwrap
    
    * chore: update readme codeblocks to jsonc
    luckydye authored Jun 25, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    11bd5b2 View commit details

Commits on Jun 28, 2024

  1. chore: improve documentation around configuration issues (#25)

    luckydye authored Jun 28, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    f11f4d6 View commit details

Commits on Jul 17, 2024

  1. feat: add setting require_config_file (#29)

    * feat: add setting `require_config_file`
    
    * chore: fix formatting
    
    * feat: check biome.json and biome.jsonc
    luckydye authored Jul 17, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    f83ac71 View commit details

Commits on Jul 24, 2024

  1. feat: use native biome binary without node (#31)

    * feat: use native biome binary without node
    
    * chore: update formatter configuration in README
    
    * fix: error on unsupported architecture
    luckydye authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    be0e886 View commit details
  2. chore: bump to 0.1.0

    luckydye authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c28593c View commit details

Commits on Jul 26, 2024

  1. fix: biome installed with pnpm fails to start (#34)

    * fix: biome installed with pnpm fails to start
    
    * chore: remove test files
    
    * chore: fix lint
    luckydye authored Jul 26, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4fa04f0 View commit details

Commits on Aug 8, 2024

  1. chore: fix grammatical errors in docs (#38)

    tyleralbee authored Aug 8, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7fc20c9 View commit details

Commits on Sep 9, 2024

  1. fix: fallback biome won't install correctly (#45)

    * fix: fallback biome won't install correctly
    
    * chore: remove unused method
    luckydye authored Sep 9, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    f6b708d View commit details

Commits on Sep 18, 2024

  1. feat: add GraphQL support (#47)

    ematipico authored Sep 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5878de9 View commit details
Showing with 383 additions and 77 deletions.
  1. +57 −0 .github/workflows/lint-pr-title.yml
  2. +43 −0 .github/workflows/main.yml
  3. +4 −0 .gitignore
  4. +34 −1 CHANGELOG.md
  5. +18 −0 CONTRIBUTING.md
  6. +7 −7 Cargo.lock
  7. +1 −1 Cargo.toml
  8. +32 −18 README.md
  9. +19 −17 extension.toml
  10. +39 −0 knope.toml
  11. +129 −33 src/biome.rs
57 changes: 57 additions & 0 deletions .github/workflows/lint-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Lint Pull Request Titles"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Configure which types are allowed (newline-delimited).
# ref: biomejs/biome/CONTRIBUTING.md
types: |
build
chore
ci
docs
feat
fix
perf
refactor
release
revert
test
# Configure that a scope must always be provided.
requireScope: false
# Configure which scopes are disallowed in PR titles.
# These are regex patterns auto-wrapped in `^ $`.
#
# We disable the following scopes:
# - `release` because we have the `release` type
# - UPPERCASE titles because we promote the use of lowercase
disallowScopes: |
[A-Z]+
# Configure additional validation for the subject based on a regex.
# Ensures that the subject doesn't start with an uppercase character.
subjectPattern: ^[^A-Z].*$
# If `subjectPattern` is configured, you can use this property to override
# the default error message that is shown when the pattern doesn't match.
# The variables `subject` and `title` can be used within the message.
subjectPatternError: |
The subject "{subject}" found in the pull request title "{title}"
didn't match the configured pattern.
Please ensure that the subject doesn't start with an uppercase character.
The scope should not be in UPPERCASE.
43 changes: 43 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Jobs run on pull request
name: CI main
on:
workflow_dispatch:
push:
branches:
- main

env:
RUST_LOG: info
RUST_BACKTRACE: 1

jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Install toolchain
uses: moonrepo/setup-rust@b8edcc56aab474d90c7cf0bb8beeaf8334c15e9f # v1
with:
components: rustfmt
bins: taplo-cli
cache-base: main
- name: Run format
run: |
cargo fmt --all --check
taplo format --check
lint:
name: Lint Rust Files
runs-on: ubuntu-latest
steps:
- name: Checkout PR Branch
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Install toolchain
uses: moonrepo/setup-rust@b8edcc56aab474d90c7cf0bb8beeaf8334c15e9f # v1
with:
components: clippy
cache-base: main
- name: Run clippy
run: cargo clippy --all-targets -- --deny warnings
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
target
extension.wasm
node_modules
package-lock.json
pnpm-lock.yaml
package.json
35 changes: 34 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
# Changelog
# Changelog

## 0.1.1 (2024-07-25)

### Fixes

- biome installed with pnpm fails to start

## 0.1.0 (2024-07-24)

### Features

- use native biome binary without node (#31)
- add setting require_config_file (#29)
- add support to configure --config-path through settings (#23)

## 0.0.7 (2024-06-06)

### Features

- use lsp settings to configure custom biome binary (#19)
- add support for the CSS language (#17)

## 0.0.6 (2024-04-22)

### Fixes

- Fix broken release

## 0.0.5 (2024-04-22)

### Fixes

- The extesion should be able to read the binary from the node_modules

## 0.0.4 (2024-04-18)

18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -33,6 +33,24 @@ just install-tools

If you make changes to the Rust code and you require to reload the extension, you can open the "Extensions" tab by running the command `zed: extensions`, choose the `"Installed"`, seek the current extension and click the `"Rebuild"` label.

### Custom biome binary

The binary used by the extension can be overriden in Zed settings.json using the `lsp` key:

```jsonc
// settings.json
{
"lsp": {
"biome": {
"binary": {
"path": "<path_to_biome_binary>",
"arguments": ["lsp-proxy"]
}
}
}
}
```

#### Logs

Zed will print logs in the following directory: `~/Library/Logs/Zed/Zed.log`
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ edition = "2021"
license = "MIT"
name = "zed_biome"
publish = false
version = "0.0.4"
version = "0.1.2"

[lib]
crate-type = ["cdylib"]
50 changes: 32 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
# Biome - Zed
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/biomejs/resources/main/svg/slogan-dark-transparent.svg">
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/biomejs/resources/main/svg/slogan-light-transparent.svg">
<img alt="Shows the banner of Biome, with its logo and the phrase 'Biome - Toolchain of the web'." src="https://raw.githubusercontent.com/biomejs/resources/main/svg/slogan-light-transparent.svg" width="700">
</picture>
</p>

<div align="center">

[![CI main](https://github.com/biomejs/biome-zed/actions/workflows/main.yml/badge.svg)](https://github.com/biomejs/biome-zed/actions/workflows/main.yml)

</div>

# Biome extension for Zed

This extension adds support for [Biome](https://github.com/biomejs/biome) in [Zed](https://zed.dev/).

Currently supports **JavaScript**, **TypeScript**, **TSX**, **Vue.js**, **Astro** and **Svelte** files.
Languages currently supported:

- **JavaScript**
- **TypeScript**
- **JSX**
- **TSX**
- **JSON**
- **JSONC**
- **Vue.js**
- **Astro**
- **Svelte**
- **CSS**
- **GraphQL**

## Installtion
## Installation

Requires Zed >= **v0.131.0**.

This extension is available in the extensions view inside the Zed editor. Open `zed: extensions` and search for _Biome_.

## Configuration

Example configurations in zed `settings.json`.

```jsonc
// settings.json
{
"format_on_save": "on",
"code_actions_on_format": {
"source.fixAll": true,
"source.organizeImports.biome": true
},
"formatter": "language_server"
}
```
## Documentation

Head to the [official documentation](https://biomejs.dev/reference/zed) to learn how to set up the extension, and customize it.
36 changes: 19 additions & 17 deletions extension.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
authors = ["biomejs <biomejs.dev>"]
description = "Biome support for Zed"
id = "biome"
name = "Biome"
repository = "https://github.com/biomejs/biome-zed"
authors = ["biomejs <biomejs.dev>"]
description = "Biome support for Zed"
id = "biome"
name = "Biome"
repository = "https://github.com/biomejs/biome-zed"
schema_version = 1
version = "0.0.4"
version = "0.1.3"

[language_servers.biome]
code_actions_kind = ["", "quickfix"]
language = "JavaScript"
languages = ["JavaScript", "JSX", "TypeScript", "TSX", "Vue.js", "Astro", "Svelte", "JSON", "JSONC"]
name = "Biome Language Server"
code_actions_kind = ["quickfix"]
language = "JavaScript"
languages = ["JavaScript", "JSX", "TypeScript", "TSX", "Vue.js", "Astro", "Svelte", "JSON", "JSONC", "CSS", "GraphQL"]
name = "Biome Language Server"

[language_servers.biome.language_ids]
"Astro" = "astro"
"JSON" = "json"
"JSONC" = "jsonc"
"JSX" = "javascriptreact"
"Astro" = "astro"
"CSS" = "css"
"GraphQL" = "graphql"
"JSON" = "json"
"JSONC" = "jsonc"
"JSX" = "javascriptreact"
"JavaScript" = "javascript"
"Svelte" = "svelte"
"TSX" = "typescriptreact"
"Svelte" = "svelte"
"TSX" = "typescriptreact"
"TypeScript" = "typescript"
"Vue.js" = "vuejs"
"Vue.js" = "vuejs"
39 changes: 39 additions & 0 deletions knope.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
[package]
changelog = "CHANGELOG.md"
versioned_files = ["Cargo.toml"]

[[workflows]]
name = "document-change"


[[workflows.steps]]
type = "CreateChangeFile"

[[workflows]]
name = "release"

[[workflows.steps]]
type = "PrepareRelease"
ignore_conventional_commits = true

[[workflows.steps]]
type = "Command"
shell = true
command = "cargo c && git add -A"

# Commit the changes that PrepareRelease added
[[workflows.steps]]
type = "Command"
command = "git commit -m \"chore: Bump to version\""
variables = {"version" = "Version"}

# Push the commit and the new tag to our remote repository.
[[workflows.steps]]
type = "Command"
command = "git push"


# Create a GitHub release for each package.
[[workflows.steps]]
type = "Release"

[[workflows.steps]]
type = "Command"
command = "git push --tags"
162 changes: 129 additions & 33 deletions src/biome.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,81 @@
use std::{env, fs};
use zed_extension_api::{self as zed, LanguageServerId, Result};
use std::{
env, fs,
path::{Path, PathBuf},
};
use zed::settings::LspSettings;
use zed_extension_api::{
self as zed,
serde_json::{self, Value},
LanguageServerId, Result,
};

const SERVER_PATH: &str = "node_modules/.bin/biome";
const SERVER_PATH: &str = "node_modules/@biomejs/biome/bin/biome";
const PACKAGE_NAME: &str = "@biomejs/biome";

struct BiomeExtension {
did_find_server: bool,
}
const BIOME_CONFIG_PATHS: &[&str] = &["biome.json", "biome.jsonc"];

struct BiomeExtension;

impl BiomeExtension {
fn server_exists(&self) -> bool {
fs::metadata(SERVER_PATH).map_or(false, |stat| stat.is_file())
fn server_exists(&self, path: &PathBuf) -> bool {
fs::metadata(path).map_or(false, |stat| stat.is_file())
}

fn binary_specifier(&self) -> Result<String> {
let (platform, arch) = zed::current_platform();

Ok(format!(
"@biomejs/cli-{platform}-{arch}/biome",
platform = match platform {
zed::Os::Mac => "darwin",
zed::Os::Linux => "linux",
zed::Os::Windows => "win32",
},
arch = match arch {
zed::Architecture::Aarch64 => "arm64",
zed::Architecture::X8664 => "x64",
_ => return Err(format!("unsupported architecture: {arch:?}")),
},
))
}

fn server_script_path(&mut self, language_server_id: &LanguageServerId) -> Result<String> {
let server_exists = self.server_exists();
if self.did_find_server && server_exists {
return Ok(SERVER_PATH.to_string());
fn server_script_path(
&mut self,
language_server_id: &LanguageServerId,
worktree: &zed::Worktree,
) -> Result<String> {
// This is a workaround, as reading the file from wasm doesn't work.
// Instead we try to read the `package.json`, see if `@biomejs/biome` is installed
let package_json = worktree
.read_text_file("package.json")
.unwrap_or(String::from(r#"{}"#));
let package_json: Option<serde_json::Value> = serde_json::from_str(package_json.as_str()).ok();

let server_package_exists = package_json.is_some_and(|f| {
!f["dependencies"][PACKAGE_NAME].is_null() || !f["devDependencies"][PACKAGE_NAME].is_null()
});

if server_package_exists {
let worktree_root_path = worktree.root_path();

return Ok(
Path::new(worktree_root_path.as_str())
.join(SERVER_PATH)
.to_string_lossy()
.to_string(),
);
}

// fallback to extension owned biome
zed::set_language_server_installation_status(
language_server_id,
&zed::LanguageServerInstallationStatus::CheckingForUpdate,
);

let fallback_server_path = &Path::new("./node_modules").join(self.binary_specifier()?);
let version = zed::npm_package_latest_version(PACKAGE_NAME)?;

if !server_exists
if !self.server_exists(fallback_server_path)
|| zed::npm_package_installed_version(PACKAGE_NAME)?.as_ref() != Some(&version)
{
zed::set_language_server_installation_status(
@@ -35,49 +85,95 @@ impl BiomeExtension {
let result = zed::npm_install_package(PACKAGE_NAME, &version);
match result {
Ok(()) => {
if !self.server_exists() {
if !self.server_exists(fallback_server_path) {
Err(format!(
"installed package '{PACKAGE_NAME}' did not contain expected path '{SERVER_PATH}'",
"installed package '{PACKAGE_NAME}' did not contain expected path '{fallback_server_path:?}'",
))?;
}
}
Err(error) => {
if !self.server_exists() {
Err(error)?;
if !self.server_exists(fallback_server_path) {
Err(format!(
"failed to install package '{PACKAGE_NAME}': {error}"
))?;
}
}
}
}

self.did_find_server = true;
Ok(SERVER_PATH.to_string())
Ok(fallback_server_path.to_string_lossy().to_string())
}

// Returns the path if a config file exists
pub fn config_path(&self, worktree: &zed::Worktree, settings: &Value) -> Option<String> {
let config_path_setting = settings.get("config_path").and_then(|value| value.as_str());

if let Some(config_path) = config_path_setting {
if worktree.read_text_file(config_path).is_ok() {
return Some(config_path.to_string());
} else {
return None;
}
}

for config_path in BIOME_CONFIG_PATHS {
if worktree.read_text_file(config_path).is_ok() {
return Some(config_path.to_string());
}
}

None
}
}

impl zed::Extension for BiomeExtension {
fn new() -> Self {
Self {
did_find_server: false,
}
Self
}

fn language_server_command(
&mut self,
language_server_id: &LanguageServerId,
_worktree: &zed::Worktree,
worktree: &zed::Worktree,
) -> Result<zed::Command> {
let path = self.server_script_path(language_server_id)?;
let path = self.server_script_path(language_server_id, worktree)?;
let settings = LspSettings::for_worktree(language_server_id.as_ref(), worktree)?;

let mut args = vec!["lsp-proxy".to_string()];

if let Some(settings) = settings.settings {
let config_path = self.config_path(worktree, &settings);

let require_config_file = settings
.get("require_config_file")
.and_then(|value| value.as_bool())
.unwrap_or(false);

if let Some(config_path) = config_path {
args.push("--config-path".to_string());
args.push(config_path.clone());
} else if require_config_file {
return Err("biome.json is not found but require_config_file is true".to_string());
}
}

let bin = env::current_dir()
.unwrap()
.join(path)
.to_string_lossy()
.to_string();

if let Some(binary) = settings.binary {
return Ok(zed::Command {
command: binary.path.map_or(bin, |path| path),
args: binary.arguments.map_or(args, |args| args),
env: Default::default(),
});
}

Ok(zed::Command {
command: zed::node_binary_path()?,
args: vec![
env::current_dir()
.unwrap()
.join(path)
.to_string_lossy()
.to_string(),
"lsp-proxy".to_string(),
],
command: bin,
args,
env: Default::default(),
})
}