diff --git a/compiler/crates/relay-lsp/src/goto_definition.rs b/compiler/crates/relay-lsp/src/goto_definition.rs index b1d9e7564602f..91df1882926a8 100644 --- a/compiler/crates/relay-lsp/src/goto_definition.rs +++ b/compiler/crates/relay-lsp/src/goto_definition.rs @@ -31,6 +31,7 @@ use serde::Serialize; use self::goto_docblock_definition::get_docblock_definition_description; use self::goto_graphql_definition::get_graphql_definition_description; +use self::goto_graphql_definition::get_graphql_schema_definition_description; use crate::location::transform_relay_location_on_disk_to_lsp_location; use crate::lsp_runtime_error::LSPRuntimeError; use crate::lsp_runtime_error::LSPRuntimeResult; @@ -85,7 +86,9 @@ pub fn on_goto_definition( crate::Feature::DocblockIr(docblock_ir) => { get_docblock_definition_description(&docblock_ir, position_span)? } - crate::Feature::SchemaDocument(_) => Err(LSPRuntimeError::ExpectedError)?, + crate::Feature::SchemaDocument(document) => { + get_graphql_schema_definition_description(document, position_span)? + } }; let extra_data_provider = state.get_extra_data_provider(); diff --git a/compiler/crates/relay-lsp/src/goto_definition/goto_graphql_definition.rs b/compiler/crates/relay-lsp/src/goto_definition/goto_graphql_definition.rs index 08cabcf61790d..d8d3f70d98d7e 100644 --- a/compiler/crates/relay-lsp/src/goto_definition/goto_graphql_definition.rs +++ b/compiler/crates/relay-lsp/src/goto_definition/goto_graphql_definition.rs @@ -12,9 +12,13 @@ use common::DirectiveName; use common::Span; use graphql_ir::FragmentDefinitionName; use graphql_syntax::ExecutableDocument; +use graphql_syntax::SchemaDocument; use intern::string_key::StringKey; use resolution_path::ArgumentParent; use resolution_path::ArgumentPath; +use resolution_path::ConstantArgumentParent; +use resolution_path::ConstantArgumentPath; +use resolution_path::ConstantDirectivePath; use resolution_path::DirectivePath; use resolution_path::IdentParent; use resolution_path::IdentPath; @@ -30,6 +34,54 @@ use super::DefinitionDescription; use crate::lsp_runtime_error::LSPRuntimeError; use crate::lsp_runtime_error::LSPRuntimeResult; +pub fn get_graphql_schema_definition_description( + document: SchemaDocument, + position_span: Span, +) -> LSPRuntimeResult { + let node_path = document.resolve((), position_span); + + match node_path { + ResolutionPath::Ident(IdentPath { + inner: type_name, + parent: + IdentParent::NamedTypeAnnotation(_) + | IdentParent::UnionTypeMemberType(_) + | IdentParent::ImplementedInterfaceName(_) + | IdentParent::OperationTypeDefinitionType(_) + | IdentParent::InputObjectTypeExtensionName(_) + | IdentParent::ObjectTypeExtensionName(_) + | IdentParent::InterfaceTypeExtensionName(_) + | IdentParent::UnionTypeExtensionName(_) + | IdentParent::EnumTypeExtensionName(_) + | IdentParent::ScalarTypeExtensionName(_), + }) => Ok(DefinitionDescription::Type { + type_name: type_name.value, + }), + ResolutionPath::Ident(IdentPath { + inner: directive_name, + parent: IdentParent::ConstantDirectiveName(_), + }) => Ok(DefinitionDescription::Directive { + directive_name: DirectiveName(directive_name.value), + }), + ResolutionPath::Ident(IdentPath { + inner: argument_name, + parent: + IdentParent::ConstantArgumentKey(ConstantArgumentPath { + inner: _, + parent: + ConstantArgumentParent::ConstantDirective(ConstantDirectivePath { + inner: directive, + .. + }), + }), + }) => Ok(DefinitionDescription::DirectiveArgument { + directive_name: DirectiveName(directive.name.value), + argument_name: ArgumentName(argument_name.value), + }), + _ => Err(LSPRuntimeError::ExpectedError), + } +} + pub fn get_graphql_definition_description( document: ExecutableDocument, position_span: Span,