@@ -46,12 +46,13 @@ export class PyDocumentForNotebookCell implements vscode.TextDocument {
4646 this . temporaryPath = vscode . Uri . file (
4747 path . join (
4848 tmpdir ( ) ,
49- `${ hashjs . sha1 ( ) . update ( notebookCellDocument . uri . toString ( ) ) . digest ( 'hex' ) . substr ( 0 , 12 ) } .py`
49+ `${ hashjs . sha1 ( ) . update ( notebookCellDocument . uri . toString ( ) ) . digest ( 'hex' ) . substr ( 0 , 12 ) } ` ,
50+ path . basename ( notebookCellDocument . fileName )
5051 )
5152 ) ;
5253 if ( ! PyDocumentForNotebookCell . disposables . has ( this . temporaryPath . fsPath ) ) {
5354 const disposableFunc = ( ) => {
54- fs . remove ( this . temporaryPath . fsPath ) . ignoreErrors ( ) ;
55+ fs . remove ( path . basename ( this . temporaryPath . fsPath ) ) . ignoreErrors ( ) ;
5556 } ;
5657 PyDocumentForNotebookCell . disposables . set ( this . temporaryPath . fsPath , disposableFunc ) ;
5758 disposables . push ( { dispose : disposableFunc } ) ;
@@ -91,7 +92,14 @@ export class PyDocumentForNotebookCell implements vscode.TextDocument {
9192 public validatePosition ( position : vscode . Position ) : vscode . Position {
9293 return this . notebookCellDocument . validatePosition ( position ) ;
9394 }
94- private writeContents ( ) : Promise < void > {
95+ private async writeContents ( ) : Promise < void > {
96+ // Create root folder if necessary.
97+ const dir = path . dirname ( this . temporaryPath . fsPath ) ;
98+ if ( ! ( await fs . pathExists ( dir ) ) ) {
99+ await fs . mkdir ( dir ) ;
100+ }
101+
102+ // Write new contents. Use nodejs.fs cause we want this on the same machine as the extension
95103 return fs . writeFile ( this . temporaryPath . fsPath , this . contents , { encoding : 'utf-8' , flag : 'w' } ) ;
96104 }
97105}
0 commit comments