wat_service 0.9.0

WebAssembly Text Format language service.
Documentation
use super::Diagnostic;
use crate::{
    binder::{SymbolKey, SymbolTable},
    document::Document,
    types_analyzer,
};
use rowan::ast::{AstNode, support};
use wat_syntax::{SyntaxNode, ast::Index};

const DIAGNOSTIC_CODE: &str = "start";

pub fn check(
    db: &dyn salsa::Database,
    document: Document,
    symbol_table: &SymbolTable,
    node: &SyntaxNode,
) -> Option<Diagnostic> {
    let index = support::child::<Index>(node)?;
    let index = index.syntax();
    if symbol_table
        .find_def(SymbolKey::new(index))
        .map(|func| types_analyzer::get_func_sig(db, document, func.key, &func.green))
        .is_some_and(|sig| !sig.params.is_empty() || !sig.results.is_empty())
    {
        Some(Diagnostic {
            range: index.text_range(),
            code: DIAGNOSTIC_CODE.into(),
            message: "start function must be type of [] -> []".into(),
            ..Default::default()
        })
    } else {
        None
    }
}