use rowan::ast::{AstNode, AstPtr};

use crate::Lang;

use super::FileId;

#[derive(Clone)]
pub struct Loc<N: AstNode<Language = Lang>> {
    file: FileId,
    syntax: AstPtr<N>,
}

impl<N: AstNode<Language = Lang>> Loc<N> {
    pub fn new(node: N, file: FileId) -> Self {
        Self::from_ptr(AstPtr::new(&node), file)
    }

    pub fn from_ptr(ptr: AstPtr<N>, file: FileId) -> Self {
        Self { file, syntax: ptr }
    }

    pub fn file(&self) -> FileId {
        self.file
    }

    pub fn syntax(&self) -> AstPtr<N> {
        self.syntax.clone()
    }
}
