forked from Orchid/orchid
temp commit
This commit is contained in:
@@ -4,11 +4,21 @@ use std::num::NonZeroU64;
|
||||
use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_traits::Request;
|
||||
|
||||
use crate::{HostExtReq, OrcResult, SysId, TStr, TStrv, TokenTree};
|
||||
use crate::{
|
||||
Expression, ExtHostReq, HostExtReq, OrcResult, SourceRange, SysId, TStr, TStrv, TokenTree,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
||||
pub struct ParsId(pub NonZeroU64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
||||
pub struct ParsedConstId(pub NonZeroU64);
|
||||
|
||||
/// Parse a single source line. Return values can be modules, constants, or
|
||||
/// token sequences for re-parsing. These re-parsed token sequences can also
|
||||
/// represent raw language items such as modules, imports, and const. This is
|
||||
/// how we enable generating imports without forcing import syntax to affect API
|
||||
/// versioning
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(HostExtReq)]
|
||||
pub struct ParseLine {
|
||||
@@ -23,7 +33,46 @@ pub struct ParseLine {
|
||||
pub line: Vec<TokenTree>,
|
||||
}
|
||||
impl Request for ParseLine {
|
||||
type Response = OrcResult<Vec<TokenTree>>;
|
||||
type Response = OrcResult<Vec<ParsedLine>>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub struct ParsedLine {
|
||||
pub comments: Vec<Comment>,
|
||||
pub source_range: SourceRange,
|
||||
pub kind: ParsedLineKind,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub enum ParsedLineKind {
|
||||
Recursive(Vec<TokenTree>),
|
||||
Member(ParsedMember),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub struct ParsedMember {
|
||||
pub name: TStr,
|
||||
pub exported: bool,
|
||||
pub kind: ParsedMemberKind,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub enum ParsedMemberKind {
|
||||
Constant(ParsedConstId),
|
||||
Module(Vec<ParsedLine>),
|
||||
}
|
||||
|
||||
/// Obtain the value of a parsed constant. This is guaranteed to be called after
|
||||
/// the last [ParseLine] but before any [crate::AtomReq]. As such, in principle
|
||||
/// the macro engine could run here.
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(HostExtReq)]
|
||||
pub struct FetchParsedConst {
|
||||
pub sys: SysId,
|
||||
pub id: ParsedConstId,
|
||||
}
|
||||
impl Request for FetchParsedConst {
|
||||
type Response = Expression;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
@@ -31,3 +80,25 @@ pub struct Comment {
|
||||
pub text: TStr,
|
||||
pub range: Range<u32>,
|
||||
}
|
||||
|
||||
/// Resolve relative names from the perspective of a constant. This can only be
|
||||
/// called during a [FetchParsedConst] call, but it can be called for a
|
||||
/// different [ParsedConstId] from the one in [FetchParsedConst].
|
||||
///
|
||||
/// Each name is either resolved to an alias or existing constant `Some(TStrv)`
|
||||
/// or not resolved `None`. An error is never raised, as names may have a
|
||||
/// primary meaning such as a local binding which can be overridden by specific
|
||||
/// true names such as those triggering macro keywords. It is not recommended to
|
||||
/// define syntax that can break by defining arbitrary constants, as line
|
||||
/// parsers can define new ones at will.
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(ExtHostReq)]
|
||||
pub struct ResolveNames {
|
||||
pub sys: SysId,
|
||||
pub constid: ParsedConstId,
|
||||
pub names: Vec<TStrv>,
|
||||
}
|
||||
|
||||
impl Request for ResolveNames {
|
||||
type Response = Vec<Option<TStrv>>;
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ pub enum ExtHostReq {
|
||||
ExprReq(expr::ExprReq),
|
||||
SubLex(lexer::SubLex),
|
||||
LsModule(tree::LsModule),
|
||||
ResolveNames(parser::ResolveNames),
|
||||
}
|
||||
|
||||
/// Notifications sent from the extension to the host
|
||||
@@ -117,8 +118,9 @@ pub enum HostExtReq {
|
||||
DeserAtom(atom::DeserAtom),
|
||||
LexExpr(lexer::LexExpr),
|
||||
ParseLine(parser::ParseLine),
|
||||
FetchParsedConst(parser::FetchParsedConst),
|
||||
GetMember(tree::GetMember),
|
||||
VfsReq(vfs::VfsReq),
|
||||
VfsRead(vfs::VfsRead),
|
||||
}
|
||||
|
||||
/// Notifications sent from the host to the extension
|
||||
|
||||
@@ -5,7 +5,7 @@ use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_traits::Request;
|
||||
use ordered_float::NotNan;
|
||||
|
||||
use crate::{CharFilter, ExtHostReq, HostExtNotif, HostExtReq, MemberKind, TStr};
|
||||
use crate::{CharFilter, EagerVfs, ExtHostReq, HostExtNotif, HostExtReq, MemberKind, TStr};
|
||||
|
||||
/// ID of a system type
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
||||
@@ -63,6 +63,7 @@ pub struct NewSystemResponse {
|
||||
pub lex_filter: CharFilter,
|
||||
pub line_types: Vec<TStr>,
|
||||
pub const_root: HashMap<TStr, MemberKind>,
|
||||
pub vfs: HashMap<TStr, EagerVfs>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
|
||||
@@ -72,7 +72,6 @@ pub struct Member {
|
||||
pub enum MemberKind {
|
||||
Const(Expression),
|
||||
Module(Module),
|
||||
Import(TStrv),
|
||||
Lazy(TreeId),
|
||||
}
|
||||
|
||||
@@ -105,10 +104,10 @@ pub enum LsModuleError {
|
||||
TreeUnavailable,
|
||||
}
|
||||
|
||||
/// Information about a module sent from the host to an extension. By necessity,
|
||||
/// members and imports are non-overlapping.
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub struct ModuleInfo {
|
||||
/// If the name isn't a canonical name, returns the true name.
|
||||
pub canonical: Option<TStrv>,
|
||||
/// List the names defined in this module
|
||||
pub members: HashMap<TStr, MemberInfo>,
|
||||
}
|
||||
@@ -116,9 +115,7 @@ pub struct ModuleInfo {
|
||||
#[derive(Clone, Copy, Debug, Coding)]
|
||||
pub struct MemberInfo {
|
||||
/// true if the name is exported
|
||||
pub exported: bool,
|
||||
/// If it's imported, you can find the canonical name here
|
||||
pub canonical: Option<TStrv>,
|
||||
pub public: bool,
|
||||
/// Whether the tree item is a constant value or a module
|
||||
pub kind: MemberInfoKind,
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub enum Loaded {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(VfsReq, HostExtReq)]
|
||||
#[extends(HostExtReq)]
|
||||
pub struct VfsRead(pub SysId, pub VfsId, pub Vec<TStr>);
|
||||
impl Request for VfsRead {
|
||||
type Response = OrcResult<Loaded>;
|
||||
@@ -30,18 +30,3 @@ pub enum EagerVfs {
|
||||
Lazy(VfsId),
|
||||
Eager(HashMap<TStr, EagerVfs>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(VfsReq, HostExtReq)]
|
||||
pub struct GetVfs(pub SysId);
|
||||
impl Request for GetVfs {
|
||||
type Response = EagerVfs;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(HostExtReq)]
|
||||
#[extendable]
|
||||
pub enum VfsReq {
|
||||
GetVfs(GetVfs),
|
||||
VfsRead(VfsRead),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user