Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SchemaDocument go to definition LSP support #4669

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/crates/relay-lsp/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DefinitionDescription> {
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,
Expand Down
Loading