Skip to content

Commit

Permalink
fix: include +- 1 in type ranges
Browse files Browse the repository at this point in the history
In cases of single letter names since the variable range was x, x+1
and the hover on x or x+1 would not be in range (x,x+1) so this fix will
make the range (x-1,x+1)
  • Loading branch information
Glyphack committed May 16, 2024
1 parent 2bcbd1a commit cfaf118
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions typechecker/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@ impl TypeChecker {
fn infer_expr_type(&mut self, expr: &Expression) -> PythonType {
let t = match self.type_evaluator.get_type(expr, None, None) {
Ok(t) => t,
Err(e) => PythonType::Unknown,
Err(e) => {
log::error!("type evaluator error: {} for expr {expr:?}", e);
PythonType::Unknown
}
};

let start = if expr.get_node().start > 0 {
expr.get_node().start - 1
} else {
expr.get_node().start
};
self.types.insert(Interval {
start: expr.get_node().start,
stop: expr.get_node().end,
start,
stop: expr.get_node().end + 1,
val: t.clone(),
});
t
Expand Down

0 comments on commit cfaf118

Please sign in to comment.