Skip to content

Commit 7207eff

Browse files
feat(lsp): provide inline configuration (#8278)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent da85e3c commit 7207eff

File tree

35 files changed

+946
-295
lines changed

35 files changed

+946
-295
lines changed

.changeset/purple-waves-brake.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
"@biomejs/biome": minor
3+
---
4+
5+
Added a feature that allows editors to inject a Biome configuration to the Biome Language Server without affecting the configuration of the project.
6+
7+
If you have a Biome extension that is compatible with your preferred LSP-ready editor, you can map `inlineConfig`. The configuration will be merged with the configuration of the project (or the default configuration):
8+
9+
For example, with the Zed editor, you would have the following configuration, which will format all files using four spaces as indentation style:
10+
11+
```json5
12+
// .zed/settings.json
13+
{
14+
"lsp": {
15+
"biome": {
16+
"settings": {
17+
"inline_config": {
18+
"formatter": {
19+
"indentStyle": "space",
20+
"indentWidth": 4
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
```

crates/biome_cli/src/execute/migrate.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ fn migrate_file(payload: MigrateFile) -> Result<MigrationFileResult, CliDiagnost
198198
.into(),
199199
),
200200
persist_node_cache: false,
201+
inline_config: None,
201202
})?;
202203
let parsed = parse_json_with_cache(&biome_config_content, &mut cache, parse_options);
203204

@@ -250,10 +251,12 @@ fn migrate_file(payload: MigrateFile) -> Result<MigrationFileResult, CliDiagnost
250251
path: biome_path.clone(),
251252
content: new_content,
252253
version: 1,
254+
inline_config: None,
253255
})?;
254256
let printed = workspace.format_file(FormatFileParams {
255257
project_key,
256258
path: biome_path,
259+
inline_config: None,
257260
})?;
258261
if write {
259262
biome_config_file.set_content(printed.as_code().as_bytes())?;
@@ -323,10 +326,12 @@ fn migrate_file(payload: MigrateFile) -> Result<MigrationFileResult, CliDiagnost
323326
path: biome_path.clone(),
324327
content: new_content,
325328
version: 1,
329+
inline_config: None,
326330
})?;
327331
let printed = workspace.format_file(FormatFileParams {
328332
project_key,
329333
path: biome_path,
334+
inline_config: None,
330335
})?;
331336
if write {
332337
biome_config_file.set_content(printed.as_code().as_bytes())?;
@@ -409,10 +414,12 @@ fn migrate_file(payload: MigrateFile) -> Result<MigrationFileResult, CliDiagnost
409414
path: biome_path.clone(),
410415
content: new_configuration_content,
411416
version: 1,
417+
inline_config: None,
412418
})?;
413419
let printed = workspace.format_file(FormatFileParams {
414420
project_key,
415421
path: biome_path,
422+
inline_config: None,
416423
})?;
417424
configuration_file.set_content(printed.as_code().as_bytes())?;
418425
Ok(MigrationFileResult::Migrated)

crates/biome_cli/src/execute/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,12 @@ pub fn execute_mode(
662662
path: report_file.clone(),
663663
document_file_source: None,
664664
persist_node_cache: false,
665+
inline_config: None,
665666
})?;
666667
let code = session.app.workspace.format_file(FormatFileParams {
667668
project_key,
668669
path: report_file.clone(),
670+
inline_config: None,
669671
})?;
670672
console.log(markup! {
671673
{code.as_code()}

crates/biome_cli/src/execute/process_file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub(crate) fn process_file(ctx: &TraversalOptions, biome_path: &BiomePath) -> Fi
136136
project_key: ctx.project_key,
137137
path: biome_path.clone(),
138138
features: ctx.execution.to_feature(),
139+
inline_config: None,
139140
})
140141
.with_file_path_and_code_and_tags(
141142
biome_path.to_string(),

crates/biome_cli/src/execute/process_file/workspace_file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl<'ctx, 'app> WorkspaceFile<'ctx, 'app> {
3939
path: path.clone(),
4040
content: FileContent::from_client(&input),
4141
persist_node_cache: false,
42+
inline_config: None,
4243
},
4344
)
4445
.with_file_path_and_code(path.to_string(), category!("internalError/fs"))?;

crates/biome_cli/src/execute/std_in.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub(crate) fn run<'a>(
4545
project_key,
4646
path: biome_path.clone(),
4747
features: FeaturesBuilder::new().with_formatter().build(),
48+
inline_config: None,
4849
})?;
4950

