navigateToCode method

Future<void> navigateToCode({
  1. required String fileUriString,
  2. required int line,
  3. required int column,
  4. required String source,
})

Posts an event to jump to code.

The event directs an IDE to move to the line and column in the specified fileUriString, which is expected to be a proper file URI (i.e. starts with "file://"). The source should indicate the tool and/or feature (i.e. in the format "someTool.someFeature") that is making the jump to code request.

If there are no IDEs listening for this event, then this will be a no-op.

Implementation

Future<void> navigateToCode({
  required String fileUriString,
  required int line,
  required int column,
  required String source,
}) async {
  try {
    await postEvent('ToolEvent', 'navigate', <String, Object>{
      'fileUri': fileUriString,
      'line': line,
      'column': column,
      'source': source,
    });
  } on RPCError catch (e) {
    // An [RPCErrorKind.kCustomStreamDoesNotExist] error is expected if the
    // custom 'ToolEvent' stream does not have any listeners (i.e. there are
    // no IDEs listening to this stream).
    if (e.code == RPCErrorKind.kCustomStreamDoesNotExist.code) {
      return;
    }
    rethrow;
  }
}