From 3d4319540931af08c30b7f6cc6a5b157f50ce4a6 Mon Sep 17 00:00:00 2001 From: Shuguang Sun Date: Thu, 21 Mar 2024 16:58:21 +0800 Subject: [PATCH] fix: setup to establishConnection Signed-off-by: Shuguang Sun --- client/src/connection/saspy/index.ts | 38 +++++++++++++++++++++++----- client/src/connection/saspy/types.ts | 1 + 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/client/src/connection/saspy/index.ts b/client/src/connection/saspy/index.ts index b81489eff..77049221b 100644 --- a/client/src/connection/saspy/index.ts +++ b/client/src/connection/saspy/index.ts @@ -4,7 +4,7 @@ import { Uri, workspace } from "vscode"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; -import { BaseConfig, RunResult } from ".."; +import { BaseConfig, LogLineTypeEnum, RunResult } from ".."; import { getGlobalStorageUri } from "../../components/ExtensionContext"; @@ -14,6 +14,19 @@ import { Session } from "../session"; // import { scriptContent } from "./script"; import { LineCodes } from "./types"; +const LogLineTypes: LogLineTypeEnum[] = [ + "normal", + "hilighted", + "source", + "title", + "byline", + "footnote", + "error", + "warning", + "note", + "message", +]; + let sessionInstance: SASPYSession; /** @@ -32,7 +45,8 @@ export class SASPYSession extends Session { private _runReject: ((reason?) => void) | undefined; private _workDirectory: string; private _pollingForLogResults: boolean; - + private _logLineType = 0; + public set config(value: Config) { this._config = value; } @@ -41,7 +55,7 @@ export class SASPYSession extends Session { * Initialization logic that should be performed prior to execution. * @returns void promise. */ - public setup = async (): Promise => { + protected establishConnection = async (): Promise => { const setupPromise = new Promise((resolve, reject) => { this._runResolve = resolve; this._runReject = reject; @@ -133,7 +147,6 @@ ll=sas.submit(vscode_saspy_code) this._shellProcess.stdin.write(`sas\n`); if (this._config.sasOptions?.length > 0) { - // console.log('sas option'); const sasOptsInput = `$sasOpts=${this.formatSASOptions( this._config.sasOptions, )}\n`; @@ -309,9 +322,9 @@ ${codeWithEnd} ); if (this._workDirectory) { - this._onExecutionLogFn?.([{ type: "normal", line }]); + this._onExecutionLogFn?.([{ type: this.getLogLineType(), line }]); } else { - this._onSessionLogFn?.([{ type: "normal", line }]); + this._onSessionLogFn?.([{ type: this.getLogLineType(), line }]); } } }); @@ -334,9 +347,22 @@ ${codeWithEnd} return true; } + if (line.includes(LineCodes.LogLineType)) { + const start = + line.indexOf(LineCodes.LogLineType) + LineCodes.LogLineType.length + 1; + this._logLineType = parseInt(line.slice(start, start + 1)); + return true; + } + return false; } + private getLogLineType(): LogLineTypeEnum { + const result = LogLineTypes[this._logLineType]; + this._logLineType = 0; + return result; + } + /** * Generic call for use on stdin write completion. * @param err The error encountered on the write attempt. Undefined if no error occurred. diff --git a/client/src/connection/saspy/types.ts b/client/src/connection/saspy/types.ts index d784601ed..0e4734bfc 100644 --- a/client/src/connection/saspy/types.ts +++ b/client/src/connection/saspy/types.ts @@ -6,4 +6,5 @@ export enum LineCodes { RunCancelledCode = "--vscode-sas-extension-run-cancelled--", RunEndCode = "--vscode-sas-extension-submit-end--", SessionCreatedCode = "--vscode-sas-extension-session-created--", + LogLineType = "--vscode-sas-extension-log-line-type--", }