Add semantic highlighting for binop params

This commit is contained in:
Sofia 2025-08-03 19:39:40 +03:00
parent d9911a8ff5
commit 1438ba7bd1
4 changed files with 22 additions and 6 deletions

View File

@ -333,6 +333,20 @@ pub fn analyze_context(context: &mir::Context, module: &mir::Module, error: Opti
} }
for binop in &module.binop_defs { for binop in &module.binop_defs {
if binop.meta.source_module_id == module.module_id {
for param in [&binop.lhs, &binop.rhs] {
dbg!(param);
scope.state.init_types(&param.meta, Some(param.ty.clone()));
let idx = scope
.token_idx(&param.meta, |t| matches!(t, Token::Identifier(_)))
.unwrap_or(param.meta.range.end);
dbg!(idx, scope.tokens.get(idx));
let symbol = scope.state.new_symbol(idx, SemanticKind::Variable);
scope.state.set_symbol(idx, symbol);
scope.variables.insert(param.name.clone(), symbol);
}
}
match &binop.fn_kind { match &binop.fn_kind {
mir::FunctionDefinitionKind::Local(block, _) => analyze_block(context, module, block, &mut scope), mir::FunctionDefinitionKind::Local(block, _) => analyze_block(context, module, block, &mut scope),
mir::FunctionDefinitionKind::Extern(_) => {} mir::FunctionDefinitionKind::Extern(_) => {}

View File

@ -272,9 +272,9 @@ pub enum TopLevelStatement {
#[derive(Debug)] #[derive(Debug)]
pub struct BinopDefinition { pub struct BinopDefinition {
pub lhs: (String, Type), pub lhs: (String, Type, TokenRange),
pub op: BinaryOperator, pub op: BinaryOperator,
pub rhs: (String, Type), pub rhs: (String, Type, TokenRange),
pub return_ty: Type, pub return_ty: Type,
pub block: Block, pub block: Block,
pub signature_range: TokenRange, pub signature_range: TokenRange,

View File

@ -1126,6 +1126,7 @@ impl Parse for BinopDefinition {
let Some(Token::Identifier(lhs_name)) = stream.next() else { let Some(Token::Identifier(lhs_name)) = stream.next() else {
return Err(stream.expected_err("lhs name")?); return Err(stream.expected_err("lhs name")?);
}; };
let lhs_range = stream.get_range_prev_curr().unwrap();
stream.expect(Token::Colon)?; stream.expect(Token::Colon)?;
let lhs_type = stream.parse()?; let lhs_type = stream.parse()?;
stream.expect(Token::ParenClose)?; stream.expect(Token::ParenClose)?;
@ -1136,6 +1137,7 @@ impl Parse for BinopDefinition {
let Some(Token::Identifier(rhs_name)) = stream.next() else { let Some(Token::Identifier(rhs_name)) = stream.next() else {
return Err(stream.expected_err("rhs name")?); return Err(stream.expected_err("rhs name")?);
}; };
let rhs_range = stream.get_range_prev_curr().unwrap();
stream.expect(Token::Colon)?; stream.expect(Token::Colon)?;
let rhs_type = stream.parse()?; let rhs_type = stream.parse()?;
stream.expect(Token::ParenClose)?; stream.expect(Token::ParenClose)?;
@ -1145,9 +1147,9 @@ impl Parse for BinopDefinition {
stream.expect(Token::Arrow)?; stream.expect(Token::Arrow)?;
Ok(BinopDefinition { Ok(BinopDefinition {
lhs: (lhs_name, lhs_type), lhs: (lhs_name, lhs_type, lhs_range),
op: operator, op: operator,
rhs: (rhs_name, rhs_type), rhs: (rhs_name, rhs_type, rhs_range),
return_ty: stream.parse()?, return_ty: stream.parse()?,
block: stream.parse()?, block: stream.parse()?,
signature_range, signature_range,

View File

@ -104,13 +104,13 @@ impl ast::Module {
lhs: mir::FunctionParam { lhs: mir::FunctionParam {
name: lhs.0.clone(), name: lhs.0.clone(),
ty: lhs.1 .0.into_mir(module_id), ty: lhs.1 .0.into_mir(module_id),
meta: lhs.1 .1.as_meta(module_id), meta: lhs.2.as_meta(module_id),
}, },
op: op.mir(), op: op.mir(),
rhs: mir::FunctionParam { rhs: mir::FunctionParam {
name: rhs.0.clone(), name: rhs.0.clone(),
ty: rhs.1 .0.into_mir(module_id), ty: rhs.1 .0.into_mir(module_id),
meta: rhs.1 .1.as_meta(module_id), meta: rhs.2.as_meta(module_id),
}, },
return_type: return_ty.0.into_mir(module_id), return_type: return_ty.0.into_mir(module_id),
fn_kind: mir::FunctionDefinitionKind::Local( fn_kind: mir::FunctionDefinitionKind::Local(