Skip to content

Commit 419b1ec

Browse files
committed
Cargo fmt
1 parent 24beda8 commit 419b1ec

File tree

21 files changed

+205
-157
lines changed

21 files changed

+205
-157
lines changed

enderpy/src/main.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
use anyhow::{Result, bail};
1+
use anyhow::{bail, Result};
22
use clap::Parser as ClapParser;
33
use cli::{Cli, Commands};
44
use enderpy_python_parser::{token, Lexer, Parser};
5-
use std::{fs, path::PathBuf};
65
use enderpy_python_type_checker::{
76
build::{BuildManager, BuildSource},
8-
settings::{ImportDiscovery, Settings}, project::find_project_root,
7+
project::find_project_root,
8+
settings::{ImportDiscovery, Settings},
99
};
10+
use std::{fs, path::PathBuf};
1011

1112
mod cli;
1213

@@ -30,8 +31,12 @@ fn symbols(path: &PathBuf) -> std::result::Result<(), anyhow::Error> {
3031
followed: false,
3132
};
3233
let dir_of_path = path.parent().unwrap();
33-
let python_executable = Some( get_python_executable()? );
34-
let settings = Settings { debug: false, root: dir_of_path.to_path_buf(), import_discovery: ImportDiscovery { python_executable } };
34+
let python_executable = Some(get_python_executable()?);
35+
let settings = Settings {
36+
debug: false,
37+
root: dir_of_path.to_path_buf(),
38+
import_discovery: ImportDiscovery { python_executable },
39+
};
3540

3641
let mut manager = BuildManager::new(vec![initial_source], settings);
3742
manager.build();
@@ -90,8 +95,12 @@ fn check(path: &PathBuf) -> Result<()> {
9095
followed: false,
9196
};
9297
let root = find_project_root(path);
93-
let python_executable = Some( get_python_executable()? );
94-
let settings = Settings { debug: true, root: PathBuf::from(root), import_discovery: ImportDiscovery { python_executable } };
98+
let python_executable = Some(get_python_executable()?);
99+
let settings = Settings {
100+
debug: true,
101+
root: PathBuf::from(root),
102+
import_discovery: ImportDiscovery { python_executable },
103+
};
95104
let mut build_manager = BuildManager::new(vec![initial_source], settings);
96105
build_manager.type_check();
97106

lsp/src/main.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use env_logger::Builder;
4-
use log::{LevelFilter, info};
4+
use log::{info, LevelFilter};
55
use tower_lsp::jsonrpc::Result;
66
use tower_lsp::lsp_types::*;
77
use tower_lsp::{Client, LanguageServer, LspService, Server};
@@ -128,10 +128,13 @@ impl LanguageServer for Backend {
128128
}
129129
}
130130

131-
async fn diagnostic(&self, params: DocumentDiagnosticParams) -> Result<DocumentDiagnosticReportResult> {
131+
async fn diagnostic(
132+
&self,
133+
params: DocumentDiagnosticParams,
134+
) -> Result<DocumentDiagnosticReportResult> {
132135
self.client
133136
.log_message(MessageType::INFO, "diagnostic!")
134-
.await;
137+
.await;
135138
let uri = params.text_document.uri;
136139
let path = uri.to_file_path();
137140

@@ -141,23 +144,23 @@ impl LanguageServer for Backend {
141144
let diagnostics = self.check_file(&path).await;
142145
info!("diagnostics: {:?}", diagnostics);
143146
Ok(DocumentDiagnosticReportResult::Report(
144-
DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport{
147+
DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport {
145148
related_documents: None,
146-
full_document_diagnostic_report: FullDocumentDiagnosticReport{
149+
full_document_diagnostic_report: FullDocumentDiagnosticReport {
147150
result_id: None,
148151
items: diagnostics,
149-
}
150-
})
152+
},
153+
}),
151154
))
152155
}
153-
Err(_) => {
154-
Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Unchanged(RelatedUnchangedDocumentDiagnosticReport{
155-
related_documents:None,
156-
unchanged_document_diagnostic_report: UnchangedDocumentDiagnosticReport{
156+
Err(_) => Ok(DocumentDiagnosticReportResult::Report(
157+
DocumentDiagnosticReport::Unchanged(RelatedUnchangedDocumentDiagnosticReport {
158+
related_documents: None,
159+
unchanged_document_diagnostic_report: UnchangedDocumentDiagnosticReport {
157160
result_id: "typechecker".to_string(),
158-
}
159-
})))
160-
}
161+
},
162+
}),
163+
)),
161164
}
162165
}
163166

