sendRequest method

Future<Map<String, dynamic>> sendRequest(
  1. String method,
  2. Map<String, dynamic> params
)

Send a JSON-RPC request and await response.

Implementation

Future<Map<String, dynamic>> sendRequest(
  String method,
  Map<String, dynamic> params,
) async {
  final id = _nextId++;
  final request = {
    'jsonrpc': '2.0',
    'id': id,
    'method': method,
    'params': params,
  };

  final completer = Completer<Map<String, dynamic>>();
  _pendingRequests[id] = completer;

  _send(request);

  return completer.future.timeout(
    const Duration(seconds: 30),
    onTimeout: () {
      _pendingRequests.remove(id);
      throw TimeoutException('LSP request timed out: $method');
    },
  );
}