5051
if file_features.is_ignored() {
@@ -71,10 +72,12 @@ pub(crate) fn run<'a>(
7172
content: FileContent::from_client(content),
7273
document_file_source: None,
7374
persist_node_cache: false,
75+
inline_config: None,
7476
})?;
7577
let printed = workspace.format_file(FormatFileParams {
7678
project_key,
7779
path: biome_path.clone(),
80+
inline_config: None,
7881
})?;
7982

8083
let code = printed.into_code();
@@ -113,6 +116,7 @@ pub(crate) fn run<'a>(
113116
content: FileContent::from_client(content),
114117
document_file_source: None,
115118
persist_node_cache: false,
119+
inline_config: None,
116120
})?;
117121

118122
// apply fix file of the linter
@@ -126,6 +130,7 @@ pub(crate) fn run<'a>(
126130
.with_assist()
127131
.with_formatter()
128132
.build(),
133+
inline_config: None,
129134
})?;
130135

131136
if file_features.is_ignored() {
@@ -176,6 +181,7 @@ pub(crate) fn run<'a>(
176181
suppression_reason: None,
177182
enabled_rules: vec![],
178183
rule_categories: rule_categories.build(),
184+
inline_config: None,
179185
})?;
180186
let code = fix_file_result.code;
181187
let output = if !file_features.supports_full_html_support() {
@@ -195,6 +201,7 @@ pub(crate) fn run<'a>(
195201
content: output.clone(),
196202
path: biome_path.clone(),
197203
version,
204+
inline_config: None,
198205
})?;
199206
new_content = Cow::Owned(output);
200207
}
@@ -204,6 +211,7 @@ pub(crate) fn run<'a>(
204211
let printed = workspace.format_file(FormatFileParams {
205212
project_key,
206213
path: biome_path.clone(),
214+
inline_config: None,
207215
})?;
208216
let code = printed.into_code();
209217
let output = if !file_features.supports_full_html_support() {

crates/biome_cli/src/execute/traverse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ impl TraversalContext for TraversalOptions<'_, '_> {
576576
project_key: self.project_key,
577577
path: biome_path.clone(),
578578
features: self.execution.to_feature(),
579+
inline_config: None,
579580
});
580581

581582
let can_read = DocumentFileSource::can_read(biome_path);

crates/biome_formatter_test/src/spec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl<'a> SpecTestFile<'a> {
7070
project_key,
7171
path: input_file.clone(),
7272
features: FeaturesBuilder::new().with_formatter().build(),
73+
inline_config: None,
7374
})
7475
.unwrap();
7576

crates/biome_lsp/src/extension_settings.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::str::FromStr;
22

3+
use biome_configuration::Configuration;
34
use camino::Utf8PathBuf;
45
use serde::{Deserialize, Serialize};
56
use serde_json::{Error, Value};
@@ -27,6 +28,9 @@ pub struct WorkspaceSettings {
2728

2829
/// Experimental settings
2930
pub experimental: Option<ExperimentalSettings>,
31+
32+
/// Inline configuration, which gets merged before applying querying instructions via workspace
33+
pub inline_config: Option<Configuration>,
3034
}
3135

3236
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
@@ -70,4 +74,8 @@ impl ExtensionSettings {
7074
_ => None,
7175
}
7276
}
77+
78+
pub(crate) fn inline_config(&self) -> Option<Configuration> {
79+
self.settings.inline_config.clone()
80+
}
7381
}

crates/biome_lsp/src/handlers/analysis.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub(crate) fn code_actions(
7979
project_key: doc.project_key,
8080
path: path.clone(),
8181
features,
82+
inline_config: session.inline_config(),
8283
})?;
8384

8485
if !file_features.supports_lint() && !file_features.supports_assist() {
@@ -163,6 +164,7 @@ pub(crate) fn code_actions(
163164
.map(AnalyzerSelector::from)
164165
.collect(),
165166
categories: categories.build(),
167+
inline_config: session.inline_config(),
166168
}) {
167169
Ok(result) => result,
168170
Err(err) => {
@@ -316,6 +318,7 @@ fn fix_all(
316318
.with_linter()
317319
.with_assist()
318320
.build(),
321+
inline_config: session.inline_config(),
319322
})?;
320323
let should_format = file_features.supports_format();
321324

@@ -354,6 +357,7 @@ fn fix_all(
354357
enabled_rules: vec![],
355358
suppression_reason: None,
356359
rule_categories: categories.build(),
360+
inline_config: session.inline_config(),
357361
})?;
358362
let output = if file_features.supports_full_html_support() {
359363
fixed.code

0 commit comments

Comments
 (0)