parser/src/lexer/lexer.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Lexer {
5454
start: self.current,
5555
end: self.current,
5656
});
57-
}
57+
}
5858
let start = self.current;
5959
let kind = self.next_kind()?;
6060

@@ -330,7 +330,7 @@ impl Lexer {
330330
}
331331
}
332332
return Ok(Kind::Dot);
333-
},
333+
}
334334
';' => return Ok(Kind::SemiColon),
335335
'=' => match self.peek() {
336336
Some('=') => {
@@ -348,7 +348,7 @@ impl Lexer {
348348
self.next();
349349
}
350350
return Ok(Kind::Comment);
351-
},
351+
}
352352
'\\' => return Ok(Kind::BackSlash),
353353
'$' => return Ok(Kind::Dollar),
354354
'?' => return Ok(Kind::QuestionMark),
@@ -779,7 +779,7 @@ impl Lexer {
779779
}
780780
}
781781
if spaces_count == 0 {
782-
// When there are no spaces and only a new line
782+
// When there are no spaces and only a new line
783783
// like the following
784784
// if True:
785785
//
@@ -791,7 +791,7 @@ impl Lexer {
791791
// we should not consider it as dedent
792792
// Thanks python
793793
if self.peek() == Some('\n') && self.double_peek().is_some() {
794-
return None
794+
return None;
795795
}
796796
}
797797
if let Some(top) = self.indent_stack.last() {
@@ -830,7 +830,7 @@ impl Lexer {
830830
| Kind::RawString
831831
| Kind::RawFStringStart
832832
| Kind::Bytes
833-
| Kind::Unicode
833+
| Kind::Unicode
834834
| Kind::Comment => TokenValue::Str(kind_value),
835835
Kind::Dedent => {
836836
let mut spaces_count = 0;
@@ -862,7 +862,7 @@ impl Lexer {
862862
// minus 1 because the dedent with actual Indent value is already added
863863
// This is super hacky and I don't like it
864864
self.next_token_is_dedent += de_indents - 1;
865-
}
865+
}
866866
TokenValue::Indent(de_indents.into())
867867
}
868868
Kind::Indent => TokenValue::Indent(1),
@@ -1154,7 +1154,7 @@ def",
11541154
f = c
11551155
11561156
# Path: test_local.py
1157-
"
1157+
",
11581158
],
11591159
)
11601160
.unwrap();
@@ -1200,11 +1200,15 @@ def",
12001200

12011201
#[test]
12021202
fn test_ellipsis() {
1203-
snapshot_test_lexer("ellipsis", &[
1204-
"...",
1205-
"def a():
1206-
..."
1207-
]).unwrap();
1203+
snapshot_test_lexer(
1204+
"ellipsis",
1205+
&[
1206+
"...",
1207+
"def a():
1208+
...",
1209+
],
1210+
)
1211+
.unwrap();
12081212
}
12091213

12101214
#[test]

