Skip to content

Commit 2986a7a

Browse files
authored
Merge branch 'main' into FoldingRange
2 parents e15f23e + cf9ff74 commit 2986a7a

24 files changed

+393
-236
lines changed

.zed/settings.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Folder-specific settings
2+
//
3+
// For a full list of overridable settings, and general information on folder-specific settings,
4+
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
5+
{
6+
"lsp": {
7+
"rust-analyzer": {
8+
"initialization_options": {
9+
"checkOnSave": {
10+
"command": "clippy"
11+
},
12+
"rustfmt": {
13+
"extraArgs": ["+nightly"]
14+
}
15+
}
16+
}
17+
}
18+
}

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# Development version
44

5+
6+
# 0.1.2
7+
58
- The default indent style has been changed to spaces. The default indent width
69
has been changed to two. This more closely matches the overwhelming majority
710
of existing R code.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/air/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "air"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
publish = true
55
authors.workspace = true
66
categories.workspace = true

crates/lsp/src/capabilities.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
use tower_lsp::lsp_types::ClientCapabilities;
99
use tower_lsp::lsp_types::PositionEncodingKind;
1010

11-
/// A resolved representation of the [ClientCapabilities] the Client sends over that we
12-
/// actually do something with
11+
/// The subset of [ClientCapabilities] the Client sends over that we actually do
12+
/// something with
1313
#[derive(Debug, Default)]
14-
pub(crate) struct ResolvedClientCapabilities {
14+
pub(crate) struct AirClientCapabilities {
1515
pub(crate) position_encodings: Vec<PositionEncodingKind>,
1616
pub(crate) dynamic_registration_for_did_change_configuration: bool,
1717
pub(crate) dynamic_registration_for_did_change_watched_files: bool,
18+
pub(crate) request_configuration: bool,
1819
}
1920

20-
impl ResolvedClientCapabilities {
21+
impl AirClientCapabilities {
2122
pub(crate) fn new(capabilities: ClientCapabilities) -> Self {
2223
let position_encodings = capabilities
2324
.general
@@ -38,10 +39,17 @@ impl ResolvedClientCapabilities {
3839
.and_then(|watched_files| watched_files.dynamic_registration)
3940
.unwrap_or_default();
4041

42+
let configuration = capabilities
43+
.workspace
44+
.as_ref()
45+
.and_then(|workspace| workspace.configuration)
46+
.unwrap_or_default();
47+
4148
Self {
4249
position_encodings,
4350
dynamic_registration_for_did_change_configuration,
4451
dynamic_registration_for_did_change_watched_files,
52+
request_configuration: configuration,
4553
}
4654
}
4755
}

crates/lsp/src/config.rs

Lines changed: 0 additions & 148 deletions
This file was deleted.

crates/lsp/src/documents.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use biome_lsp_converters::{line_index, PositionEncoding};
99
use settings::LineEnding;
1010
use tower_lsp::lsp_types;
1111

12-
use crate::config::DocumentConfig;
1312
use crate::rust_analyzer::line_index::LineIndex;
1413
use crate::rust_analyzer::utils::apply_document_changes;
14+
use crate::settings::DocumentSettings;
1515

1616
#[derive(Clone)]
1717
pub struct Document {
@@ -34,8 +34,8 @@ pub struct Document {
3434
/// None if the document hasn't been synchronized yet.
3535
pub version: Option<i32>,
3636

37-
/// Configuration of the document, such as indentation settings.
38-
pub config: DocumentConfig,
37+
/// Settings of the document, such as indentation settings.
38+
pub settings: DocumentSettings,
3939
}
4040

4141
impl std::fmt::Debug for Document {
@@ -80,7 +80,7 @@ impl Document {
8080
line_index,
8181
parse,
8282
version,
83-
config: Default::default(),
83+
settings: Default::default(),
8484
}
8585
}
8686

crates/lsp/src/handlers.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ use crate::config::VscLogConfig;
2121
use crate::main_loop::LspState;
2222
use crate::state::WorldState;
2323

24+
use crate::settings_vsc::VscDiagnosticsSettings;
25+
use crate::settings_vsc::VscDocumentSettings;
26+
use crate::settings_vsc::VscLogSettings;
27+
2428
// Handlers that do not mutate the world state. They take a sharing reference or
2529
// a clone of the state.
2630

@@ -44,16 +48,16 @@ pub(crate) async fn handle_initialized(
4448
// changed by extensions or by the user without changing the actual
4549
// underlying setting. Unfortunately we don't receive updates in that case.
4650
let mut config_document_registrations = collect_regs(
47-
VscDocumentConfig::FIELD_NAMES_AS_ARRAY.to_vec(),
48-
VscDocumentConfig::section_from_key,
51+
VscDocumentSettings::FIELD_NAMES_AS_ARRAY.to_vec(),
52+
VscDocumentSettings::section_from_key,
4953
);
50-
let mut config_diagnostics_registrations: Vec<lsp_types::Registration> = collect_regs(
51-
VscDiagnosticsConfig::FIELD_NAMES_AS_ARRAY.to_vec(),
52-
VscDiagnosticsConfig::section_from_key,
54+
let mut config_diagnostics_registrations = collect_regs(
55+
VscDiagnosticsSettings::FIELD_NAMES_AS_ARRAY.to_vec(),
56+
VscDiagnosticsSettings::section_from_key,
5357
);
54-
let mut config_log_registrations: Vec<lsp_types::Registration> = collect_regs(
55-
VscLogConfig::FIELD_NAMES_AS_ARRAY.to_vec(),
56-
VscLogConfig::section_from_key,
58+
let mut config_log_registrations = collect_regs(
59+
VscLogSettings::FIELD_NAMES_AS_ARRAY.to_vec(),
60+
VscLogSettings::section_from_key,
5761
);
5862

5963
registrations.append(&mut config_document_registrations);

crates/lsp/src/handlers_format.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn document_formatting(
2323
) -> anyhow::Result<Option<Vec<lsp_types::TextEdit>>> {
2424
let doc = state.get_document(&params.text_document.uri)?;
2525

26-
let settings = lsp_state.document_settings(&params.text_document.uri);
26+
let settings = lsp_state.document_settings(&params.text_document.uri, &doc.settings);
2727
let format_options = settings.format.to_format_options(&doc.contents);
2828

2929
if doc.parse.has_errors() {
@@ -68,7 +68,7 @@ pub(crate) fn document_range_formatting(
6868
let range =
6969
from_proto::text_range(&doc.line_index.index, params.range, doc.line_index.encoding)?;
7070

71-
let settings = lsp_state.document_settings(&params.text_document.uri);
71+
let settings = lsp_state.document_settings(&params.text_document.uri, &doc.settings);
7272
let format_options = settings.format.to_format_options(&doc.contents);
7373

7474
let logical_lines = find_deepest_enclosing_logical_lines(doc.parse.syntax(), range);
@@ -521,4 +521,40 @@ mod tests {
521521
insta::assert_snapshot!(output6);
522522
});
523523
}
524+
525+
#[test]
526+
fn test_format_indent_options() {
527+
with_client(|client| async {
528+
let mut client = client.lock().await;
529+
530+
#[rustfmt::skip]
531+
let mut doc = Document::doodle("{1}");
532+
533+
doc.settings.indent_width = Some(settings::IndentWidth::try_from(8_u8).unwrap());
534+
let output_8_spaces = client.format_document(&doc).await;
535+
insta::assert_snapshot!(output_8_spaces);
536+
537+
doc.settings.indent_style = Some(settings::IndentStyle::Tab);
538+
let output_tab = client.format_document(&doc).await;
539+
insta::assert_snapshot!(output_tab);
540+
});
541+
}
542+
543+
#[test]
544+
fn test_format_range_indent_options() {
545+
with_client(|client| async {
546+
let mut client = client.lock().await;
547+
548+
#[rustfmt::skip]
549+
let (mut doc, range) = Document::doodle_and_range("<<{1}>>");
550+
551+
doc.settings.indent_width = Some(settings::IndentWidth::try_from(8_u8).unwrap());
552+
let output_8_spaces = client.format_document_range(&doc, range).await;
553+
insta::assert_snapshot!(output_8_spaces);
554+
555+
doc.settings.indent_style = Some(settings::IndentStyle::Tab);
556+
let output_tab = client.format_document_range(&doc, range).await;
557+
insta::assert_snapshot!(output_tab);
558+
});
559+
}
524560
}

0 commit comments

Comments
 (0)