Skip to content

Commit

Permalink
Add fn "findDebugIdInCode( )"
Browse files Browse the repository at this point in the history
  • Loading branch information
yazz committed Jan 8, 2025
1 parent 860d863 commit 6ce7ab8
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion public/go.html
Original file line number Diff line number Diff line change
Expand Up @@ -13557,6 +13557,7 @@ <h1 style='width:100%;vertical-align:top;display:inline-block;font-size:100px; t
//
// Find out who called this function
//
//debugger
let stackTrace = yz.uiDb.getCallStack()
let fnLine = stackTrace[2]
console.log(fnLine)
Expand Down Expand Up @@ -13682,13 +13683,15 @@ <h1 style='width:100%;vertical-align:top;display:inline-block;font-size:100px; t
//
// do nothing if not in debug mode
//

if ((typeof $DEBUGUI == 'undefined') || (!$DEBUGUI)) {
return
}

//
// reset all the debug markers as we are starting a new debug trace
//
debugger
yz.debug.currentDebugId = debugId
yz.debug.debugTracerId = yz.uuidv4()
yz.debug.debugTraceSteps = []
Expand All @@ -13698,7 +13701,7 @@ <h1 style='width:100%;vertical-align:top;display:inline-block;font-size:100px; t
//
// Find out which source code line we are editing
//
debugger
//debugger
let sourceForFunction = yz.uiDb.findSourceLineInCode(debugId)

//
Expand Down Expand Up @@ -14090,6 +14093,60 @@ <h1 style='width:100%;vertical-align:top;display:inline-block;font-size:100px; t
[yz.uiDb.uiDbNextId ++,result.fileName,result.contents])
yz.debug.linesOfSourceFile[result.fileName] = result.contents.split('\n');
},
findDebugIdInCode: function ( searchText ) {
let found = false
let startLine = null
let endLine = null
let foundLine = null
let foundFile = null
let lineNumberOfSearchItem = null
let surroundingLines = null

for (let fileSourceRecord of yz.uiDb.uiDbTableData["ui_table_command_source_files"].data) {
console.log("Searching " + fileSourceRecord.source_file_name)
let indexOfSearch = fileSourceRecord.source_text.indexOf(searchText)

if ( indexOfSearch != -1 ) {
console.log(" Found '" + searchText + "' at index " + indexOfSearch)
found = true
foundFile = fileSourceRecord.source_file_name

let textUpToSearchItem = fileSourceRecord.source_text.substring(0,indexOfSearch)
let linesOfFileBeforeSearchItem = textUpToSearchItem.split('\n');
lineNumberOfSearchItem = linesOfFileBeforeSearchItem.length

let linesOfFile = yz.debug.linesOfSourceFile[fileSourceRecord.source_file_name]

startLine = lineNumberOfSearchItem - 5
if (startLine < 1) {
startLine = 1
}
endLine = lineNumberOfSearchItem + 5
if (endLine > linesOfFile.length) {
endLine = linesOfFile.length
}

for (let currentLineNumber = startLine; currentLineNumber <= endLine ; currentLineNumber ++) {
let currentLine = linesOfFile[currentLineNumber - 1]

let existsRow = yz.uiDb.sqlui1("select id from ui_table_command_source_file_lines where source_file_name= ? and source_line_number = ?",
[fileSourceRecord.source_file_name , currentLineNumber])
if (!existsRow) {
yz.uiDb.sqlui("INSERT INTO ui_table_command_source_file_lines ( id , source_file_name , source_line_text , source_line_number ) VALUES (?,?,?,?)",
[yz.uiDb.uiDbNextId ++,fileSourceRecord.source_file_name, currentLine, currentLineNumber])
}
}
console.log("Filename: " + fileSourceRecord.source_file_name)
foundLine = linesOfFile[lineNumberOfSearchItem - 1]
console.log(" foundOnLine: " + lineNumberOfSearchItem + ":" + foundLine)

surroundingLines = sqlui("select * from ui_table_command_source_file_lines where source_file_name = ? and source_line_number >= ? and source_line_number <= ?",[foundFile, startLine, endLine])

break
}
}
return { found: found , fileName: foundFile, lineNumber: lineNumberOfSearchItem, lineText: foundLine , context: surroundingLines }
},
findSourceLineInCode: function ( searchText ) {
let found = false
let startLine = null
Expand Down

0 comments on commit 6ce7ab8

Please sign in to comment.