parser/src/parser/error.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ pub enum ParsingError {
77
#[diagnostic(code(gen_color::io_error))]
88
IoError(#[from] std::io::Error),
99

10-
#[error(
11-
"Invalid syntax"
12-
)]
13-
#[diagnostic(code(
14-
gen_color::colors_and_steps_mismatch
15-
))]
10+
#[error("Invalid syntax")]
11+
#[diagnostic(code(gen_color::colors_and_steps_mismatch))]
1612
InvalidSyntax {
1713
path: Box<str>,
1814
msg: Box<str>,

parser/src/parser/parser.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ impl Parser {
218218
}
219219
let err = ParsingError::InvalidSyntax {
220220
path: Box::from(self.path.as_str()),
221-
msg: Box::from(format!("Expected one of {:?} but found {:?}", expected, found)),
221+
msg: Box::from(format!(
222+
"Expected one of {:?} but found {:?}",
223+
expected, found
224+
)),
222225
line: self.curr_line_number,
223226
input: self.curr_line_string.clone(),
224227
advice: "maybe you forgot to put this character".to_string(),
@@ -429,7 +432,7 @@ impl Parser {
429432
}
430433

431434
let mut single_else_body: Option<Vec<Statement>> = None;
432-
if self.eat(Kind::Else) {
435+
if self.eat(Kind::Else) {
433436
self.expect(Kind::Colon)?;
434437
let else_body = self.parse_suite()?;
435438
if let Some(val) = &mut orelse {
@@ -1912,7 +1915,7 @@ impl Parser {
19121915
if self.at(Kind::Pow) {
19131916
// key must be None
19141917
let (key, value) = self.parse_double_starred_kv_pair()?;
1915-
return self.parse_dict(node, key, value)
1918+
return self.parse_dict(node, key, value);
19161919
}
19171920
let first_key_or_element = self.parse_star_named_expression()?;
19181921
if matches!(
@@ -2016,7 +2019,9 @@ impl Parser {
20162019
}
20172020
}
20182021

2019-
fn parse_double_starred_kv_pair(&mut self) -> Result<(Option<Expression>,Expression), ParsingError> {
2022+
fn parse_double_starred_kv_pair(
2023+
&mut self,
2024+
) -> Result<(Option<Expression>, Expression), ParsingError> {
20202025
if self.eat(Kind::Pow) {
20212026
let value = self.parse_expression_2()?;
20222027
Ok((None, value))
@@ -3693,7 +3698,10 @@ class a: pass",
36933698
fn test_complete() {
36943699
glob!("../../test_data", "inputs/*.py", |path| {
36953700
let test_case = fs::read_to_string(path).unwrap();
3696-
let mut parser = Parser::new(test_case.clone(), String::from(path.file_name().unwrap().to_str().unwrap()));
3701+
let mut parser = Parser::new(
3702+
test_case.clone(),
3703+
String::from(path.file_name().unwrap().to_str().unwrap()),
3704+
);
36973705
let program = parser.parse();
36983706

36993707
insta::with_settings!({
@@ -3719,7 +3727,10 @@ class a: pass",
37193727
glob!("../../test_data", "inputs/one_liners/*.py", |path| {
37203728
let input = fs::read_to_string(path).unwrap();
37213729
for test_case in input.split("\n\n") {
3722-
let mut parser = Parser::new(test_case.to_string(), String::from(path.file_name().unwrap().to_str().unwrap()));
3730+
let mut parser = Parser::new(
3731+
test_case.to_string(),
3732+
String::from(path.file_name().unwrap().to_str().unwrap()),
3733+
);
37233734
let program = parser.parse();
37243735

37253736
insta::with_settings!({

typechecker/src/ast_visitor.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use enderpy_python_parser::ast::*;
21
use enderpy_python_parser as parser;
2+
use enderpy_python_parser::ast::*;
33

44
/// A visitor that traverses the AST and calls the visit method for each node
55
/// This is useful for visitors that only need to visit a few nodes
@@ -34,7 +34,7 @@ pub trait TraversalVisitor {
3434
Statement::ClassDef(c) => self.visit_class_def(c),
3535
Statement::Match(m) => self.visit_match(m),
3636
Statement::AsyncForStatement(f) => self.visit_async_for(f),
37-
Statement::AsyncWithStatement(w) => self.visit_async_with(w),
37+
Statement::AsyncWithStatement(w) => self.visit_async_with(w),
3838
Statement::AsyncFunctionDef(f) => self.visit_async_function_def(f),
3939
}
4040
}
@@ -194,40 +194,40 @@ pub trait TraversalVisitor {
194194
}
195195

196196
fn visit_match_pattern(&mut self, _m: &parser::ast::MatchPattern) {
197-
match _m {
198-
MatchPattern::MatchValue(m) => self.visit_expr(&m.value),
199-
MatchPattern::MatchSingleton(m) => self.visit_expr(m),
200-
MatchPattern::MatchSequence(m) => {
201-
for item in m.iter() {
202-
self.visit_match_pattern(item);
203-
}
204-
},
205-
MatchPattern::MatchStar(m) => self.visit_expr(m),
206-
MatchPattern::MatchMapping(m) => {
207-
for key in &m.keys {
208-
self.visit_expr(key);
209-
}
210-
for pattern in &m.patterns {
211-
self.visit_match_pattern(pattern);
212-
}
213-
},
214-
MatchPattern::MatchAs(m) => {
215-
if let Some(pattern) = &m.pattern {
216-
self.visit_match_pattern(pattern);
217-
}
218-
},
219-
MatchPattern::MatchClass(m) => {
220-
self.visit_expr(&m.cls);
221-
for pattern in &m.patterns {
222-
self.visit_match_pattern(pattern);
223-
}
224-
},
225-
MatchPattern::MatchOr(m) => {
226-
for pattern in m.iter() {
227-
self.visit_match_pattern(pattern);
228-
}
229-
},
197+
match _m {
198+
MatchPattern::MatchValue(m) => self.visit_expr(&m.value),
199+
MatchPattern::MatchSingleton(m) => self.visit_expr(m),
200+
MatchPattern::MatchSequence(m) => {
201+
for item in m.iter() {
202+
self.visit_match_pattern(item);
203+
}
204+
}
205+
MatchPattern::MatchStar(m) => self.visit_expr(m),
206+
MatchPattern::MatchMapping(m) => {
207+
for key in &m.keys {
208+
self.visit_expr(key);
209+
}
210+
for pattern in &m.patterns {
211+
self.visit_match_pattern(pattern);
212+
}
213+
}
214+
MatchPattern::MatchAs(m) => {
215+
if let Some(pattern) = &m.pattern {
216+
self.visit_match_pattern(pattern);
217+
}
230218
}
219+
MatchPattern::MatchClass(m) => {
220+
self.visit_expr(&m.cls);
221+
for pattern in &m.patterns {
222+
self.visit_match_pattern(pattern);
223+
}
224+
}
225+
MatchPattern::MatchOr(m) => {
226+
for pattern in m.iter() {
227+
self.visit_match_pattern(pattern);
228+
}
229+
}
230+
}
231231
}
232232

233233
fn visit_constant(&mut self, _c: &Constant) {

typechecker/src/ast_visitor_generic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use ast::{Expression, Statement};
55

6-
76
use enderpy_python_parser as parser;
87
use enderpy_python_parser::ast::{self, *};
98

@@ -36,7 +35,7 @@ pub trait TraversalVisitorImmutGeneric<T> {
3635
Statement::ClassDef(c) => self.visit_class_def(c),
3736
Statement::Match(m) => self.visit_match(m),
3837
Statement::AsyncForStatement(f) => self.visit_async_for(f),
39-
Statement::AsyncWithStatement(w) => self.visit_async_with(w),
38+
Statement::AsyncWithStatement(w) => self.visit_async_with(w),
4039
Statement::AsyncFunctionDef(f) => self.visit_async_function_def(f),
4140
}
4241
}

typechecker/src/ast_visitor_immut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub trait TraversalVisitorImmut {
3333
Statement::ClassDef(c) => self.visit_class_def(c),
3434
Statement::Match(m) => self.visit_match(m),
3535
Statement::AsyncForStatement(f) => self.visit_async_for(f),
36-
Statement::AsyncWithStatement(w) => self.visit_async_with(w),
36+
Statement::AsyncWithStatement(w) => self.visit_async_with(w),
3737
Statement::AsyncFunctionDef(f) => self.visit_async_function_def(f),
3838
}
3939
}

0 commit comments

Comments
 (0)