Skip to content

Commit 9aa43d5

Browse files
authored
Separate red_knot into CLI and red_knot_workspace crates (#12623)
## Summary This PR separates the current `red_knot` crate into two crates: 1. `red_knot` - This will be similar to the `ruff` crate, it'll act as the CLI crate 2. `red_knot_workspace` - This includes everything except for the CLI functionality from the existing `red_knot` crate Note that the code related to the file watcher is in `red_knot_workspace` for now but might be required to extract it out in the future. The main motivation for this change is so that we can have a `red_knot server` command. This makes it easier to test the server out without making any changes in the VS Code extension. All we need is to specify the `red_knot` executable path in `ruff.path` extension setting. ## Test Plan - `cargo build` - `cargo clippy --workspace --all-targets --all-features` - `cargo shear --fix`
1 parent 966563c commit 9aa43d5

File tree

290 files changed

+66
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+66
-25
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exclude: |
1010
crates/ruff_python_formatter/tests/snapshots/.*|
1111
crates/ruff_python_resolver/resources/.*|
1212
crates/ruff_python_resolver/tests/snapshots/.*|
13-
crates/red_knot/resources/.*
13+
crates/red_knot_workspace/resources/.*
1414
)$
1515
1616
repos:

Cargo.lock

+18-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ ruff_source_file = { path = "crates/ruff_source_file" }
3535
ruff_text_size = { path = "crates/ruff_text_size" }
3636
ruff_workspace = { path = "crates/ruff_workspace" }
3737

38-
red_knot = { path = "crates/red_knot" }
3938
red_knot_module_resolver = { path = "crates/red_knot_module_resolver" }
4039
red_knot_python_semantic = { path = "crates/red_knot_python_semantic" }
40+
red_knot_workspace = { path = "crates/red_knot_workspace" }
4141

4242
aho-corasick = { version = "1.1.3" }
4343
annotate-snippets = { version = "0.9.2", features = ["color"] }

crates/red_knot/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@ license.workspace = true
1313

1414
[dependencies]
1515
red_knot_module_resolver = { workspace = true }
16-
red_knot_python_semantic = { workspace = true }
16+
red_knot_workspace = { workspace = true }
1717

1818
ruff_db = { workspace = true, features = ["os", "cache"] }
19-
ruff_python_ast = { workspace = true }
2019

2120
anyhow = { workspace = true }
2221
clap = { workspace = true, features = ["wrap_help"] }
2322
countme = { workspace = true, features = ["enable"] }
2423
crossbeam = { workspace = true }
2524
ctrlc = { version = "3.4.4" }
26-
notify = { workspace = true }
2725
rayon = { workspace = true }
28-
rustc-hash = { workspace = true }
2926
salsa = { workspace = true }
3027
tracing = { workspace = true }
3128
tracing-subscriber = { workspace = true }

crates/red_knot/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use tracing_subscriber::layer::{Context, Filter, SubscriberExt};
99
use tracing_subscriber::{Layer, Registry};
1010
use tracing_tree::time::Uptime;
1111

12-
use red_knot::db::RootDatabase;
13-
use red_knot::watch;
14-
use red_knot::watch::WorkspaceWatcher;
15-
use red_knot::workspace::WorkspaceMetadata;
12+
use red_knot_workspace::db::RootDatabase;
13+
use red_knot_workspace::watch;
14+
use red_knot_workspace::watch::WorkspaceWatcher;
15+
use red_knot_workspace::workspace::WorkspaceMetadata;
1616
use ruff_db::program::{ProgramSettings, SearchPathSettings};
1717
use ruff_db::system::{OsSystem, System, SystemPathBuf};
1818

crates/red_knot/tests/file_watching.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use std::time::Duration;
66
use anyhow::{anyhow, Context};
77
use salsa::Setter;
88

9-
use red_knot::db::RootDatabase;
10-
use red_knot::watch;
11-
use red_knot::watch::{directory_watcher, WorkspaceWatcher};
12-
use red_knot::workspace::WorkspaceMetadata;
139
use red_knot_module_resolver::{resolve_module, ModuleName};
10+
use red_knot_workspace::db::RootDatabase;
11+
use red_knot_workspace::watch;
12+
use red_knot_workspace::watch::{directory_watcher, WorkspaceWatcher};
13+
use red_knot_workspace::workspace::WorkspaceMetadata;
1414
use ruff_db::files::{system_path_to_file, File, FileError};
1515
use ruff_db::program::{Program, ProgramSettings, SearchPathSettings, TargetVersion};
1616
use ruff_db::source::source_text;

crates/red_knot_workspace/Cargo.toml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "red_knot_workspace"
3+
version = "0.0.0"
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
homepage.workspace = true
7+
documentation.workspace = true
8+
repository.workspace = true
9+
authors.workspace = true
10+
license.workspace = true
11+
12+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+
14+
[dependencies]
15+
red_knot_module_resolver = { workspace = true }
16+
red_knot_python_semantic = { workspace = true }
17+
18+
ruff_db = { workspace = true, features = ["os", "cache"] }
19+
ruff_python_ast = { workspace = true }
20+
21+
anyhow = { workspace = true }
22+
crossbeam = { workspace = true }
23+
notify = { workspace = true }
24+
rustc-hash = { workspace = true }
25+
salsa = { workspace = true }
26+
tracing = { workspace = true }
27+
28+
[dev-dependencies]
29+
30+
[lints]
31+
workspace = true
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

crates/red_knot/tests/check.rs renamed to crates/red_knot_workspace/tests/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use red_knot::db::RootDatabase;
2-
use red_knot::lint::lint_semantic;
3-
use red_knot::workspace::WorkspaceMetadata;
1+
use red_knot_workspace::db::RootDatabase;
2+
use red_knot_workspace::lint::lint_semantic;
3+
use red_knot_workspace::workspace::WorkspaceMetadata;
44
use ruff_db::files::system_path_to_file;
55
use ruff_db::program::{ProgramSettings, SearchPathSettings, TargetVersion};
66
use ruff_db::system::{OsSystem, SystemPathBuf};

crates/ruff_benchmark/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ruff_python_ast = { workspace = true }
5050
ruff_python_formatter = { workspace = true }
5151
ruff_python_parser = { workspace = true }
5252
ruff_python_trivia = { workspace = true }
53-
red_knot = { workspace = true }
53+
red_knot_workspace = { workspace = true }
5454

5555
[lints]
5656
workspace = true

crates/ruff_benchmark/benches/red_knot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion};
44

5-
use red_knot::db::RootDatabase;
6-
use red_knot::workspace::WorkspaceMetadata;
5+
use red_knot_workspace::db::RootDatabase;
6+
use red_knot_workspace::workspace::WorkspaceMetadata;
77
use ruff_db::files::{system_path_to_file, vendored_path_to_file, File};
88
use ruff_db::parsed::parsed_module;
99
use ruff_db::program::{ProgramSettings, SearchPathSettings, TargetVersion};

0 commit comments

Comments
 (0)