diff --git a/crates/frontend/src/lib.rs b/crates/frontend/src/lib.rs index c4b2fb3..4a98168 100644 --- a/crates/frontend/src/lib.rs +++ b/crates/frontend/src/lib.rs @@ -26,6 +26,7 @@ use crate::{diagnostic::DynDiagnostic, workspace::Workspace}; pub mod ast; pub mod diagnostic; pub mod editor; +pub mod resolve; pub mod workspace; pub mod prelude { diff --git a/crates/frontend/src/resolve.rs b/crates/frontend/src/resolve.rs new file mode 100644 index 0000000..6cdcfdf --- /dev/null +++ b/crates/frontend/src/resolve.rs @@ -0,0 +1,51 @@ +// Copyright (C) 2025-2026 Marceline Cramer +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// This file is part of Kerolox. +// +// Kerolox is free software: you can redistribute it and/or modify it under +// the terms of the GNU Affero General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// Kerolox is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +// more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Kerolox. If not, see . + +use std::collections::BTreeMap; + +use salsa::Update; + +use crate::prelude::*; + +#[salsa::tracked] +pub struct Namespace<'db> { + #[returns(ref)] + pub items: BTreeMap>, +} + +#[derive(Clone, PartialEq, Eq, Hash, Update)] +pub enum NamespaceItem<'db> { + File(workspace::File), + Namespace(Namespace<'db>), + Relation(ast::Relation<'db>), + TypeAlias(ast::TypeAlias<'db>), + Unknown, +} + +impl<'db> NamespaceItem<'db> { + /// Returns a user-readable string identifier for what kind of item this is. + pub fn kind(&self) -> &'static str { + match self { + NamespaceItem::File(_) => "file", + NamespaceItem::Namespace(_) => "namespace", + NamespaceItem::Relation(_) => "relation", + NamespaceItem::TypeAlias(_) => "type alias", + NamespaceItem::Unknown => "unknown", + } + } +} diff --git a/crates/frontend/src/workspace.rs b/crates/frontend/src/workspace.rs index 8797577..e6d732f 100644 --- a/crates/frontend/src/workspace.rs +++ b/crates/frontend/src/workspace.rs @@ -19,7 +19,7 @@ // TODO: document module use std::{ - collections::{BTreeMap, HashMap}, + collections::HashMap, fmt::{Debug, Display}, ops::Deref, str::FromStr, @@ -40,34 +40,6 @@ pub struct Workspace { pub stdlib: HashMap, } -#[salsa::tracked] -pub struct Namespace<'db> { - #[returns(ref)] - pub items: BTreeMap>, -} - -#[derive(Clone, PartialEq, Eq, Hash, Update)] -pub enum NamespaceItem<'db> { - File(File), - Namespace(Namespace<'db>), - Relation(ast::Relation<'db>), - TypeAlias(ast::TypeAlias<'db>), - Unknown, -} - -impl<'db> NamespaceItem<'db> { - /// Returns a user-readable string identifier for what kind of item this is. - pub fn kind(&self) -> &'static str { - match self { - NamespaceItem::File(_) => "file", - NamespaceItem::Namespace(_) => "namespace", - NamespaceItem::Relation(_) => "relation", - NamespaceItem::TypeAlias(_) => "type alias", - NamespaceItem::Unknown => "unknown", - } - } -} - #[salsa::input] #[derive(Debug)] pub struct File {