Skip to content

Commit

Permalink
Use parse_unchecked_source
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jun 4, 2024
1 parent 4af0673 commit 82c5f17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 0 additions & 1 deletion crates/red_knot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ tracing-subscriber = { workspace = true }
tracing-tree = { workspace = true }

[dev-dependencies]
textwrap = { version = "0.16.1" }
tempfile = { workspace = true }

[lints]
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) fn lint_semantic(db: &dyn LintDb, file_id: FileId) -> QueryResult<Dia
let context = SemanticLintContext {
file_id: *file_id,
source,
parsed: &*parsed,
parsed: &parsed,
symbols,
db,
diagnostics: RefCell::new(Vec::new()),
Expand Down
11 changes: 5 additions & 6 deletions crates/red_knot/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::{Deref, DerefMut};
use std::sync::Arc;

use ruff_python_ast::ModModule;
use ruff_python_parser::{Mode, Parsed};
use ruff_python_parser::Parsed;

use crate::cache::KeyValueCache;
use crate::db::{QueryResult, SourceDb};
Expand All @@ -16,11 +16,10 @@ pub(crate) fn parse(db: &dyn SourceDb, file_id: FileId) -> QueryResult<Arc<Parse
jar.parsed.get(&file_id, |file_id| {
let source = source_text(db, *file_id)?;

Ok(Arc::new(
ruff_python_parser::parse_unchecked(source.text(), Mode::Module)
.try_into_module()
.unwrap(),
))
Ok(Arc::new(ruff_python_parser::parse_unchecked_source(
source.text(),
source.kind().into(),
)))
})
}

Expand Down
10 changes: 10 additions & 0 deletions crates/red_knot/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ pub enum SourceKind {
IpyNotebook(Arc<Notebook>),
}

impl<'a> From<&'a SourceKind> for PySourceType {
fn from(value: &'a SourceKind) -> Self {
match value {
SourceKind::Python(_) => PySourceType::Python,
SourceKind::Stub(_) => PySourceType::Stub,
SourceKind::IpyNotebook(_) => PySourceType::Ipynb,
}
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct Source {
kind: SourceKind,
Expand Down

0 comments on commit 82c5f17

Please sign in to comment.