Fix hover types for for-loops

This commit is contained in:
Sofia 2025-08-02 20:10:48 +03:00
parent 3f6d26679d
commit 658450993a
4 changed files with 38 additions and 31 deletions

18
Cargo.lock generated
View File

@ -662,15 +662,7 @@ dependencies = [
]
[[package]]
name = "reid-lib"
version = "1.0.0-beta.3"
dependencies = [
"llvm-sys",
"thiserror",
]
[[package]]
name = "reid-lsp"
name = "reid-language-server"
version = "0.1.0"
dependencies = [
"dashmap 6.1.0",
@ -680,6 +672,14 @@ dependencies = [
"tower-lsp",
]
[[package]]
name = "reid-lib"
version = "1.0.0-beta.3"
dependencies = [
"llvm-sys",
"thiserror",
]
[[package]]
name = "rustc-demangle"
version = "0.1.26"

View File

@ -1,5 +1,5 @@
[package]
name = "reid-lsp"
name = "reid-language-server"
version = "0.1.0"
edition = "2024"

View File

@ -108,10 +108,10 @@ impl LanguageServer for Backend {
if let Some(ty) = possible_ty.clone() {
(Some(range), format!("{}", ty))
} else {
(Some(range), String::from("no type"))
(Some(range), String::from("None type"))
}
} else {
(None, String::from("no token"))
(None, String::from("no type"))
}
} else {
(None, String::from("no token"))
@ -267,7 +267,10 @@ async fn main() {
pub fn find_type_in_context(module: &mir::Module, token_idx: usize) -> Option<TypeKind> {
for import in &module.imports {
if import.1.contains(token_idx) {
return None;
return Some(TypeKind::CustomType(mir::CustomTypeKey(
"d".to_owned(),
SourceModuleId(1),
)));
}
}
for typedef in &module.typedefs {
@ -342,7 +345,7 @@ pub fn find_type_in_context(module: &mir::Module, token_idx: usize) -> Option<Ty
pub fn find_type_in_block(block: &mir::Block, module_id: SourceModuleId, token_idx: usize) -> Option<TypeKind> {
if !block.meta.contains(token_idx) {
return None;
return Some(TypeKind::Bool);
}
for statement in &block.statements {
@ -479,7 +482,10 @@ pub fn find_type_in_expr(expr: &mir::Expression, module_id: SourceModuleId, toke
{
Some(*inner.clone())
} else {
None
Some(TypeKind::CustomType(mir::CustomTypeKey(
"ä".to_owned(),
SourceModuleId(1),
)))
}
}
mir::ExprKind::CastTo(expression, type_kind) => {

View File

@ -228,33 +228,34 @@ impl ast::Block {
StmtKind::Let(counter_var.clone(), true, start.process(module_id)),
counter_range.as_meta(module_id),
);
let statement_range = counter_range.clone() + start.1 + end.1 + block.2;
let set_new = mir::Statement(
StmtKind::Set(
mir::Expression(
mir::ExprKind::Variable(counter_var.clone()),
counter_range.as_meta(module_id),
(start.1 + end.1).as_meta(module_id),
),
mir::Expression(
mir::ExprKind::BinOp(
mir::BinaryOperator::Add,
Box::new(mir::Expression(
mir::ExprKind::Variable(counter_var.clone()),
counter_range.as_meta(module_id),
(start.1 + end.1).as_meta(module_id),
)),
Box::new(mir::Expression(
mir::ExprKind::Literal(mir::Literal::Vague(mir::VagueLiteral::Number(1))),
counter_range.as_meta(module_id),
(start.1 + end.1).as_meta(module_id),
)),
mir::TypeKind::Vague(mir::VagueType::Unknown),
),
counter_range.as_meta(module_id),
(start.1 + end.1).as_meta(module_id),
),
),
counter_range.as_meta(module_id),
(start.1 + end.1).as_meta(module_id),
);
let mut block = block.into_mir(module_id);
block.statements.push(set_new);
let mut mir_block = block.into_mir(module_id);
mir_block.statements.push(set_new);
let while_statement = mir::Statement(
StmtKind::While(WhileStatement {
condition: mir::Expression(
@ -262,28 +263,28 @@ impl ast::Block {
mir::BinaryOperator::Cmp(mir::CmpOperator::LT),
Box::new(mir::Expression(
mir::ExprKind::Variable(counter_var),
counter_range.as_meta(module_id),
(start.1 + end.1).as_meta(module_id),
)),
Box::new(end.process(module_id)),
mir::TypeKind::Vague(mir::VagueType::Unknown),
),
counter_range.as_meta(module_id),
(start.1 + end.1).as_meta(module_id),
),
block,
meta: self.2.as_meta(module_id),
block: mir_block.clone(),
meta: (start.1 + end.1 + block.2).as_meta(module_id),
}),
self.2.as_meta(module_id),
(start.1 + end.1 + block.2).as_meta(module_id),
);
let inner_scope = StmtKind::Expression(mir::Expression(
mir::ExprKind::Block(mir::Block {
statements: vec![let_statement, while_statement],
return_expression: None,
meta: counter_range.as_meta(module_id) + end.1.as_meta(module_id),
meta: statement_range.as_meta(module_id),
}),
counter_range.as_meta(module_id) + end.1.as_meta(module_id),
statement_range.as_meta(module_id),
));
(inner_scope, self.2)
(inner_scope, statement_range)
}
ast::BlockLevelStatement::WhileLoop(expression, block) => (
StmtKind::While(WhileStatement {
@ -291,7 +292,7 @@ impl ast::Block {
block: block.into_mir(module_id),
meta: self.2.as_meta(module_id),
}),
self.2,
expression.1 + block.2,
),
};