fetchLSPFoldRanges method
Fetches fold ranges from the LSP server.
If successful, these fold ranges will be used instead of the built-in fold range detection algorithm.
Example:
await controller.fetchLSPFoldRanges();
Implementation
Future<void> fetchLSPFoldRanges() async {
if (lspConfig == null || openedFile == null) return;
try {
final response = await lspConfig!.getLSPFoldRanges(openedFile!);
final result = response['result'];
if (result is List && result.isNotEmpty) {
final Map<int, FoldRange> foldMap = {};
for (final item in result) {
if (item is Map<String, dynamic>) {
final startLine = item['startLine'] as int?;
final endLine = item['endLine'] as int?;
if (startLine != null && endLine != null && endLine > startLine) {
foldMap[startLine] = FoldRange(startLine, endLine);
}
}
}
_lspFoldRanges = foldMap.isEmpty ? null : foldMap;
} else {
_lspFoldRanges = null;
}
notifyListeners();
} catch (e) {
debugPrint('Error fetching LSP fold ranges: $e');
_lspFoldRanges = null;
}
}