Skip to content
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

refactor: configuration, settings and options #3317

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sec-ant
Copy link
Member

@Sec-ant Sec-ant commented Jun 30, 2024

Summary

A preliminary attempt to address #3297, #3310 (comment) etc.

  • Use Option<T> in JsParserSettings
  • Use a consistent naming style, and improve the doc comments for sustainable maintenance.
  • Retain a single source of truth of defaults.
  • Make sure that caching works as expected.
  • Try removing the Partial macro.

Test Plan

CI passes. No performance degradation.

@Sec-ant Sec-ant changed the title Refactor/configuration settings options refactor: configuration, settings and options Jun 30, 2024
@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS L-JSON Language: JSON and super languages labels Jun 30, 2024
Copy link
Contributor

github-actions bot commented Jun 30, 2024

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 48293 48293 0
Passed 47096 47096 0
Failed 1197 1197 0
Panics 0 0 0
Coverage 97.52% 97.52% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6541 6541 0
Passed 2198 2198 0
Failed 4343 4343 0
Panics 0 0 0
Coverage 33.60% 33.60% 0.00%

ts/babel

Test result main count This PR count Difference
Total 669 669 0
Passed 597 597 0
Failed 72 72 0
Panics 0 0 0
Coverage 89.24% 89.24% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18258 18258 0
Passed 13994 13994 0
Failed 4264 4264 0
Panics 0 0 0
Coverage 76.65% 76.65% 0.00%

Copy link

codspeed-hq bot commented Jun 30, 2024

CodSpeed Performance Report

Merging #3317 will degrade performances by 16.77%

Comparing refactor/configuration-settings-options (231a856) with main (b791bb3)

Summary

❌ 3 regressions
✅ 105 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main refactor/configuration-settings-options Change
db_2930068967297060348.json[cached] 12.8 ms 13.6 ms -6.28%
db_2930068967297060348.json[uncached] 14.5 ms 15.7 ms -7.34%
eucjp_4223654609205405644.json[uncached] 964.7 µs 1,159 µs -16.77%

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the other diffs are caused by variable renaming. This file is the starting point.

@Sec-ant Sec-ant force-pushed the refactor/configuration-settings-options branch 2 times, most recently from d1bcf4e to 5795511 Compare June 30, 2024 18:32
Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me so far.

crates/biome_service/src/settings.rs Outdated Show resolved Hide resolved
@Sec-ant Sec-ant force-pushed the refactor/configuration-settings-options branch 4 times, most recently from 076de02 to 2152f5a Compare July 2, 2024 10:48
@Sec-ant Sec-ant force-pushed the refactor/configuration-settings-options branch 2 times, most recently from ca541ea to 7d2ef58 Compare July 4, 2024 04:39
@github-actions github-actions bot added the A-LSP Area: language server protocol label Jul 4, 2024
@Conaclos
Copy link
Member

Conaclos commented Jul 4, 2024

Try removing the Partial macro.

Could you explain the reasons for removing this macro and what you are using instead?

@Sec-ant
Copy link
Member Author

Sec-ant commented Jul 4, 2024

Try removing the Partial macro.

Could you explain the reasons for removing this macro and what you are using instead?

The reason is that we almost always want to wrap options as Option<T> in our internal structure because when 1. merging configurations 2. applying language-specific options to their language-agnositc counterparts 3. applying overrides to base options, we need the None state to indicate that one option will not overwrite the other.

Currently, we have some bugs when converting between concrete structs and partial structs, which may accidentally convert a None to a Some and overwrite things unexpectedly. I also find this a source of confusion.

What I'm using instead is forcing Option<T> for every option, and I plan to postpone the unwrapping/resolution to the phase when a concrete value is actually needed, e.g. when resolving the ParseOptions / FormatOptions, when printing the biome rage messages, etc.

I'm also experimenting with a model where each option carries its default value in its type directly, so that whenever we need to get a concrete value of an option, we just need .unwrap_or_default().

@Conaclos
Copy link
Member

Conaclos commented Jul 4, 2024

Thanks for the rationales.
I agree with your points. Overall, I think this will reduce the complexity of the configuration.

@Sec-ant Sec-ant force-pushed the refactor/configuration-settings-options branch from c545f2d to 3494506 Compare July 4, 2024 11:15
@Sec-ant Sec-ant force-pushed the refactor/configuration-settings-options branch from 3494506 to 5eedd9f Compare July 5, 2024 05:19
@Sec-ant
Copy link
Member Author

Sec-ant commented Jul 5, 2024

I have some questions regarding how we handle ignored and included. There might be some problems in our current code.

Based on my understanding of this feature, I summarized the logic as the table below. Is it ok that I refactor the code to use 👇 to determine whether a path should be included or ignored?

Ignored list \ Included list Some(Patterns) & Matched Some(Patterns) & Unmatched None
Some(Patterns) & Matched Path is ignored Path is ignored Path is ignored
Some(Patterns) & Unmatched Path is included Path is ignored Path is included
None Path is included Path is ignored Path is included

@Sec-ant Sec-ant mentioned this pull request Jul 6, 2024
1 task
@Sec-ant Sec-ant force-pushed the refactor/configuration-settings-options branch from 5eedd9f to 033e90c Compare July 6, 2024 08:48
@ematipico
Copy link
Member

@Sec-ant yeah that's about right.

Empty lists should not run any matching.

The golden rule is that ignored has precedence over include, always.

If include isn't empty, any path that doesn't match is automatically ignored.

@Conaclos
Copy link
Member

Conaclos commented Jul 7, 2024

Based on my understanding of this feature, I summarized the logic as the table below. Is it ok that I refactor the code to use 👇 to determine whether a path should be included or ignored?

Everything looks good to me. I changed this in January / February to have a more consistent behavior. As Ema said ignore always wins on include. If include is None, then all files are included. If it is not None, then only matched files are considered. Then ignore is applied.

What looks wrong to you?

If I were to design the configuration now, I think I would just give a single field (e.g. files or ignores) that supports negative globs and apply globs in order. This might make the system more powerful and more intuitive.

@Sec-ant
Copy link
Member Author

Sec-ant commented Jul 8, 2024

Everything looks good to me. I changed this in January / February to have a more consistent behavior. As Ema said ignore always wins on include. If include is None, then all files are included. If it is not None, then only matched files are considered. Then ignore is applied.

What looks wrong to you?

Oh, this is exactly how I see it, so nothing looks wrong to me :).

The only thing I'd like to keep you informed before doing it is that, now that we decide to always use Option<T> in this PR to refactor the options, I'd like to keep a consistent mental model across the codebase. Currently, it seems that we use Vec::empty to indicate the list is unset, I'd like to suggest that we use None for this purpose, and regard any Some values as being explicitly set, even if it's an empty vector. I'll also make sure this will not change the default behavior.

@Sec-ant
Copy link
Member Author

Sec-ant commented Jul 8, 2024

And FWIW, I'll keep working on this PR in the following days but I cannot gaurantee a specific timeframe, so this shouldn't be a blocker for any foreseeable release plans, just in case.

@Sec-ant Sec-ant force-pushed the refactor/configuration-settings-options branch 2 times, most recently from 2a762f5 to 0966d04 Compare July 10, 2024 09:11
@Sec-ant Sec-ant force-pushed the refactor/configuration-settings-options branch from 0966d04 to 231a856 Compare July 10, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Formatter Area: formatter A-Linter Area: linter A-LSP Area: language server protocol A-Parser Area: parser A-Project Area: project A-Tooling Area: internal tools L-CSS Language: CSS L-JavaScript Language: JavaScript and super languages L-JSON Language: JSON and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants