Poly symbols

From JetBrains/intellij-community · View interactive version

Poly symbols is an AI agent skill from the GitHub repository JetBrains/intellij-community. Implement PolySymbols completion, references, rename, and PolyContext feature gating.

How to use this skill

Skill file

PolySymbols

PolySymbols is a framework built on top of the platform's Symbol API

(PolySymbol : Symbol) for sharing symbol definitions and code-insight features (completion,

references, documentation, navigation, rename, find-usages, semantic highlighting) across

languages and frameworks. It was called "Web Symbols" in 2022.3–2025.1 and is still marked

experimental. Core modules: community/platform/polySymbols/ (shared, backend, web).

Do not modify PolySymbols platform source

**Never edit anything under community/platform/polySymbols/** without the user's explicit,

one-time permission for that specific change** — not even a small, purely-additive generalization

that looks obviously safe. This is shared framework code consumed by every PolySymbols integration

in the repo (Angular, Vue, CSS, JS, GDScript, etc.); a "safe-looking" generalization made to

fix one integration's test can silently change behavior for all the others. If you hit a real gap or

limitation in platform behavior while integrating a language/framework, the default response is to

report it and ask, not to patch the platform — the right fix is almost always something owned by

your own plugin (a plugin-registered EP implementation, e.g. its own UsageSearcher/

RenameUsageSearcher/CustomUsageSearcher, not a platform-file edit).

Consumer code must not cast to a concrete symbol class

*Code that consumes* PolySymbols (annotators, inspections, completion/line-marker/parameter-info

providers, and a language integration's own customizers/scopes, not just downstream callers)

should never cast a PolySymbol to a concrete implementation class to detect its kind or read its

data.** PolySymbol.kt documents this in its "## Properties" doc comment: a query may return

symbols of unexpected classes contributed by some 3rd party plugins.

available on the plain PolySymbol interface. Never is ConcreteLeafSymbolClass.

kind) → define a PolySymbolProperty<T> object and annotate the concrete class's real member

with @PolySymbol.Property(TheProperty::class), then read it via symbol[TheProperty] (the

PolySymbol.get operator) — never (symbol as? ConcreteLeafSymbolClass)?.someMember.

symbol.xxx and never see the property object or a cast at all — mirror

plugins/JavaScriptLanguage/web-platform/src/com/intellij/polySymbols/js/JSSymbolUtils.kt's

PolySymbol.jsType/jsKind/toPropertySignature, the reference example cited in PolySymbol.kt

itself. Note toPropertySignature's fallback branch (when the property is absent) builds its

result purely from other plain PolySymbol members (name, modifiers, jsType) — it never

casts, not even as a fallback.

symbol kinds. Example: GDScript's GdClassSymbol exposes directMemberScope/

resolveSuperClassSymbol() identically from both PSI- and SDK-backed class symbols. The

anti-pattern is casting to a leaf class (GdPsiMethodSymbol, GdSdkClassSymbol) or a

backing-specific base (GdPsiPolySymbol vs. GdSdkPolySymbol) from outside the

symbol-definition package.

PolySymbolPropertyGetter finds a @PolySymbol.Property-annotated member that a shared

abstract base class declares once, for every subclass. The same applies to a subclass override

with a covariant return type. You don't need to repeat the annotation on every leaf subclass when

the member is inherited unchanged.

Interface cheat sheet

| Interface / class | Purpose |

|---|---|

| PolySymbol | Core element — kind (namespace + kindName) + name, plus optional icon/priority/modifiers/apiStatus |

| PolySymbolScope | A symbol that contains other symbols (an HTML element containing attributes, a JS class containing members) |

| PolySymbolQueryExecutor / Factory | Runs nameMatchQuery/listSymbolsQuery/codeCompletionQuery against contributed scopes |

| PolySymbolQueryScopeContributor | Registers PolySymbolScopes for a PSI location — the main extension point you implement |

| PolySymbolQueryConfigurator | Supplies PolyContext rules + symbol name-conversion rules |

| PsiPolySymbolReferenceProvider | Resolves a host PsiElement to a referenced PolySymbol — registered via EP, produces external references |

| PolySymbolOwnReferences | Alternative to PsiPolySymbolReferenceProvider: builds the result of PsiElement.getOwnReferences(), a language's own canonical resolve with no EP |

| PolySymbolDeclarationProvider | Supplies PolySymbolDeclarations for a PsiElement (skip if PsiLinkedPolySymbol covers your case) |

| PolySymbolsCompletionProviderBase | Base class for a CompletionProvider that runs a codeCompletionQuery |

| PolySymbolWithPattern | A symbol expanded via a microsyntax pattern into a PolySymbolMatch |

| PsiLinkedPolySymbol | A symbol backed 1:1 by a real PsiElement — gets declarations/navigation/find-usages "for free" |

| ReferencingPolySymbol | Utility: makes one symbol kind stand in for/alias another kind |

| PolyContext | Gates scopes/configurators. A general-purpose context API: see PolyContext |

| Web Types | Static JSON symbol definitions — see references/web-types.md |

The rule: PolySymbols is additive, not automatically authoritative

**Every real integration studied in this repo keeps legacy PSI-based reference/completion code

running alongside PolySymbols. None resolves entirely through it.** See the

case studies below.

Actionable takeaway: for every new integration or feature, decide explicitly whether

PolySymbols is the resolution path of record for that PSI element/feature, or merely a

supplementary layer contributing extra symbols on top of an existing mechanism. If a legacy

PsiReferenceContributor/CompletionContributor and a new PolySymbols registration can both fire

on the same host PsiElement, either gate one off (a feature flag, a context check, an early

return null/empty-list from whichever should defer) or accept and document the overlap — don't

assume the platform will pick one for you.

Wiring checklist — adding PolySymbol support

  1. Opt the language in: register polySymbols.enableInLanguage language="..." (EP

com.intellij.polySymbols.enableInLanguage) so PsiExternalReferenceHosts in that language are

eligible for PolySymbols reference resolution at all.

  1. Contribute scopes: implement PolySymbolQueryScopeContributor

(EP com.intellij.polySymbols.queryScopeContributor) — map PSI locations to PolySymbolScopes

via the registrar DSL. Details: references/query-model.md.

  1. Resolve references: implement PsiPolySymbolReferenceProvider per host PsiElement type

(EP com.intellij.polySymbols.psiReferenceProvider, one registration per hostElementClass).

Alternative: implement PsiElement.getOwnReferences() directly via the PolySymbolOwnReferences

builder when PolySymbols should be the language's own canonical resolve rather than an

EP-contributed layer (e.g. replacing a legacy PsiReferenceContributor) — see

references/query-model.md.

Don't register both for the same host — own references pre-empt external ones. Either way, the

host element's own type must implement PsiExternalReferenceHost (external) or

PolySymbolOwnReferenceHost (own) — PolySymbolHighlightingAnnotator only looks at elements

implementing one of the two, so skipping this isn't just a missed nicety, it's silently no

highlighting/diagnostics at all (own references also won't compile against the DSL without it).

  1. Supply declarations: if a symbol maps 1:1 onto a real PsiElement and lives purely in the

PolySymbols model, implement PolySymbolDeclaredInPsi plus a PolySymbolDeclarationProvider

(EP com.intellij.polySymbols.declarationProvider) that builds the symbol — this is the default.

The provider is pure dispatch: decide which symbol(s) a PsiElement backs, instantiate them,

and return symbol.declaration (the interface's own default). Don't hand-roll a

PolySymbolDeclaration implementation or thread a range through the provider — the

declaration range is a textRangeInSourceElement override on the symbol class itself; the symbol

represents itself, the provider only knows which symbol to build.

Reach for PsiLinkedPolySymbol + polySymbols.psiLinkedSymbol host="..." only when that same

PsiElement must also keep working as a target for a legacy, non-PolySymbols

find-usages/rename mechanism you're running alongside (a bridge for partial migrations, not a

general shortcut — see references/query-model.md).

For symbols with no backing PsiElement at all (synthetic/SDK symbols), write a

PolySymbolDeclarationProvider by hand.

  1. Wire completion: register an ordinary completion.contributor whose provider extends

PolySymbolsCompletionProviderBase and calls queryExecutor.codeCompletionQuery(...).

  1. Optional: PolySymbolQueryConfigurator for context rules/name-conversion rules;

PolySymbolQueryResultsCustomizerFactory to post-filter/remap query results;

polySymbols.webTypes if standard-library symbols can be shipped as static JSON instead of code

(see references/web-types.md); a PolySymbolFramework

(polySymbols.framework) + PolyContextProvider (polySymbols.context) if you're introducing a

new framework identity (see PolyContext).

  1. Use PolySymbolWithPattern/the pattern DSL when the language/framework layers a microsyntax on

top of base syntax (directive-style attribute names, event-modifier chains). See

references/patterns.md.

Case studies

Four real integrations in this repo, each ending in an explicit PolySymbols-vs-legacy verdict — read

references/case-studies.md for the full writeup with file:line

evidence.

| Integration | Where | One-line verdict |

|---|---|---|

| GDScript | dotnet/Plugins/godot-support/gdscript/.../polySymbols/ | Dual-track: SDK/engine and user-code symbols are PolySymbols-first; res:// string literals, TSCN res:// values and doc-comment links are legacy-only, both paths run concurrently on some elements |

| JS/TS, HTML, CSS | plugins/JavaScriptLanguage/web-platform/, community/xml, plugins/css | PolySymbols is grafted onto legacy extension points and steps aside for anything standard/spec-defined |

| Vue | contrib/vuejs/vuejs-backend/src/org/jetbrains/vuejs/web/ | Template/markup surface (components/directives/props/slots/events) is ~fully PolySymbols; Vuex, refs, CSS bindings are not |

| Angular | contrib/Angular/angular-backend/src/org/angular2/web/ | Markup/selector surface is ~fully PolySymbols; the Angular2 expression-language layer and some file/pipe-name refs are not |

Related skills

Implementing Poly Symbols,

Poly Symbols Integration with Language Features.

Supporting files

Load only when needed:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.