fetchDocumentHighlights method

Future<void> fetchDocumentHighlights(
  1. int line,
  2. int character
)

Fetches document highlights for a symbol at the cursor position.

This highlights all occurrences of the symbol at the given position. Should be called with a debounce delay to avoid frequent calls.

Example:

await controller.fetchDocumentHighlights(10, 5);

Implementation

Future<void> fetchDocumentHighlights(int line, int character) async {
  if (lspConfig == null || openedFile == null) return;

  try {
    final result = await lspConfig!.getDocumentHighlight(
      openedFile!,
      line,
      character,
    );

    if (result.isNotEmpty) {
      _documentHighlights = result
          .whereType<Map<String, dynamic>>()
          .map((data) => DocumentHighlight.fromLsp(data))
          .toList();
    } else {
      _documentHighlights = [];
    }

    documentHighlightsChanged = true;
    notifyListeners();
  } catch (e) {
    debugPrint('Error fetching document highlights: $e');
    _documentHighlights = [];
    documentHighlightsChanged = true;
    notifyListeners();
  }
}