Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

412
Vistas
Vscode move to line X after openTextDocument

I'm developing a VS Code extension that jump to a specific file:num, but I'm stuck at the step of moving the cursor to a specific line after opening a file. How can I achieve this :

export const openAndMoveToLine = async (file_line: string) => {

  // /home/user/some/path.php:10
  let [filename, line_number] = file_line.split(":")
  
  // opening the file => OK
  let setting: vscode.Uri = vscode.Uri.parse(filename)
  let doc = await vscode.workspace.openTextDocument(setting)
  vscode.window.showTextDocument(doc, 1, false);

  // FIXME: After being opened, now move to the line X  => NOK **/

  await vscode.commands.executeCommand("cursorMove",     {
          to: "down", by:'wrappedLine',
          value: parseInt(line_number)
    });

}

Thank you

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You will first need to get access to the active editor. This is done by adding a .then to the showTextDocument call (which is a Thenable function) that returns a text editor object. You will then be able to use the textEditor variable (as in the example) to set the position of the cursor using the selection property as follows:

vscode.window.showTextDocument(doc, 1, false).then((textEditor: TextEditor) => {
  const lineNumber = 1;
  const characterNumberOnLine = 1;
  const position = new vscode.Position(lineNumber, characterNumberOnLine);
  const newSelection = new vscode.Selection(position, position);
  textEditor.selection = newSelection;
});

Reference to selection API can be found here.

The usecase that you are exploring has been discussed in GitHub issue that can be found here.

about 4 years ago · Juan Pablo Isaza Denunciar

0

It can be done with the TextDocumentShowOptions easily:

const showDocOptions = {
    preserveFocus: false,
    preview: false,
    viewColumn: 1,

    // replace with your line_number's
    selection: new vscode.Range(314, 0, 314, 0)
};

let doc = await vscode.window.showTextDocument(setting, showDocOptions);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda