Migrate namespace defs to resolve module

This commit is contained in:
2026-05-04 19:04:11 -06:00
parent 98ab014603
commit 85f646fc10
3 changed files with 53 additions and 29 deletions

View File

@@ -26,6 +26,7 @@ use crate::{diagnostic::DynDiagnostic, workspace::Workspace};
pub mod ast; pub mod ast;
pub mod diagnostic; pub mod diagnostic;
pub mod editor; pub mod editor;
pub mod resolve;
pub mod workspace; pub mod workspace;
pub mod prelude { pub mod prelude {

View File

@@ -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 <https://www.gnu.org/licenses/>.
use std::collections::BTreeMap;
use salsa::Update;
use crate::prelude::*;
#[salsa::tracked]
pub struct Namespace<'db> {
#[returns(ref)]
pub items: BTreeMap<String, NamespaceItem<'db>>,
}
#[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",
}
}
}

View File

@@ -19,7 +19,7 @@
// TODO: document module // TODO: document module
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::HashMap,
fmt::{Debug, Display}, fmt::{Debug, Display},
ops::Deref, ops::Deref,
str::FromStr, str::FromStr,
@@ -40,34 +40,6 @@ pub struct Workspace {
pub stdlib: HashMap<String, File>, pub stdlib: HashMap<String, File>,
} }
#[salsa::tracked]
pub struct Namespace<'db> {
#[returns(ref)]
pub items: BTreeMap<String, NamespaceItem<'db>>,
}
#[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] #[salsa::input]
#[derive(Debug)] #[derive(Debug)]
pub struct File { pub struct File {