Skip to content

Commit

Permalink
fix: setup to establishConnection
Browse files Browse the repository at this point in the history
Signed-off-by: Shuguang Sun <[email protected]>
  • Loading branch information
ShuguangSun committed Apr 30, 2024
1 parent 059d741 commit 3d43195
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
38 changes: 32 additions & 6 deletions client/src/connection/saspy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;

/**
Expand All @@ -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;
}
Expand All @@ -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<void> => {
protected establishConnection = async (): Promise<void> => {
const setupPromise = new Promise<void>((resolve, reject) => {
this._runResolve = resolve;
this._runReject = reject;
Expand Down Expand Up @@ -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`;
Expand Down Expand Up @@ -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 }]);
}
}
});
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions client/src/connection/saspy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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--",
}

0 comments on commit 3d43195

Please sign in to comment.