Skip to content

Commit

Permalink
Improved debugging window of parsed files to show parsed data of sele…
Browse files Browse the repository at this point in the history
…cted range of text
  • Loading branch information
eyza-cod2 committed Sep 22, 2024
1 parent 6d60a92 commit 10252db
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/GscFileParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 23 additions & 14 deletions src/GscFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,42 +623,51 @@ export class GscFiles {

private static getWebviewContent(): string {
const editor = vscode.window.activeTextEditor;
const cursor = editor?.selection.active;
const uri = editor?.document.uri;

var html = `
<html>
<body>
<h1>Debug Information</h1>
`;

if (cursor) {
html += `<p>Cursor position: ${cursor?.line}, ${cursor?.character}</p>`;
}
if (editor) {
const cursor = editor.selection.active;
const cursorRange = new vscode.Range(editor.selection.start, editor.selection.end);
const uri = editor.document.uri;

html += `<p>Cursor position: ${cursor.line}, ${cursor.character} start: ${cursorRange.start.line}, ${cursorRange.start?.character} end: ${cursorRange.end?.line}, ${cursorRange.end?.character}</p>`;

if (uri && cursor) {

const gscFile = GscFiles.getCachedFile(uri);

if (gscFile === undefined) {
html += "<p>File is not part of workspace: " + uri.fsPath + "</p>";
} 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 += "<p>No item found at position.</p>";
} else {

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

html += "<br>";

const funcNameAndPath = groupAtCursor.getFunctionReferenceInfo();
const funcNameAndPath = groupAtCursorStart.getFunctionReferenceInfo();
if (funcNameAndPath !== undefined) {
html += "<pre>";
html += "Function:\n";
Expand Down

0 comments on commit 10252db

Please sign in to comment.