Skip to content

Commit

Permalink
Add hack_source property to on-hover behavior to allow users to jump …
Browse files Browse the repository at this point in the history
…to type definitions

Reviewed By: ginfung

Differential Revision: D46777141

fbshipit-source-id: 5235b445d6fb3bf83bf73cc40adae3253e15dfb5
  • Loading branch information
Catherine Chen authored and facebook-github-bot committed Jun 22, 2023
1 parent eb29556 commit 4b9cde8
Show file tree
Hide file tree
Showing 35 changed files with 481 additions and 18 deletions.
5 changes: 5 additions & 0 deletions compiler/crates/graphql-syntax/src/node/type_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ impl fmt::Display for TypeSystemDefinition {
repeatable,
locations,
description,
hack_source,
}) => write_directive_definition_helper(
f,
&name.value,
arguments,
repeatable,
locations,
description,
hack_source,
),
TypeSystemDefinition::InputObjectTypeDefinition(InputObjectTypeDefinition {
name,
Expand Down Expand Up @@ -299,6 +301,7 @@ pub struct DirectiveDefinition {
pub repeatable: bool,
pub locations: Vec<DirectiveLocation>,
pub description: Option<StringNode>,
pub hack_source: Option<StringNode>,
}

#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
Expand Down Expand Up @@ -399,6 +402,7 @@ pub struct FieldDefinition {
pub arguments: Option<List<InputValueDefinition>>,
pub directives: Vec<ConstantDirective>,
pub description: Option<StringNode>,
pub hack_source: Option<StringNode>,
}

impl fmt::Display for FieldDefinition {
Expand Down Expand Up @@ -548,6 +552,7 @@ fn write_directive_definition_helper(
_repeatable: &bool,
locations: &[DirectiveLocation],
_description: &Option<StringNode>,
_hack_source: &Option<StringNode>,
) -> fmt::Result {
write!(f, "directive @{}", name)?;
if let Some(arguments) = arguments.as_ref() {
Expand Down
28 changes: 27 additions & 1 deletion compiler/crates/graphql-syntax/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ impl<'a> Parser<'a> {
/// [] TypeSystemExtension
fn parse_type_system_definition(&mut self) -> ParseResult<TypeSystemDefinition> {
let description = self.parse_optional_description();
let hack_source = self.parse_optional_hack_source();
let token = self.peek();
if token.kind != TokenKind::Identifier {
// TODO
Expand Down Expand Up @@ -401,7 +402,7 @@ impl<'a> Parser<'a> {
self.parse_input_object_type_definition()?,
)),
"directive" => Ok(TypeSystemDefinition::DirectiveDefinition(
self.parse_directive_definition(description)?,
self.parse_directive_definition(description, hack_source)?,
)),
"extend" => self.parse_type_system_extension(),
token_str => {
Expand Down Expand Up @@ -793,6 +794,7 @@ impl<'a> Parser<'a> {
fn parse_directive_definition(
&mut self,
description: Option<StringNode>,
hack_source: Option<StringNode>,
) -> ParseResult<DirectiveDefinition> {
self.parse_keyword("directive")?;
self.parse_kind(TokenKind::At)?;
Expand All @@ -811,6 +813,7 @@ impl<'a> Parser<'a> {
repeatable,
locations,
description,
hack_source,
})
}

Expand Down Expand Up @@ -910,6 +913,27 @@ impl<'a> Parser<'a> {
}
}

/**
* hack_source : StringValue
*/
fn parse_optional_hack_source(&mut self) -> Option<StringNode> {
match self.peek_token_kind() {
TokenKind::StringLiteral => {
let token = self.parse_token();
let source = self.source(&token);
let value = source[1..source.len() - 1].to_string().intern();
Some(StringNode { token, value })
}
TokenKind::BlockStringLiteral => {
let token = self.parse_token();
let source = self.source(&token);
let value = clean_block_string_literal(source).intern();
Some(StringNode { token, value })
}
_ => None,
}
}

/**
* FieldsDefinition : { FieldDefinition+ }
*/
Expand All @@ -927,6 +951,7 @@ impl<'a> Parser<'a> {
*/
fn parse_field_definition_impl(&mut self) -> ParseResult<FieldDefinition> {
let description = self.parse_optional_description();
let hack_source = self.parse_optional_hack_source();
let name = self.parse_identifier()?;
let arguments = self.parse_argument_defs()?;
self.parse_kind(TokenKind::Colon)?;
Expand All @@ -938,6 +963,7 @@ impl<'a> Parser<'a> {
arguments,
directives,
description,
hack_source,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Document {
arguments: None,
directives: [],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SchemaDocument {
value: "My Directive",
},
),
hack_source: None,
},
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ SchemaDocument {
value: "Single line field description",
},
),
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -115,6 +116,7 @@ SchemaDocument {
value: "Block field description",
},
),
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -148,6 +150,7 @@ SchemaDocument {
value: "Multiline block field description which is so long\nthat it spans onto a second line.",
},
),
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -210,6 +213,7 @@ SchemaDocument {
value: "Single line extended field description",
},
),
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -243,6 +247,7 @@ SchemaDocument {
value: "Block field description",
},
),
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -276,6 +281,7 @@ SchemaDocument {
value: "Multiline block field description which is so long\nthat it spans onto a second line.",
},
),
hack_source: None,
},
],
end: Token {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ SchemaDocument {
value: "Description of the `one` field.",
},
),
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -358,6 +359,7 @@ SchemaDocument {
value: "This is a description of the `two` field.",
},
),
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -453,6 +455,7 @@ SchemaDocument {
value: "This is a description of the `three` field.",
},
),
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -526,6 +529,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -636,6 +640,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -739,6 +744,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -809,6 +815,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -1000,6 +1007,7 @@ SchemaDocument {
},
],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -1120,6 +1128,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -1206,6 +1215,7 @@ SchemaDocument {
arguments: None,
directives: [],
description: None,
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -1279,6 +1289,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -1422,6 +1433,7 @@ SchemaDocument {
},
],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -1547,6 +1559,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -1650,6 +1663,7 @@ SchemaDocument {
arguments: None,
directives: [],
description: None,
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -1722,6 +1736,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -1795,6 +1810,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -2714,6 +2730,7 @@ SchemaDocument {
value: "This is a description of the `@skip` directive",
},
),
hack_source: None,
},
),
DirectiveDefinition(
Expand Down Expand Up @@ -2781,6 +2798,7 @@ SchemaDocument {
InlineFragment,
],
description: None,
hack_source: None,
},
),
DirectiveDefinition(
Expand Down Expand Up @@ -2848,6 +2866,7 @@ SchemaDocument {
InlineFragment,
],
description: None,
hack_source: None,
},
),
DirectiveDefinition(
Expand Down Expand Up @@ -2914,6 +2933,7 @@ SchemaDocument {
Interface,
],
description: None,
hack_source: None,
},
),
SchemaExtension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ SchemaDocument {
arguments: None,
directives: [],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down Expand Up @@ -211,6 +212,7 @@ SchemaDocument {
arguments: None,
directives: [],
description: None,
hack_source: None,
},
FieldDefinition {
name: Identifier {
Expand Down Expand Up @@ -283,6 +285,7 @@ SchemaDocument {
),
directives: [],
description: None,
hack_source: None,
},
],
end: Token {
Expand Down
Loading

0 comments on commit 4b9cde8

Please sign in to comment.