From a3d55683877d94f99ddcea3ce93479209b19dd68 Mon Sep 17 00:00:00 2001 From: Dylon Edwards Date: Thu, 19 Dec 2024 21:40:49 -0500 Subject: [PATCH] Improves tracing of function calls; improves logging of LFortran errors --- server/src/lfortran-accessors.ts | 195 ++++++++----- server/src/lfortran-language-server.ts | 377 +++++++++++++++---------- server/src/logger.ts | 32 ++- 3 files changed, 381 insertions(+), 223 deletions(-) diff --git a/server/src/lfortran-accessors.ts b/server/src/lfortran-accessors.ts index dbfa2f1..d95fbf6 100644 --- a/server/src/lfortran-accessors.ts +++ b/server/src/lfortran-accessors.ts @@ -84,7 +84,7 @@ export class LFortranCLIAccessor implements LFortranAccessor { private cleanUpHandler: () => void; constructor(logger: Logger) { - const fnid: string = "constructor(...)"; + const fnid: string = "constructor"; const start: number = performance.now(); this.logger = logger; @@ -95,15 +95,19 @@ export class LFortranCLIAccessor implements LFortranAccessor { process.on("SIGINT", this.cleanUpHandler); process.on("uncaughtException", this.cleanUpHandler); - this.logger.benchmarkAndTrace( - LFortranCLIAccessor.LOG_CONTEXT, - fnid, start, - [logger] - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranCLIAccessor.LOG_CONTEXT, + fnid, start, + [ + "logger", logger, + ] + ); + } } cleanUp(...args: any[]): void { - const fnid: string = "cleanUp(...)"; + const fnid: string = "cleanUp"; const start: number = performance.now(); try { @@ -128,14 +132,19 @@ export class LFortranCLIAccessor implements LFortranAccessor { process.removeListener("exit", this.cleanUpHandler); } - this.logger.benchmarkAndTrace( - LFortranCLIAccessor.LOG_CONTEXT, - fnid, start, args - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranCLIAccessor.LOG_CONTEXT, + fnid, start, + [ + "args", args, + ] + ); + } } async checkPathExistsAndIsExecutable(path: string): Promise { - const fnid: string = "checkPathExistsAndIsExecutable(...)"; + const fnid: string = "checkPathExistsAndIsExecutable"; const start: number = performance.now(); let pathExistsAndIsExecutable: boolean = false; @@ -150,12 +159,16 @@ export class LFortranCLIAccessor implements LFortranAccessor { } } - this.logger.benchmarkAndTrace( - LFortranCLIAccessor.LOG_CONTEXT, - fnid, start, - [path], - pathExistsAndIsExecutable - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranCLIAccessor.LOG_CONTEXT, + fnid, start, + [ + "path", path, + ], + pathExistsAndIsExecutable + ); + } return pathExistsAndIsExecutable; } @@ -168,7 +181,7 @@ export class LFortranCLIAccessor implements LFortranAccessor { text: string, defaultValue: string = "", noResponseIsSuccess: boolean = false): Promise { - const fnid: string = "runCompiler(...)"; + const fnid: string = "runCompiler"; const start: number = performance.now(); let output: string = defaultValue; @@ -211,7 +224,7 @@ export class LFortranCLIAccessor implements LFortranAccessor { let escapedCommand: string | undefined; let commandStart: number | undefined; - if (this.logger.isBenchmarkEnabled()) { + if (this.logger.isBenchmarkEnabled() || this.logger.isDebugEnabled()) { escapedCommand = shellescape([lfortranPath].concat(params)); commandStart = performance.now(); } @@ -226,6 +239,19 @@ export class LFortranCLIAccessor implements LFortranAccessor { escapedCommand as string, commandStart as number); + if (this.logger.isDebugEnabled()) { + this.logger.debug( + LFortranCLIAccessor.LOG_CONTEXT, + "`%s` yielded status=%s, signal=%s, response=%s", + escapedCommand, response.status, response.signal, + JSON.stringify( + response, + undefined, + this.logger.indentSize + ) + ); + } + if (response.error) { if (response.stderr) { output = response.stderr.toString(); @@ -234,6 +260,8 @@ export class LFortranCLIAccessor implements LFortranAccessor { LFortranCLIAccessor.LOG_CONTEXT, "Failed to get stderr from lfortran"); } + } else if (response.stderr) { + output = response.stderr.toString(); } else { if (response.stdout) { output = response.stdout.toString(); @@ -248,7 +276,11 @@ export class LFortranCLIAccessor implements LFortranAccessor { } } } catch (compileError: any) { - output = compileError.stdout; + if (compileError.stderr) { + output = compileError.stderr; + } else { + output = compileError.stdout; + } if (compileError.signal !== null) { this.logger.error( LFortranCLIAccessor.LOG_CONTEXT, @@ -260,17 +292,20 @@ export class LFortranCLIAccessor implements LFortranAccessor { this.logger.error(LFortranCLIAccessor.LOG_CONTEXT, error); } - this.logger.benchmarkAndTrace( - LFortranCLIAccessor.LOG_CONTEXT, - fnid, start, [ - settings, - params, - text, - defaultValue, - noResponseIsSuccess, - ], - output - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranCLIAccessor.LOG_CONTEXT, + fnid, start, + [ + "settings", settings, + "params", params, + "text", text, + "defaultValue", defaultValue, + "noResponseIsSuccess", noResponseIsSuccess, + ], + output + ); + } return output; } @@ -278,7 +313,7 @@ export class LFortranCLIAccessor implements LFortranAccessor { async showDocumentSymbols(uri: string, text: string, settings: LFortranSettings): Promise { - const fnid: string = "showDocumentSymbols(...)"; + const fnid: string = "showDocumentSymbols"; const start: number = performance.now(); const flags = ["--show-document-symbols", "--continue-compilation"]; @@ -314,12 +349,18 @@ export class LFortranCLIAccessor implements LFortranAccessor { } } - this.logger.benchmarkAndTrace( - LFortranCLIAccessor.LOG_CONTEXT, - fnid, start, - [uri, text, settings], - symbols - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranCLIAccessor.LOG_CONTEXT, + fnid, start, + [ + "uri", uri, + "text", text, + "settings", settings, + ], + symbols + ); + } return symbols; } @@ -328,7 +369,7 @@ export class LFortranCLIAccessor implements LFortranAccessor { line: number, column: number, settings: LFortranSettings): Promise { - const fnid: string = "lookupName(...)"; + const fnid: string = "lookupName"; const start: number = performance.now(); const definitions: DefinitionLink[] = []; @@ -370,17 +411,20 @@ export class LFortranCLIAccessor implements LFortranAccessor { this.logger.error(LFortranCLIAccessor.LOG_CONTEXT, error); } - this.logger.benchmarkAndTrace( - LFortranCLIAccessor.LOG_CONTEXT, - fnid, start, [ - uri, - text, - line, - column, - settings, - ], - definitions - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranCLIAccessor.LOG_CONTEXT, + fnid, start, + [ + "uri", uri, + "text", text, + "line", line, + "column", column, + "settings", settings, + ], + definitions + ); + } return definitions; } @@ -388,7 +432,7 @@ export class LFortranCLIAccessor implements LFortranAccessor { async showErrors(uri: string, text: string, settings: LFortranSettings): Promise { - const fnid: string = "showErrors(...)"; + const fnid: string = "showErrors"; const start: number = performance.now(); const diagnostics: Diagnostic[] = []; @@ -444,12 +488,18 @@ export class LFortranCLIAccessor implements LFortranAccessor { this.logger.error(LFortranCLIAccessor.LOG_CONTEXT, error); } - this.logger.benchmarkAndTrace( - LFortranCLIAccessor.LOG_CONTEXT, - fnid, start, - [uri, text, settings], - diagnostics - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranCLIAccessor.LOG_CONTEXT, + fnid, start, + [ + "uri", uri, + "text", text, + "settings", settings, + ], + diagnostics + ); + } return diagnostics; } @@ -459,7 +509,7 @@ export class LFortranCLIAccessor implements LFortranAccessor { column: number, newName: string, settings: LFortranSettings): Promise { - const fnid: string = "renameSymbol(...)"; + const fnid: string = "renameSymbol"; const start: number = performance.now(); const edits: TextEdit[] = []; @@ -499,18 +549,21 @@ export class LFortranCLIAccessor implements LFortranAccessor { this.logger.error(LFortranCLIAccessor.LOG_CONTEXT, error); } - this.logger.benchmarkAndTrace( - LFortranCLIAccessor.LOG_CONTEXT, - fnid, start, [ - uri, - text, - line, - column, - newName, - settings - ], - edits - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranCLIAccessor.LOG_CONTEXT, + fnid, start, + [ + "uri", uri, + "text", text, + "line", line, + "column", column, + "newName", newName, + "settings", settings, + ], + edits + ); + } return edits; } diff --git a/server/src/lfortran-language-server.ts b/server/src/lfortran-language-server.ts index 015df56..634f6c4 100644 --- a/server/src/lfortran-language-server.ts +++ b/server/src/lfortran-language-server.ts @@ -86,7 +86,7 @@ export class LFortranLanguageServer { documents: TextDocuments, logger: Logger, settings: LFortranSettings = defaultSettings) { - const fnid: string = "constructor(...)"; + const fnid: string = "constructor"; const start: number = performance.now(); this.lfortran = lfortran; @@ -96,21 +96,23 @@ export class LFortranLanguageServer { this.settings = settings; logger.configure(settings); - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [ - lfortran, - connection, - documents, - logger, - settings, - ] - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "lfortran", lfortran, + "connection", connection, + "documents", documents, + "logger", logger, + "settings", settings, + ] + ); + } } onInitialize(params: InitializeParams): InitializeResult { - const fnid: string = "onInitialize(...)"; + const fnid: string = "onInitialize"; const start: number = performance.now(); const capabilities = params.capabilities; @@ -151,17 +153,21 @@ export class LFortranLanguageServer { }; } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [params], - result - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "params", params, + ], + result + ); + } return result; } onInitialized(params: InitializedParams): void { - const fnid: string = "onInitialized(...)"; + const fnid: string = "onInitialized"; const start: number = performance.now(); if (this.hasConfigurationCapability) { @@ -170,15 +176,19 @@ export class LFortranLanguageServer { .register(DidChangeConfigurationNotification.type, undefined); } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [params] - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "params", params, + ] + ); + } } extractDefinition(location: Location): string | null { - const fnid: string = "extractDefinition(...)"; + const fnid: string = "extractDefinition"; const start: number = performance.now(); let definition: string | null = null; const document = this.documents.get(location.uri); @@ -239,16 +249,21 @@ export class LFortranLanguageServer { } } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [location], - definition); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "location", location, + ], + definition + ); + } return definition; } index(uri: string, symbols: SymbolInformation[]): void { - const fnid: string = "index(...)"; + const fnid: string = "index"; const start: number = performance.now(); // (symbols.length == 0) => error with document, but we still need to @@ -274,15 +289,20 @@ export class LFortranLanguageServer { const dictionary = PrefixTrie.from(terms, values); this.dictionaries.set(uri, dictionary); - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [uri, symbols] - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "uri", uri, + "symbols", symbols, + ] + ); + } } async onDocumentSymbol(request: DocumentSymbolParams): Promise { - const fnid: string = "onDocumentSymbol(...)"; + const fnid: string = "onDocumentSymbol"; const start: number = performance.now(); let symbols: SymbolInformation[] | null = null; @@ -301,18 +321,22 @@ export class LFortranLanguageServer { } } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [request], - symbols - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "request", request, + ], + symbols + ); + } return symbols; } async onDefinition(request: DefinitionParams): Promise { - const fnid: string = "onDefinition(...)"; + const fnid: string = "onDefinition"; const start: number = performance.now(); let definitions: DefinitionLink[] | null = null; @@ -328,18 +352,22 @@ export class LFortranLanguageServer { await this.lfortran.lookupName(uri, text, line, column, this.settings); } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [request], - definitions - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "request", request, + ], + definitions + ); + } return definitions; } onDidChangeConfiguration(change: DidChangeConfigurationParams): void { - const fnid: string = "onDidChangeConfiguration(...)"; + const fnid: string = "onDidChangeConfiguration"; const start: number = performance.now(); if (this.hasConfigurationCapability) { @@ -355,24 +383,32 @@ export class LFortranLanguageServer { // Revalidate all open text documents this.documents.all().forEach(this.validateTextDocument.bind(this)); - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [change] - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "change", change, + ] + ); + } } getDocumentSettings(uri: string): Thenable { - const fnid: string = "getDocumentSettings(...)"; + const fnid: string = "getDocumentSettings"; const start: number = performance.now(); if (!this.hasConfigurationCapability) { - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [uri], - this.settings - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "uri", uri, + ], + this.settings + ); + } return Promise.resolve(this.settings); } @@ -387,44 +423,56 @@ export class LFortranLanguageServer { this.documentSettings.set(uri, settings); } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [uri], - settings - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "uri", uri, + ], + settings + ); + } return settings; } // Only keep settings for open documents onDidClose(event: TextDocumentChangeEvent): void { - const fnid: string = "onDidClose(...)"; + const fnid: string = "onDidClose"; const start: number = performance.now(); this.documentSettings.delete(event.document.uri); - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [event] - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "event", event, + ] + ); + } } onDidChangeContent(event: TextDocumentChangeEvent): void { - const fnid: string = "onDidChangeContent(...)"; + const fnid: string = "onDidChangeContent"; const start: number = performance.now(); this.validateTextDocument(event.document); - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [event] - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "event", event, + ] + ); + } } async validateTextDocument(textDocument: TextDocument): Promise { - const fnid: string = "validateTextDocument(...)"; + const fnid: string = "validateTextDocument"; const start: number = performance.now(); if (this.hasDiagnosticRelatedInformationCapability) { @@ -442,15 +490,19 @@ export class LFortranLanguageServer { 'Cannot validate a document with no diagnostic capability'); } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [textDocument] - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "textDocument", textDocument, + ] + ); + } } extractQuery(text: string, line: number, column: number): string | null { - const fnid: string = "extractQuery(...)"; + const fnid: string = "extractQuery"; const start: number = performance.now(); let query: string | null = null; @@ -491,17 +543,23 @@ export class LFortranLanguageServer { } } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [text, line, column], - query - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "text", text, + "line", line, + "column", column, + ], + query + ); + } return query; } onCompletion(documentPosition: TextDocumentPositionParams): CompletionItem[] | CompletionList | null { - const fnid: string = "onCompletion(...)"; + const fnid: string = "onCompletion"; const start: number = performance.now(); let completions: CompletionItem[] | null = null; @@ -519,29 +577,37 @@ export class LFortranLanguageServer { } } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [documentPosition], - completions - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "documentPosition", documentPosition, + ], + completions + ); + } return completions; } onCompletionResolve(item: CompletionItem): CompletionItem { - const fnid: string = "onCompletionResolve(...)"; + const fnid: string = "onCompletionResolve"; const start: number = performance.now(); - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [item], - item - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "item", item, + ], + item + ); + } return item; } onHover(params: HoverParams): Hover | null { - const fnid: string = "onHover(...)"; + const fnid: string = "onHover"; const start: number = performance.now(); let hover: Hover | null = null; @@ -569,17 +635,21 @@ export class LFortranLanguageServer { } } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [params], - hover - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "params", params, + ], + hover + ); + } return hover; } highlightSymbol(text: string, symbol: string): Range[] { - const fnid: string = "highlightSymbol(...)"; + const fnid: string = "highlightSymbol"; const start: number = performance.now(); // case-insensitive search @@ -649,17 +719,22 @@ export class LFortranLanguageServer { } } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [text, symbol], - highlights - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "text", text, + "symbol", symbol, + ], + highlights + ); + } return highlights; } renameSymbol(text: string, symbol: string, newName: string): TextEdit[] { - const fnid: string = "renameSymbol(...)"; + const fnid: string = "renameSymbol"; const start: number = performance.now(); const edits: TextEdit[] = this.highlightSymbol(text, symbol).map(range => ({ @@ -667,17 +742,23 @@ export class LFortranLanguageServer { newText: newName, })); - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [text, symbol, newName], - edits - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "text", text, + "symbol", symbol, + "newName", newName, + ], + edits + ); + } return edits; } async onRenameRequest(params: RenameParams): Promise { - const fnid: string = "onRenameRequest(...)"; + const fnid: string = "onRenameRequest"; const start: number = performance.now(); let workspaceEdit: WorkspaceEdit | null = null; @@ -719,17 +800,21 @@ export class LFortranLanguageServer { } } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [params], - workspaceEdit - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "params", params, + ], + workspaceEdit + ); + } return workspaceEdit; } async onDocumentHighlight(params: DocumentHighlightParams): Promise { - const fnid: string = "onDocumentHighlight(...)"; + const fnid: string = "onDocumentHighlight"; const start: number = performance.now(); let highlights: DocumentHighlight[] | null = null; @@ -755,12 +840,16 @@ export class LFortranLanguageServer { } } - this.logger.benchmarkAndTrace( - LFortranLanguageServer.LOG_CONTEXT, - fnid, start, - [params], - highlights - ); + if (this.logger.isBenchmarkOrTraceEnabled()) { + this.logger.benchmarkAndTrace( + LFortranLanguageServer.LOG_CONTEXT, + fnid, start, + [ + "params", params, + ], + highlights + ); + } return highlights; } } diff --git a/server/src/logger.ts b/server/src/logger.ts index 3e5975d..a4c12e8 100644 --- a/server/src/logger.ts +++ b/server/src/logger.ts @@ -306,20 +306,36 @@ export class Logger { } } + isBenchmarkOrTraceEnabled() { + return this.isBenchmarkEnabled() || this.isTraceEnabled(); + } + benchmarkAndTrace(context: string, fnid: string, start: number, - params: any[], + paramNamesAndValues: any[], retval?: any): void { this.benchmark(context, fnid, start); if (this.isTraceEnabled()) { - const indentSize = (this.prettyPrint) ? this.indentSize : undefined; - const stringified: string = JSON.stringify([ - fnid, - params, - retval - ], undefined, indentSize); - this.debug(context, stringified); + const indentSize: number | undefined = (this.prettyPrint) ? this.indentSize : undefined; + const params: object[] = []; + const names: string[] = []; + for (let i = 0, k = paramNamesAndValues.length; i < k; i += 2) { + const name: string = paramNamesAndValues[i]; + const value: any = paramNamesAndValues[i + 1]; + const param: object = { + [name]: value, + }; + params.push(param); + names.push(name); + } + const signature: string = `${fnid}(${names.join(", ")})` + const stringified: string = JSON.stringify({ + "function": signature, + "input": params, + "output": retval, + }, undefined, indentSize); + this.trace(context, stringified); } } }