Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

408
Views
Vscode se mueve a la línea X después de abrirTextDocument

Estoy desarrollando una extensión de VS Code que salta a un archivo específico: num , pero estoy atascado en el paso de mover el cursor a una línea específica después de abrir un archivo. Cómo puedo conseguir esto :

 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) }); }

Gracias

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Primero deberá obtener acceso al editor activo. Esto se hace agregando un .then a la llamada showTextDocument (que es una función de Thenable ) que devuelve un objeto de editor de texto. Luego podrá usar la variable textEditor (como en el ejemplo) para establecer la posición del cursor usando la propiedad de selection de la siguiente manera:

 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; });

La referencia a la API de selection se puede encontrar aquí .

El caso de uso que está explorando se ha discutido en el problema de GitHub que se puede encontrar aquí .

about 4 years ago · Juan Pablo Isaza Report

0

Se puede hacer con TextDocumentShowOptions fácilmente:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!