Skip to content

Commit 74982fe

Browse files
Move ExperimentalFeatures to cli.rs and simplify implementation
Co-authored-by: felix-andreas-copilot <[email protected]>
1 parent 3eb79a5 commit 74982fe

File tree

6 files changed

+55
-106
lines changed

6 files changed

+55
-106
lines changed

crates/roughly/src/cli.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use {
22
crate::{
33
config, diagnostics,
4-
experimental::ExperimentalFeatures,
54
format::{self, LineEnding},
65
index,
76
lsp_types::{self, DiagnosticSeverity},
@@ -16,6 +15,55 @@ use {
1615
},
1716
};
1817

18+
//
19+
// EXPERIMENTAL FEATURES
20+
//
21+
22+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23+
pub struct ExperimentalFeatures {
24+
pub unused: bool,
25+
pub range_formatting: bool,
26+
}
27+
28+
impl ExperimentalFeatures {
29+
pub fn new() -> Self {
30+
Self {
31+
unused: false,
32+
range_formatting: false,
33+
}
34+
}
35+
36+
pub fn is_empty(&self) -> bool {
37+
!self.unused && !self.range_formatting
38+
}
39+
}
40+
41+
impl Default for ExperimentalFeatures {
42+
fn default() -> Self {
43+
Self::new()
44+
}
45+
}
46+
47+
pub fn parse_experimental_features(feature_strings: &[String]) -> ExperimentalFeatures {
48+
let mut features = ExperimentalFeatures::new();
49+
50+
for feature_str in feature_strings {
51+
match feature_str.as_str() {
52+
"all" => {
53+
features.unused = true;
54+
features.range_formatting = true;
55+
}
56+
"unused" => features.unused = true,
57+
"range_formatting" => features.range_formatting = true,
58+
_ => {
59+
warn(&format!("unknown experimental feature: {}", feature_str));
60+
}
61+
}
62+
}
63+
64+
features
65+
}
66+
1967
//
2068
// LOG
2169
//

crates/roughly/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ mod unused;
44

55
use {
66
crate::{
7+
cli::ExperimentalFeatures,
78
config::{self, Case},
8-
experimental::{ExperimentalFeature, ExperimentalFeatures},
99
lsp_types::{Diagnostic, DiagnosticSeverity},
1010
utils,
1111
},
@@ -37,7 +37,7 @@ pub fn analyze(node: Node, rope: &Rope, config: Config, full: bool) -> Vec<Diagn
3737

3838
if full && !has_syntax_errors {
3939
#[allow(clippy::collapsible_if)]
40-
if config.experimental_features.has(ExperimentalFeature::Unused) {
40+
if config.experimental_features.unused {
4141
match unused::analyze(node, rope) {
4242
Ok(diags) => diagnostics.extend(diags),
4343
Err(error) => {

crates/roughly/src/experimental.rs

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

crates/roughly/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod cli;
44
pub mod completions;
55
pub mod config;
66
pub mod diagnostics;
7-
pub mod experimental;
87
pub mod format;
98
pub mod index;
109
pub mod server;

crates/roughly/src/main.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use {
22
clap::{Parser, Subcommand},
33
roughly::{
4-
cli::{self, CheckError, DebugError, FmtError},
5-
experimental::ExperimentalFeatures,
4+
cli::{self, parse_experimental_features, CheckError, DebugError, FmtError},
65
},
76
std::{path::PathBuf, process::ExitCode},
87
tracing_subscriber::prelude::*,
@@ -22,10 +21,7 @@ fn main() -> ExitCode {
2221
let cli = Cli::parse();
2322

2423
// Parse experimental features and warn about unknown ones
25-
let (experimental_features, unknown_features) = ExperimentalFeatures::from_strings(&cli.experimental_features);
26-
for unknown in &unknown_features {
27-
eprintln!("warning: unknown experimental feature: {}", unknown);
28-
}
24+
let experimental_features = parse_experimental_features(&cli.experimental_features);
2925

3026
match cli.command {
3127
Command::Check { files } => match cli::check(files.as_deref(), experimental_features) {

crates/roughly/src/server.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use {
22
crate::{
3-
cli, completions,
3+
cli::{self, ExperimentalFeatures}, completions,
44
config::Config,
55
diagnostics,
6-
experimental::{ExperimentalFeature, ExperimentalFeatures},
76
format::{self, LineEnding},
87
index::{self, IndexError},
98
lsp_types::{
@@ -139,7 +138,7 @@ impl LanguageServer for ServerState {
139138
..Default::default()
140139
}),
141140
document_formatting_provider: Some(OneOf::Left(true)),
142-
document_range_formatting_provider: Some(OneOf::Left(self.experimental_features.has(ExperimentalFeature::RangeFormatting))),
141+
document_range_formatting_provider: Some(OneOf::Left(self.experimental_features.range_formatting)),
143142
document_symbol_provider: Some(OneOf::Left(true)),
144143
text_document_sync: Some(TextDocumentSyncCapability::Options(
145144
TextDocumentSyncOptions {

0 commit comments

Comments
 (0)