Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 114 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ default-members = ["crates/roughly"]
version = "0.0.5"

[workspace.dependencies]
typing = { path = "crates/typing" }

clap = { version = "4.5.40", features = ["derive"] }
console = "0.15.11"
ignore = "0.4.23"
Expand Down Expand Up @@ -41,6 +43,9 @@ nu-ansi-term = "0.50.1"
extendr-api = "0.8.0"
extendr-engine = "0.8.0"

# typing
miette = { version = "7.6.0", features = ["fancy"] }

# dev-dependencies
insta = "1.43.1"

Expand Down
2 changes: 2 additions & 0 deletions crates/roughly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ edition = "2024"
version.workspace = true

[dependencies]
typing.workspace = true

clap.workspace = true
console.workspace = true
ignore.workspace = true
Expand Down
15 changes: 12 additions & 3 deletions crates/roughly/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ pub fn check(
let mut n_files = 0;
let mut n_errors = 0;
for (paths, config) in paths_with_config {
let config = diagnostics::Config::from_config(config, experimental_features.unused);
let config = diagnostics::Config::from_config(
config,
experimental_features.unused,
experimental_features.typing,
);
for path in paths {
n_files += 1;
let old = match std::fs::read_to_string(&path) {
Expand Down Expand Up @@ -461,21 +465,25 @@ pub fn ast(path: &Path) -> Result<(), DebugError> {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExperimentalFeatures {
pub range_formatting: bool,
pub typing: bool,
pub unused: bool,
}

impl ExperimentalFeatures {
pub fn parse(flags: &[impl AsRef<str>]) -> Self {
let mut unused = false;
let mut range_formatting = false;
let mut typing = false;
let mut unused = false;

for flag in flags {
match flag.as_ref() {
"all" => {
unused = true;
range_formatting = true;
typing = true;
unused = true;
}
"range_formatting" => range_formatting = true,
"typing" => typing = true,
"unused" => unused = true,
unknown => {
warn(&format!("unknown experimental feature: {unknown}"));
Expand All @@ -485,6 +493,7 @@ impl ExperimentalFeatures {

Self {
unused,
typing,
range_formatting,
}
}
Expand Down
17 changes: 14 additions & 3 deletions crates/roughly/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod fast;
mod syntax;
mod typing;
mod unused;

use {
Expand All @@ -15,15 +16,21 @@ use {

#[derive(Debug, Clone, Copy)]
pub struct Config {
case: Case,
experimental_unused: bool,
pub case: Case,
pub experimental_unused: bool,
pub experimental_typing: bool,
}

impl Config {
pub fn from_config(config: config::Config, experimental_unused: bool) -> Self {
pub fn from_config(
config: config::Config,
experimental_unused: bool,
experimental_typing: bool,
) -> Self {
Config {
case: config.case,
experimental_unused,
experimental_typing,
}
}
}
Expand All @@ -44,6 +51,10 @@ pub fn analyze(node: Node, rope: &Rope, config: Config, full: bool) -> Vec<Diagn
}
}
}

if config.experimental_typing {
diagnostics.extend(typing::analyze(node, rope))
}
}

diagnostics
Expand Down
5 changes: 5 additions & 0 deletions crates/roughly/src/diagnostics/typing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use {crate::lsp_types::Diagnostic, ropey::Rope, tree_sitter::Node};

pub fn analyze(_node: Node, _rope: &Rope) -> Vec<Diagnostic> {
vec![]
}
2 changes: 0 additions & 2 deletions crates/roughly/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#![feature(let_chains)]

pub mod cli;
Expand Down
18 changes: 15 additions & 3 deletions crates/roughly/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ impl LanguageServer for ServerState {
let diagnostics = diagnostics::analyze_full(
tree.root_node(),
&rope,
diagnostics::Config::from_config(self.config, self.experimental_features.unused),
diagnostics::Config::from_config(
self.config,
self.experimental_features.unused,
self.experimental_features.typing,
),
);

let symbols = index::index(tree.root_node(), &rope, false);
Expand Down Expand Up @@ -338,7 +342,11 @@ impl LanguageServer for ServerState {
let diagnostics = diagnostics::analyze_fast(
tree.root_node(),
rope,
diagnostics::Config::from_config(self.config, self.experimental_features.unused),
diagnostics::Config::from_config(
self.config,
self.experimental_features.unused,
self.experimental_features.typing,
),
);

// UPDATE SYMBOLS
Expand Down Expand Up @@ -386,7 +394,11 @@ impl LanguageServer for ServerState {
let diagnostics = diagnostics::analyze_full(
root_node,
rope,
diagnostics::Config::from_config(self.config, self.experimental_features.unused),
diagnostics::Config::from_config(
self.config,
self.experimental_features.unused,
self.experimental_features.typing,
),
);

if let Err(error) = self
Expand Down
5 changes: 5 additions & 0 deletions crates/typing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ edition = "2024"
version.workspace = true

[dependencies]
miette.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
tree-sitter.workspace = true
tree-sitter-r.workspace = true
Loading