A VSCode extension that provides intelligent navigation from Redux Toolkit Query (RTK Query) auto-generated hooks directly to their endpoint definitions using both CodeLens annotations and "Go to Definition" functionality.
When working with RTK Query, hooks are automatically generated from endpoint definitions. This extension bridges the gap by providing two navigation methods:
- CodeLens Annotations: Clickable annotations above hook names showing
โ endpointName - Go to Definition: Standard VSCode navigation (F12, Ctrl+Click) from hooks to endpoints
- Smart CodeLens Detection: Automatically detects RTK Query hook destructuring patterns and adds clickable annotations
- Go to Definition Support: Navigate from exported hooks to their endpoint definitions with F12 or Ctrl+Click
- Multiple Format Support: Handles all common RTK Query export patterns (single-line, multi-line)
- TypeScript Support: Works seamlessly with TypeScript files
- Zero Configuration: Works out of the box with standard RTK Query patterns
- Pattern Recognition: Supports
useXxxQuery,useXxxMutation, anduseLazyXxxQueryformats
The extension analyzes your TypeScript files and provides two navigation methods:
Adds clickable CodeLens annotations above RTK Query hook names. Each annotation shows โ endpointName and clicking it navigates to the corresponding builder.query or builder.mutation definition.
Implements VSCode's DefinitionProvider to enable standard "Go to Definition" functionality for RTK Query hooks, allowing Ctrl+Click or F12 navigation.
The extension intelligently converts hook names to endpoint names:
| Hook Name | Endpoint Name |
|---|---|
useGetPokemonByNameQuery |
getPokemonByName |
useCreateUserMutation |
createUser |
useLazyFetchPostsQuery |
fetchPosts |
// CodeLens: โ getPokemonByName
export const { useGetPokemonByNameQuery } = pokemonApiexport const {
// CodeLens: โ getPokemonByName
useGetPokemonByNameQuery,
// CodeLens: โ createUser
useCreateUserMutation,
// CodeLens: โ fetchPosts
useLazyFetchPostsQuery
} = apiexport const {
// CodeLens: โ getPokemonByName
useGetPokemonByNameQuery,
// CodeLens: โ createUser
useCreateUserMutation,
// CodeLens: โ fetchPosts
useLazyFetchPostsQuery } = api- Main extension activation and registration
- Registers both CodeLens provider and DefinitionProvider for TypeScript files
- Handles navigation commands
- Implements VSCode's
DefinitionProviderinterface for "Go to Definition" functionality - Detects RTK Query hook patterns and resolves to endpoint locations
- Implements VSCode's
CodeLensProviderinterface - Creates CodeLens annotations with endpoint names
- Converts hook names to endpoint names using regex patterns
- Handles
useXxxQuery,useXxxMutation, anduseLazyXxxQueryformats - Converts PascalCase to camelCase
- Searches for endpoint definitions in the current document
- Uses regex to find
endpointName: builder.(query|mutation)patterns - Returns VSCode Location for navigation
- Install the extension from VSCode Marketplace
- Open any TypeScript file containing RTK Query slices
- Enable CodeLens: Go to VSCode settings โ Search for "CodeLens" โ Ensure "Editor: Code Lens" is enabled
- Look for CodeLens annotations above hook names (shows
โ endpointName) - Click the annotation to navigate to the endpoint definition
- Ctrl+Click (or Cmd+Click on Mac) on any exported hook name
- Press F12 while cursor is on a hook name
- Right-click and select "Go to Definition"
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
export const pokemonApi = createApi({
reducerPath: 'pokemonApi',
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
endpoints: (builder) => ({
// โ Navigation targets here
getPokemonByName: builder.query<Pokemon, string>({
query: (name) => `pokemon/${name}`,
}),
createPokemon: builder.mutation<Pokemon, Partial<Pokemon>>({
query: (pokemon) => ({
url: 'pokemon',
method: 'POST',
body: pokemon,
}),
}),
}),
})
// CodeLens annotations appear above each hook
// Go to Definition works on hook names below
export const {
useGetPokemonByNameQuery, // โ getPokemonByName
useCreatePokemonMutation, // โ createPokemon
} = pokemonApi- VSCode: ^1.90.0
- TypeScript: Files must be TypeScript (.ts, .tsx)
- RTK Query: Standard RTK Query patterns and naming conventions
- CodeLens: Must be enabled in VSCode settings for CodeLens features
/^use(Lazy)?([A-Z][a-zA-Z0-9]*)(Query|Mutation)$//^\s*endpointName\s*:\s*builder\.(query|mutation)\s*[<(]/- Single-line:
/^\s*export\s+const\s*\{\s*([^}]+)\s*\}\s*=\s*(\w+)\s*;?\s*$/ - Multi-line start:
/^\s*export\s+const\s*\{\s*$/ - Multi-line end:
/\}\s*=\s*(\w+)\s*;?\s*$/
- Node.js
- pnpm
# Install dependencies
pnpm install
# Compile TypeScript
pnpm run compile
# Run in development mode
# Press F5 in VSCode to launch extension development hostpnpm run compile # Build the extension
pnpm run watch # Watch mode for development
pnpm run package # Package for publishing
pnpm run test # Run tests- Large RTK Query slices with many endpoints
- Team collaboration where hook usage and definitions are in different parts of files
- Code reviews to quickly understand hook-to-endpoint relationships
- Refactoring to locate endpoint definitions from hook usage
- Only works within the same file (doesn't follow imports across files)
- Requires standard RTK Query naming conventions
- Works with
injectEndpointsandcreateApipatterns only - CodeLens annotations may not appear if CodeLens is disabled
- Cross-file navigation (hooks imported from other files)
- Support for custom RTK Query naming conventions
- Integration with RTK Query devtools
- Reverse navigation (endpoint โ hooks)
- Configuration options for custom patterns
- Initial release
- CodeLens navigation support
- Go to Definition support
- TypeScript file support
- Standard RTK Query pattern recognition
Contributions are welcome! Please ensure your code follows the existing patterns and includes appropriate TypeScript types.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details
Made with โค๏ธ for the RTK Query community



