diff --git a/crates/common_lang_types/src/location.rs b/crates/common_lang_types/src/location.rs index 1ee27d81..b4a46714 100644 --- a/crates/common_lang_types/src/location.rs +++ b/crates/common_lang_types/src/location.rs @@ -33,14 +33,14 @@ impl RelativeTextSource { } #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct EmbeddedLocation { +pub struct EmbeddedRelativeLocation { pub text_source: RelativeTextSource, /// The span is relative to the Source's span, not to the /// entire source file. pub span: Span, } -impl std::fmt::Display for EmbeddedLocation { +impl std::fmt::Display for EmbeddedRelativeLocation { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (file_path, read_out_text) = self.text_source.read_to_string(); let text_with_carats = text_with_carats(&read_out_text, self.span); @@ -49,15 +49,15 @@ impl std::fmt::Display for EmbeddedLocation { } } -impl From for Location { - fn from(value: EmbeddedLocation) -> Self { +impl From for Location { + fn from(value: EmbeddedRelativeLocation) -> Self { Location::Embedded(value) } } #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] pub enum Location { - Embedded(EmbeddedLocation), + Embedded(EmbeddedRelativeLocation), Generated, } @@ -66,7 +66,7 @@ impl Location { Location::Generated } pub fn new(text_source: RelativeTextSource, span: Span) -> Self { - Location::Embedded(EmbeddedLocation::new(text_source, span)) + Location::Embedded(EmbeddedRelativeLocation::new(text_source, span)) } pub fn span(&self) -> Option { @@ -76,9 +76,9 @@ impl Location { } } } -impl EmbeddedLocation { +impl EmbeddedRelativeLocation { pub fn new(text_source: RelativeTextSource, span: Span) -> Self { - EmbeddedLocation { text_source, span } + EmbeddedRelativeLocation { text_source, span } } } @@ -131,7 +131,7 @@ impl WithLocation { /// EmbeddedLocation or WithEmbeddedLocation pub fn hack_to_with_span(self) -> WithSpan { let span = match self.location { - Location::Embedded(EmbeddedLocation { span, .. }) => span, + Location::Embedded(EmbeddedRelativeLocation { span, .. }) => span, Location::Generated => Span::todo_generated(), }; WithSpan { @@ -142,38 +142,41 @@ impl WithLocation { } #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd)] -pub struct WithEmbeddedLocation { - pub location: EmbeddedLocation, +pub struct WithEmbeddedRelativeLocation { + pub location: EmbeddedRelativeLocation, pub item: T, } -impl Error for WithEmbeddedLocation { +impl Error for WithEmbeddedRelativeLocation { fn description(&self) -> &str { #[allow(deprecated)] self.item.description() } } -impl fmt::Display for WithEmbeddedLocation { +impl fmt::Display for WithEmbeddedRelativeLocation { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}\n{}", self.item, self.location) } } -impl WithEmbeddedLocation { - pub fn new(item: T, location: EmbeddedLocation) -> Self { - WithEmbeddedLocation { item, location } +impl WithEmbeddedRelativeLocation { + pub fn new(item: T, location: EmbeddedRelativeLocation) -> Self { + WithEmbeddedRelativeLocation { item, location } } - pub fn map(self, map: impl FnOnce(T) -> U) -> WithEmbeddedLocation { - WithEmbeddedLocation::new(map(self.item), self.location) + pub fn map(self, map: impl FnOnce(T) -> U) -> WithEmbeddedRelativeLocation { + WithEmbeddedRelativeLocation::new(map(self.item), self.location) } pub fn and_then( self, map: impl FnOnce(T) -> Result, - ) -> Result, E> { - Ok(WithEmbeddedLocation::new(map(self.item)?, self.location)) + ) -> Result, E> { + Ok(WithEmbeddedRelativeLocation::new( + map(self.item)?, + self.location, + )) } pub fn into_with_location(self) -> WithLocation { @@ -181,8 +184,8 @@ impl WithEmbeddedLocation { } } -impl From> for WithLocation { - fn from(value: WithEmbeddedLocation) -> Self { +impl From> for WithLocation { + fn from(value: WithEmbeddedRelativeLocation) -> Self { WithLocation { location: Location::Embedded(value.location), item: value.item, diff --git a/crates/common_lang_types/src/span.rs b/crates/common_lang_types/src/span.rs index d6dc2f55..a67a0f4e 100644 --- a/crates/common_lang_types/src/span.rs +++ b/crates/common_lang_types/src/span.rs @@ -1,6 +1,9 @@ use std::{fmt, ops::Range}; -use crate::{EmbeddedLocation, Location, RelativeTextSource, WithEmbeddedLocation, WithLocation}; +use crate::{ + EmbeddedRelativeLocation, Location, RelativeTextSource, WithEmbeddedRelativeLocation, + WithLocation, +}; // Invariant: end >= start #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] @@ -105,8 +108,14 @@ impl WithSpan { WithLocation::new(self.item, Location::new(text_source, self.span)) } - pub fn to_with_embedded_location(self, text_source: RelativeTextSource) -> WithEmbeddedLocation { - WithEmbeddedLocation::new(self.item, EmbeddedLocation::new(text_source, self.span)) + pub fn to_with_embedded_location( + self, + text_source: RelativeTextSource, + ) -> WithEmbeddedRelativeLocation { + WithEmbeddedRelativeLocation::new( + self.item, + EmbeddedRelativeLocation::new(text_source, self.span), + ) } } diff --git a/crates/graphql_lang_types/src/directive.rs b/crates/graphql_lang_types/src/directive.rs index 378d2dcc..30857d9d 100644 --- a/crates/graphql_lang_types/src/directive.rs +++ b/crates/graphql_lang_types/src/directive.rs @@ -2,7 +2,7 @@ use std::fmt; use super::{write::write_arguments, NameValuePair}; use crate::GraphQLConstantValue; -use common_lang_types::{DirectiveArgumentName, DirectiveName, WithEmbeddedLocation}; +use common_lang_types::{DirectiveArgumentName, DirectiveName, WithEmbeddedRelativeLocation}; use intern::Lookup; use serde::{ de::{self, value::SeqDeserializer, IntoDeserializer, MapAccess}, @@ -13,7 +13,7 @@ use thiserror::Error; // TODO maybe this should be NameAndArguments and a field should be the same thing...? #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct GraphQLDirective { - pub name: WithEmbeddedLocation, + pub name: WithEmbeddedRelativeLocation, pub arguments: Vec>, }