mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-18 03:13:31 +00:00
fix: Properly handle CRLF line endings in the syntax tree view
This commit is contained in:
parent
7c387ed3a7
commit
027363fef1
4 changed files with 183 additions and 78 deletions
|
|
@ -361,10 +361,7 @@ export function syntaxTreeReveal(): Cmd {
|
|||
const activeEditor = vscode.window.activeTextEditor;
|
||||
|
||||
if (activeEditor !== undefined) {
|
||||
const start = activeEditor.document.positionAt(element.start);
|
||||
const end = activeEditor.document.positionAt(element.end);
|
||||
|
||||
const newSelection = new vscode.Selection(start, end);
|
||||
const newSelection = new vscode.Selection(element.range.start, element.range.end);
|
||||
|
||||
activeEditor.selection = newSelection;
|
||||
activeEditor.revealRange(newSelection);
|
||||
|
|
@ -378,15 +375,12 @@ function elementToString(
|
|||
depth: number = 0,
|
||||
): string {
|
||||
let result = " ".repeat(depth);
|
||||
const start = element.istart ?? element.start;
|
||||
const end = element.iend ?? element.end;
|
||||
const offsets = element.inner?.offsets ?? element.offsets;
|
||||
|
||||
result += `${element.kind}@${start}..${end}`;
|
||||
result += `${element.kind}@${offsets.start}..${offsets.end}`;
|
||||
|
||||
if (element.type === "Token") {
|
||||
const startPosition = activeDocument.positionAt(element.start);
|
||||
const endPosition = activeDocument.positionAt(element.end);
|
||||
const text = activeDocument.getText(new vscode.Range(startPosition, endPosition));
|
||||
const text = activeDocument.getText(element.range).replaceAll("\r\n", "\n");
|
||||
// JSON.stringify quotes and escapes the string for us.
|
||||
result += ` ${JSON.stringify(text)}\n`;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue