feat: add GraphQL operations and fragments to the outline (navigation tree) - #410
Open
JoviDeCroock wants to merge 1 commit into
Open
feat: add GraphQL operations and fragments to the outline (navigation tree)#410JoviDeCroock wants to merge 1 commit into
JoviDeCroock wants to merge 1 commit into
Conversation
Implements a getNavigationTree proxy that parses every GraphQL document in a file (both call-expression and tagged-template mode) and appends a navigation item per operation or fragment definition to the deepest existing navigation tree node containing the document. This powers the Outline view, breadcrumbs, and in-file symbol navigation in editors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 71f9f24 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What/Why
GraphQL documents embedded in TypeScript files were invisible to editor outline features. This PR proxies
getNavigationTreeso every GraphQL operation and fragment shows up in VS Code's Outline view, breadcrumbs, and in-file symbol navigation (Cmd+Shift+O), e.g.query NavPokemons,query (anonymous), andfragment pokemonFields on Pokemon.Implementation notes
packages/graphqlsp/src/navigationTree.ts, wired into the language-service proxy inindex.tsusing the existingguard()pattern — on any error the original navigation tree is returned unchanged.graphql()/gql(), viafindAllCallExpressions) and tagged templates (viafindAllTaggedTemplateNodes+resolveTemplate). Unparseable documents are skipped (parsein try/catch).NavigationTreenode (ScriptElementKind.constElement) with spans mapped from GraphQL ASTlocoffsets to TS file positions (document text start = literal start + 1, matchingdefinition.ts). For tagged templates with interpolations, offsets after an interpolation are re-mapped throughresolveTemplate's resolved spans; definitions that live entirely inside an interpolated (external) fragment are skipped since they have no text in the file.childItemsof the deepest existing navigation tree node whose span contains the document, so they nest under the containing variable/function; existing nodes are otherwise untouched.Test plan
test/e2e/navigation-tree.test.tsagainstfixture-project-tadausing the tsservernavtreecommand, asserting text, kind, parent nesting, and exact line/offset spans (includingnameSpan) for a named query, an anonymous query, and a fragment.pnpm --filter @0no-co/graphqlsp run buildpasses, and the fullpnpm run test:e2esuite is green: 12 test files, 55 tests passed (3 new).unused-fieds,tada,multi-schema-tada) are timing-flaky when the whole suite runs; they also fail intermittently onmainwith identical snapshot mismatches and pass consistently in isolation and in the final full-suite run of this branch.🤖 Generated with Claude Code