@@ -17,7 +17,6 @@ import {
1717
1818import { BaseConfig , RunResult } from ".." ;
1919import { updateStatusBarItem } from "../../components/StatusBarItem" ;
20- import { LineParser } from "../LineParser" ;
2120import { Session } from "../session" ;
2221import { extractOutputHtmlFileName } from "../util" ;
2322import { AuthHandler } from "./auth" ;
@@ -56,7 +55,6 @@ export class SSHSession extends Session {
5655 private _sessionReady : boolean ;
5756 private _authHandler : AuthHandler ;
5857 private _workDirectory : string ;
59- private _workDirectoryParser : LineParser ;
6058 private _authsLeft : AuthenticationType [ ] ;
6159
6260 constructor ( c ?: Config , client ?: Client ) {
@@ -65,11 +63,6 @@ export class SSHSession extends Session {
6563 this . _conn = client ;
6664 this . _sessionReady = false ;
6765 this . _authHandler = new AuthHandler ( ) ;
68- this . _workDirectoryParser = new LineParser (
69- WORK_DIR_START_TAG ,
70- WORK_DIR_END_TAG ,
71- false ,
72- ) ;
7366 this . _authsLeft = [ ] ;
7467 }
7568
@@ -181,19 +174,23 @@ export class SSHSession extends Session {
181174
182175 s . on ( "data" , ( data ) => {
183176 fileContents += data . toString ( ) ;
184- } ) . on ( "close" , ( code ) => {
185- const rc : number = code ;
186-
187- if ( rc === 0 ) {
188- //Make sure that the html has a valid body
189- //TODO #185: should this be refactored into a shared location?
190- if ( fileContents . search ( '<*id="IDX*.+">' ) !== - 1 ) {
191- runResult . html5 = fileContents ;
192- runResult . title = l10n . t ( "Result" ) ;
177+ } )
178+ . on ( "close" , ( code ) => {
179+ const rc : number = code ;
180+
181+ if ( rc === 0 ) {
182+ //Make sure that the html has a valid body
183+ //TODO #185: should this be refactored into a shared location?
184+ if ( fileContents . search ( '<*id="IDX*.+">' ) !== - 1 ) {
185+ runResult . html5 = fileContents ;
186+ runResult . title = l10n . t ( "Result" ) ;
187+ }
193188 }
194- }
195- this . _resolve ?.( runResult ) ;
196- } ) ;
189+ this . _resolve ?.( runResult ) ;
190+ } )
191+ . on ( "error" , ( err ) => {
192+ console . log ( err ) ;
193+ } ) ;
197194 } ,
198195 ) ;
199196 } ;
@@ -203,22 +200,15 @@ export class SSHSession extends Session {
203200 updateStatusBarItem ( false ) ;
204201 } ;
205202
206- private fetchWorkDirectory = ( line : string ) : string => {
207- const foundWorkDirectory = this . _workDirectoryParser . processLine ( line ) ;
208- // We don't want to output any of the captured lines
209- if ( this . _workDirectoryParser . isCapturingLine ( ) ) {
210- return ;
211- }
212-
213- return foundWorkDirectory || "" ;
214- } ;
215-
216203 private resolveSystemVars = ( ) : void => {
217- const code = `%let workDir = %sysfunc(pathname(work));
218- %put ${ WORK_DIR_START_TAG } &workDir${ WORK_DIR_END_TAG } ;
219- %let rc = %sysfunc(dlgcdir("&workDir"));
220- run;
221- ` ;
204+ const code = `%let wd = %sysfunc(pathname(work));
205+ %let rc = %sysfunc(dlgcdir("&wd"));
206+ data _null_; length x $ 4096;
207+ file STDERR;
208+ x = resolve('&wd'); put '${ WORK_DIR_START_TAG } ' x '${ WORK_DIR_END_TAG } ';
209+ run;
210+
211+ ` ;
222212 this . _stream . write ( code ) ;
223213 } ;
224214
@@ -233,6 +223,15 @@ export class SSHSession extends Session {
233223 return ;
234224 }
235225
226+ if ( this . _sessionReady && ! this . _workDirectory ) {
227+ const match = output . match (
228+ `${ WORK_DIR_START_TAG } (/[\\s\\S]*?)${ WORK_DIR_END_TAG } ` ,
229+ ) ;
230+ if ( match && match . length > 1 ) {
231+ this . _workDirectory = match [ 1 ] . trimEnd ( ) . replace ( / ( \r \n | \n | \r ) / gm, "" ) ;
232+ }
233+ }
234+
236235 const outputLines = output . split ( / \n | \r \n / ) ;
237236 outputLines . forEach ( ( line ) => {
238237 if ( ! line ) {
@@ -250,14 +249,6 @@ export class SSHSession extends Session {
250249 ) ;
251250 this . _onExecutionLogFn ?.( [ { type : "normal" , line } ] ) ;
252251 }
253-
254- if ( this . _sessionReady && ! this . _workDirectory ) {
255- const foundWorkDir = this . fetchWorkDirectory ( line ) ;
256- if ( foundWorkDir ) {
257- const match = foundWorkDir . match ( / \/ [ ^ \s \r ] + / ) ;
258- this . _workDirectory = match ? match [ 0 ] : "" ;
259- }
260- }
261252 } ) ;
262253 } ;
263254
0 commit comments