-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
feat(cli): support nested .gitignore
and better glob patterns support
#1134
Conversation
✅ Deploy Preview for biomejs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
804f1a9
to
1cccade
Compare
08b87d6
to
53e1df8
Compare
ignore
and globset
.gitignore
and better glob patter support
236d9f5
to
4487664
Compare
.gitignore
and better glob patter support.gitignore
and better glob patterns support
5a7b2f6
to
f2d9e8f
Compare
59b647a
to
105eac6
Compare
Does this have a performance impact? |
# pinning to version 1.18 to avoid multiple versions of windows-sys as dependency | ||
tokio = { version = "~1.18.5" } | ||
unicode-bom = "2.0.3" | ||
tokio = { version = "~1.18.5" } |
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.
The spacing before =
seems to be wrong
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.
Sorry I don't understand what you mean
@@ -128,6 +128,16 @@ pub(crate) fn process_file(ctx: &TraversalOptions, path: &Path) -> FileResult { | |||
category!("files/missingHandler"), | |||
)?; | |||
|
|||
// first we stop if there are some files that don't have ALL features enabled, e.g. images, fonts, etc. | |||
if file_features.is_ignored() || file_features.is_not_enabled() { |
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.
Do we use experimental Rust features in Biome? If yes, can we surround this with std::intrinsics::unlikely
?
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.
No, we don't use experimental features, and I don't think we plan for now (at least for stable releases)
acfb554
to
b2f1673
Compare
02cb641
to
288e62d
Compare
I had not the time to review the PR. Does this also add support for Also, we should certainly update our website documentation for which glob patterns we support (ref to gitignore docs?) and the fact that we support nested |
@Conaclos you can still leave your review, I will address your comments in another PR. |
No and yes (maybe we should add this to the changelog and documentation). |
@ematipico not sure if you want this as a separate issue, but I'm seeing issues with this in Biome My repo looks like so:
The
Biome incorrectly looks in
It seems like |
We reverted the support for nested git ignore files. After a bunch of testing, we realised that there were some issues in the crawling of the file system. We will implement the feature in a separate PR with a different logic. Also, FYI the result you're seeing seems expected, because the glob You should specify |
This is how Git handles there
I believe that this would be the equivalent to just doing Is the intent of your crawler to be compatible with how Git uses In that case I believe that some care needs to be taken to account for these edge cases. I'd be happy to lend some help since I've worked with this recently when creating a tool that converts Git ignore files to a Docker ignore file. I would also recommend to make it compatible with Git from the start, since otherwise it's easy to get stuck in a place where a change to Git's model is desired, but would be considered a breaking change. As seems to have happened to Docker 😅 |
That is another proof that I did well to remove the feature for the time being 😅
Yeah, that's the idea. The next release (your current nightly) should be compatible with git blogs inside
That would be awesome! I always appreciate help from people who are more expert than me! |
Summary
files.include
not working (at all) #1117This PR implements a bunch of changes to our file system crawling strategy and how we parse globs inside
ignore
andinclude
properties.File system crawling
In order to improve the file system crawling strategy, we decided to use the
ignore
crate. This was a big judgment call, but I think it's going to pay off in the long run.This crate depended on
regex-automata
, which is an engine to compile regexes. For some time we were trying to stay away from crates of this nature because they could slow down compiling times and runtime times, but I believe we should just include them and make sure that we carefully use them. E.g.:ignore
is well maintained, and it's used byripgrep
. This crate provides a bunch of functionalities out of the box, such as:.gitignore
supportoverrides
globsPlus, it would allow us to support glob patterns in the CLI, but this isn't implemented in this PR yet, because it requires some more work.
Technical changes
TraversalScope
calledtraverse_paths
, which is the first function to call when beginning the traversal. This function accepts all the paths we need to traverseos.rs
oftraverse_paths
is the function that usesignore
. We create aWalkerBuilder
to pass all the paths we need to traverse and all the overrides (this doesn't work well at the moment, because we don't pass absolute paths to the walker).can_track_error
function.
and./
with the current working directory. This allows us to create absolute paths and apply globs in a more predictable wayWhile implementing this, I found out that there were a few issues on how we handle files that we don't support. I applied the correct changes and how they should be fixed. They are around
FileFeaturesResult
.Better glob support
Our previous implementation of glob support used an internal fork of the
glob
create. This wasn't ideal, because it didn't support some edge cases and.gitignore
patterns.I removed this fork and used
globset
. This is another crate that pumpsripgrep
, so it's battle-tested and provides the features we want:.gitignore
globs supportTo support this feature, I had to do some refactoring on how we retrieve this information. Some of those changes lead also to some optimisations that we didn't do before.
Technical changes
load_configuration
was accepting the wholesession
object, and it was also writing diagnostics to the terminal. This wasn't well architected, because we don't have the console object in the LSP. I changed, by pass only theFileSystem
trait, and created a function calledvalidate_configuration_diagnostics
that checks whether there are errors and blocks the process.error!
macro and block the processupdate_settings
now accepts the root path of the VCS and the contents inside the.gitignore
file. Before Biome was reading the contents of the file and adding the paths tofiles.ignore
. This isn't the case anymore. We pass this information to theWorkspace
server so it can properly create theMatcher
types. This isn't ideal, I am sure we can optimise this part later.Matcher
object is not anOption
anymore, but instead, we use the newempty
function to determine whether we should apply its matching logic or not. This is required because we don't want to apply the matching if there isn't anything to match. This is an important requirement. Theempty
function checks if there are matches defined in the configuration e.g.files.ignore: ["dist/**"]
and in the.gitignore
.biome_service
because these kinds of errors are expected inside the LSP too (yay!!)Test Plan
The current tests should pass and shouldn't change, except for a few that should be updated.
I also tested it in our internal script. This revealed a bunch of bugs!! For example, we were not receiving diagnostics for files that we can't handle such as
mdx
,css
etc. Note that the optionfiles.ignoreUnknown
wasn't turned on. I added more globs to ourbiome.json
and I could see that these files aren't processed anymore.I will create a nightly release and test it in other repositories.