getHover method
This method is used to get details at a specific position in the document.
This method is used internally by the CodeCrafter, calling this with appropriate parameters will returns a String.
If the LSP server does not support hover or the location provided is invalid, it will return an empty string.
Implementation
Future<String> getHover(int line, int character) async {
final response = await _sendRequest(
method: 'textDocument/hover',
params: _commonParams(line, character),
);
final contents = response['result']?['contents'];
if (contents == null || contents.isEmpty) return '';
if (contents is String) return contents;
if (contents is Map && contents.containsKey('value')) {
return contents['value'] ?? '';
}
if (contents is List && contents.isNotEmpty) {
return contents
.map((item) {
if (item is String) return item;
if (item is Map && item.containsKey('value')) return item['value'];
return '';
})
.join('\n');
}
return '';
}