From 10252dbc1ed8a59cdf1a5bfc102c92603dab1c91 Mon Sep 17 00:00:00 2001 From: eyza Date: Sun, 22 Sep 2024 09:23:58 +0200 Subject: [PATCH] Improved debugging window of parsed files to show parsed data of selected range of text --- src/GscFileParser.ts | 14 ++++++++++++++ src/GscFiles.ts | 37 +++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/GscFileParser.ts b/src/GscFileParser.ts index b303586..8c876aa 100644 --- a/src/GscFileParser.ts +++ b/src/GscFileParser.ts @@ -2623,6 +2623,20 @@ export class GscGroup { } + /** + * Find parent group of current group that contains given range. + */ + public getParentWithinRange(range: vscode.Range): GscGroup | undefined { + var group = this as GscGroup; + while (group.parent !== undefined) { + if (group.parent.getRange().contains(range)) { + return group.parent; + } + group = group.parent; + } + return undefined; + } + /** * Select variable tokens like 'level.aaa.bbb' from document diff --git a/src/GscFiles.ts b/src/GscFiles.ts index c53dfae..579c343 100644 --- a/src/GscFiles.ts +++ b/src/GscFiles.ts @@ -623,8 +623,6 @@ export class GscFiles { private static getWebviewContent(): string { const editor = vscode.window.activeTextEditor; - const cursor = editor?.selection.active; - const uri = editor?.document.uri; var html = ` @@ -632,11 +630,13 @@ export class GscFiles {

Debug Information

`; - if (cursor) { - html += `

Cursor position: ${cursor?.line}, ${cursor?.character}

`; - } + if (editor) { + const cursor = editor.selection.active; + const cursorRange = new vscode.Range(editor.selection.start, editor.selection.end); + const uri = editor.document.uri; + + html += `

Cursor position: ${cursor.line}, ${cursor.character} start: ${cursorRange.start.line}, ${cursorRange.start?.character} end: ${cursorRange.end?.line}, ${cursorRange.end?.character}

`; - if (uri && cursor) { const gscFile = GscFiles.getCachedFile(uri); @@ -644,21 +644,30 @@ export class GscFiles { html += "

File is not part of workspace: " + uri.fsPath + "

"; } else { - - // Get group before cursor - var groupAtCursor = gscFile.data.root.findGroupOnLeftAtPosition(cursor); + var groupAtCursorStart = gscFile.data.root.findGroupOnLeftAtPosition(cursorRange.start.translate(0, 1)); - if (groupAtCursor === undefined) { + + if (groupAtCursorStart === undefined) { html += "

No item found at position.

"; } else { - html += "
" + GscFileParser.debugGroupAsString(gscFile.data.root.tokensAll, undefined, groupAtCursor, 0, true, groupAtCursor) + "
"; - html += "
----------------------------------------------------------------------------------------
"; - html += "
" + GscFileParser.debugAsString(gscFile.data.root.tokensAll, groupAtCursor.findParentOfType(GroupType.Root)!, true, groupAtCursor) + "
"; + if (cursorRange.isEmpty) { + html += "
" + GscFileParser.debugGroupAsString(gscFile.data.root.tokensAll, undefined, groupAtCursorStart, 0, true, groupAtCursorStart) + "
"; + html += "
----------------------------------------------------------------------------------------
"; + html += "
" + GscFileParser.debugAsString(gscFile.data.root.tokensAll, groupAtCursorStart.findParentOfType(GroupType.Root)!, true, groupAtCursorStart) + "
"; + } else { + const parentInRange = groupAtCursorStart.getParentWithinRange(cursorRange); + if (parentInRange === undefined) { + html += "
No group found in selected range
"; + } else { + html += "
" + GscFileParser.debugGroupAsString(gscFile.data.root.tokensAll, undefined, parentInRange, 0, true) + "
"; + } + } + html += "
"; - const funcNameAndPath = groupAtCursor.getFunctionReferenceInfo(); + const funcNameAndPath = groupAtCursorStart.getFunctionReferenceInfo(); if (funcNameAndPath !== undefined) { html += "
";
                         html += "Function:\n";