Skip to content

Commit

Permalink
perf: upgrade Grit and remove im crate (#4232)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored Oct 10, 2024
1 parent 7c0832b commit 2e5e3f2
Show file tree
Hide file tree
Showing 26 changed files with 433 additions and 328 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- The `--summary` reporter now reports parsing diagnostics too. Contributed by @ematipico

- Improved performance of GritQL queries by roughly 25-30%. Contributed by @arendjr

### Configuration

#### Bug fixes
Expand Down
61 changes: 5 additions & 56 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions crates/biome_grit_patterns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ repository.workspace = true
version = "0.0.1"

[dependencies]
anyhow = { workspace = true }
biome_console = { workspace = true }
biome_diagnostics = { workspace = true }
biome_grit_parser = { workspace = true }
Expand All @@ -22,9 +21,8 @@ biome_js_syntax = { workspace = true }
biome_parser = { workspace = true }
biome_rowan = { workspace = true }
biome_string_case = { workspace = true }
grit-pattern-matcher = { version = "0.3" }
grit-util = { version = "0.3" }
im = { version = "15.1.0" }
grit-pattern-matcher = { version = "0.4" }
grit-util = { version = "0.4" }
path-absolutize = { version = "3.1.1", optional = false, features = ["use_unix_paths_on_wasm"] }
rand = { version = "0.8.5" }
regex = { workspace = true }
Expand Down
19 changes: 11 additions & 8 deletions crates/biome_grit_patterns/src/grit_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use crate::{
grit_context::GritQueryContext, grit_target_language::GritTargetLanguage,
grit_target_node::GritTargetNode, source_location_ext::SourceFileExt, util::TextRangeGritExt,
};
use anyhow::bail;
use biome_diagnostics::{display::SourceFile, SourceCode};
use biome_rowan::TextRange;
use grit_pattern_matcher::{
binding::Binding, constant::Constant, effects::Effect, pattern::FileRegistry,
};
use grit_util::{AnalysisLogBuilder, AnalysisLogs, AstNode, ByteRange, CodeRange, Range};
use grit_util::{
error::{GritPatternError, GritResult},
AnalysisLogBuilder, AnalysisLogs, AstNode, ByteRange, CodeRange, Range,
};
use std::{borrow::Cow, collections::HashMap, path::Path};

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -161,11 +163,11 @@ impl<'a> Binding<'a, GritQueryContext> for GritBinding<'a> {
_memo: &mut HashMap<grit_util::CodeRange, Option<String>>,
_distributed_indent: Option<usize>,
_logs: &mut AnalysisLogs,
) -> anyhow::Result<Cow<'a, str>> {
bail!("Not implemented") // TODO: Implement rewriting
) -> GritResult<Cow<'a, str>> {
Err(GritPatternError::new("Not implemented")) // TODO: Implement rewriting
}

fn text(&self, _language: &GritTargetLanguage) -> anyhow::Result<Cow<'a, str>> {
fn text(&self, _language: &GritTargetLanguage) -> GritResult<Cow<'a, str>> {
match self {
Self::File(path) => Ok(path.to_string_lossy()),
Self::Node(node) => Ok(node.text().into()),
Expand Down Expand Up @@ -249,9 +251,9 @@ impl<'a> Binding<'a, GritQueryContext> for GritBinding<'a> {
&self,
_language: &GritTargetLanguage,
logs: &mut grit_util::AnalysisLogs,
) -> anyhow::Result<()> {
) -> GritResult<()> {
if let Self::Empty(node, slot) = self {
let range = Range::from_byte_range(node.source(), node.byte_range());
let range = Range::from_byte_range(node.source(), &node.byte_range());
let log = AnalysisLogBuilder::default()
.level(441_u16)
.source(node.source())
Expand All @@ -261,7 +263,8 @@ impl<'a> Binding<'a, GritQueryContext> for GritBinding<'a> {
"Error: failed to rewrite binding, cannot derive range of empty slot {slot} of node with kind {:?}",
node.kind()
))
.build()?;
.build()
.map_err(|error| GritPatternError::Builder(error.to_string()))?;
logs.push(log);
}

Expand Down
Loading

0 comments on commit 2e5e3f2

Please sign in to comment.