semanticTokensField top-level property

StateField<SemanticTokensState> semanticTokensField
final

State field for storing semantic tokens.

Implementation

final semanticTokensField = StateField.define(
  StateFieldConfig<SemanticTokensState>(
    create: (_) => SemanticTokensState.empty,
    update: (value, tr) {
      // Check for explicit token updates
      for (final effect in tr.effects) {
        if (effect.is_(setSemanticTokens)) {
          return effect.value as SemanticTokensState;
        }
      }

      // Map decorations through document changes
      if (tr.docChanged && !value.decorations.isEmpty) {
        // Note: We need access to the ChangeSet from the transaction
        // For now, just invalidate - the plugin will re-request tokens
        return SemanticTokensState(
          tokens: value.tokens, // Tokens become stale, will be refreshed
          decorations: Decoration.none, // Clear stale decorations
          resultId: null, // Invalidate result ID on doc change
          data: value.data,
          version: value.version,
        );
      }

      return value;
    },
    provide: (field) => decorationsFacet.from(
      field,
      (state) => state.decorations,
    ),
  ),
);