-
-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(grit): add auto-wrap + integrate with search
command
#3288
Conversation
search
command
CodSpeed Performance ReportMerging #3288 will degrade performances by 7.88%Comparing Summary
Benchmarks breakdown
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! We are almost here :)
I believe there's some work to be done around diagnostics and the usage of anyhow
. Not sure when they should be addressed, but really should at some point. Other than that, I just left few nitpicks.
|
||
for f in new_files { | ||
let Some(file) = f.get_file() else { | ||
bail!("Expected a list of files") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally, we don't use anyhow
, so I wonder if you plan to change this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to, but it would require updating the Grit libraries too. I agree it's less than ideal now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is a fix that we should follow up upstream. anyhow
isn't meant for libraries but for applications, so I suppose we can open an issue.
let name: PathBuf = file | ||
.name(&state.files) | ||
.text(&state.files, &self.lang) | ||
.unwrap() | ||
.as_ref() | ||
.into(); | ||
let body = file | ||
.body(&state.files) | ||
.text(&state.files, &self.lang) | ||
.unwrap(); | ||
let owned_file = | ||
new_file_owner(name.clone(), &body, &self.lang, logs)?.ok_or_else(|| { | ||
anyhow!( | ||
"failed to construct new file for file {}", | ||
name.to_string_lossy() | ||
) | ||
})?; | ||
self.files().push(owned_file); | ||
let _ = state.files.push_new_file(self.files().last().unwrap()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you replace the unwrap
with a safer alternative or provide a // SAFETY
comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 240455b.
match error.diagnostics.first() { | ||
Some(diag) => { | ||
fmt.write_str(": ")?; | ||
diag.message(fmt) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach may not be correct. We are basically truncating diagnostics. I think we should revisit this part.
Also, diagnostics
are marked as vector of SerializableDiagnostic
, but they should not, theoretically. We want to use serialisable diagnostics only in particular cases; for example, we want to cross thread boundaries inside the workspace.
This means, the transformation must happen at the workspace level, like in this case:
biome/crates/biome_service/src/workspace/server.rs
Lines 633 to 635 in f663e6b
.map(|diag| { | |
let diag = diag.with_file_path(params.path.as_path().display().to_string()); | |
SerdeDiagnostic::new(diag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed the part about SerializableDiagnostic
in dcfb43d. I'll try to revisit the diagnostics further indeed, though I hope to push that to a follow-up PR. There's some even worse feedback issues still too 😅
@@ -341,6 +343,30 @@ pub enum SearchError { | |||
)] | |||
pub struct InvalidPattern; | |||
|
|||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct QueryError(pub String); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: QueryDiagnostic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 240455b.
fn verbose_advices(&self, visitor: &mut dyn Visit) -> std::io::Result<()> { | ||
visitor.record_log( | ||
LogCategory::Info, | ||
&markup! { "For reference, please consult: https://docs.grit.io/language/syntax" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use <Hyperlink href="">please consult the official grit syntax page.</Hyperlink>
to create a clickable link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 240455b.
fn message(&self, fmt: &mut biome_console::fmt::Formatter<'_>) -> std::io::Result<()> { | ||
fmt.write_markup(markup! { "Error executing the Grit query: "{{&self.0}} }) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this diagnostic is inside the service, it will likely be used by other clients, too, e.g., LSP. Hence, we should implement description
, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 240455b.
&BiomePath, | ||
&DocumentFileSource, | ||
AnyParse, | ||
&GritQuery, | ||
WorkspaceSettingsHandle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Considering the great number of arguments, we could evaluate a struct
instead
@@ -584,6 +601,34 @@ pub(crate) fn parse_lang_from_script_opening_tag(script_opening_tag: &str) -> La | |||
.map_or(Language::JavaScript, |lang| lang) | |||
} | |||
|
|||
pub(crate) fn search_file( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would call it search
, without the use of file
. While it feels correct now, it won't be once this feature will be wired to additional clients.
It will be inline with the format capabilities. I suppose we will have search_range
too in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 240455b.
@@ -851,3 +847,9 @@ impl Workspace for WorkspaceServer { | |||
fn is_dir(path: &Path) -> bool { | |||
path.is_dir() || (path.is_symlink() && fs::read_link(path).is_ok_and(|path| path.is_dir())) | |||
} | |||
|
|||
fn make_search_pattern_id() -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For searching, the workspace protocol is split into three functions: parse_pattern()
, search_pattern()
, and drop_pattern()
. The reason for this is that we only need to parse once, and all workers can search using the pattern by referencing a handle instead of parsing again. This function generates the IDs for these "handles".
Summary
This implements the first iteration of the
biome search
command:Changes in this PR:
SearchCapabilities
to our file features system.Note that diagnostics are still rough in some places, and plenty of features are still unsupported.
Test Plan
Tested manually.