updateSemanticTokens method

void updateSemanticTokens(
  1. List<LspSemanticToken> tokens,
  2. String fullText
)

Implementation

void updateSemanticTokens(List<LspSemanticToken> tokens, String fullText) {
  _lineSemanticSpans.clear();
  final lines = fullText.split('\n');

  for (final token in tokens) {
    if (token.line < lines.length) {
      final lineText = lines[token.line];
      final start = token.start.clamp(0, lineText.length);
      final end = (token.start + token.length).clamp(0, lineText.length);

      if (start < end) {
        final word = lineText.substring(start, end);
        final style = _resolveSemanticStyle(token.tokenTypeName);

        if (style != null && word.isNotEmpty) {
          final lineSpans = _lineSemanticSpans.putIfAbsent(
            token.line,
            () => [],
          );
          lineSpans.add(
            SemanticWordSpan(
              startChar: start,
              endChar: end,
              word: word,
              style: style,
            ),
          );
        }
      }
    }
  }

  for (final lineSpans in _lineSemanticSpans.values) {
    lineSpans.sort((a, b) => a.startChar.compareTo(b.startChar));
  }

  _isEditing = false;
  _lineSpanCache.clear();
  _mergedCache.clear();
  _grammarCache.clear();
  _version++;
  onHighlightComplete?.call();
}