File tree 3 files changed +26
-12
lines changed
3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- import * as fs from "fs" ;
5
4
import path = require( "path" ) ;
5
+ import utils = require( "../utils" )
6
6
import vscode = require( "vscode" ) ;
7
7
8
8
export class ExamplesFeature implements vscode . Disposable {
9
9
private command : vscode . Disposable ;
10
- private examplesPath : string ;
10
+ private examplesPath : vscode . Uri ;
11
11
12
12
constructor ( ) {
13
- this . examplesPath = path . resolve ( __dirname , "../examples" ) ;
13
+ this . examplesPath = vscode . Uri . file ( path . resolve ( __dirname , "../examples" ) ) ;
14
14
this . command = vscode . commands . registerCommand ( "PowerShell.OpenExamplesFolder" , ( ) => {
15
- vscode . commands . executeCommand (
16
- "vscode.openFolder" ,
17
- vscode . Uri . file ( this . examplesPath ) ,
18
- true ) ;
19
-
15
+ vscode . commands . executeCommand ( "vscode.openFolder" , this . examplesPath , true ) ;
20
16
// Return existence of the path for testing. The `vscode.openFolder`
21
17
// command should do this, but doesn't (yet).
22
- return fs . existsSync ( this . examplesPath )
18
+ return utils . fileExists ( this . examplesPath ) ;
23
19
} ) ;
24
20
}
25
21
Original file line number Diff line number Diff line change 2
2
// Licensed under the MIT License.
3
3
4
4
import * as path from "path" ;
5
- import * as fs from "fs" ;
6
5
import vscode = require( "vscode" ) ;
7
6
import { SessionManager } from "../session" ;
8
7
import Settings = require( "../settings" ) ;
@@ -144,7 +143,7 @@ export class PesterTestsFeature implements vscode.Disposable {
144
143
//
145
144
// Ensure the necessary script exists (for testing). The debugger will
146
145
// start regardless, but we also pass its success along.
147
- return fs . existsSync ( this . invokePesterStubScriptPath )
146
+ return utils . fileExists ( this . invokePesterStubScriptPath )
148
147
&& vscode . debug . startDebugging ( vscode . workspace . workspaceFolders [ 0 ] , launchConfig ) ;
149
148
}
150
149
}
Original file line number Diff line number Diff line change 6
6
import fs = require( "fs" ) ;
7
7
import os = require( "os" ) ;
8
8
import path = require( "path" ) ;
9
+ import vscode = require( "vscode" ) ;
9
10
10
11
export const PowerShellLanguageId = "powershell" ;
11
12
12
- export function ensurePathExists ( targetPath : string ) {
13
+ export function ensurePathExists ( targetPath : string ) : void {
13
14
// Ensure that the path exists
14
15
try {
16
+ // TODO: Use vscode.workspace.fs
15
17
fs . mkdirSync ( targetPath ) ;
16
18
} catch ( e ) {
17
19
// If the exception isn't to indicate that the folder exists already, rethrow it.
@@ -21,6 +23,23 @@ export function ensurePathExists(targetPath: string) {
21
23
}
22
24
}
23
25
26
+ // Check that the file exists in an asynchronous manner that relies solely on the VS Code API, not Node's fs library.
27
+ export async function fileExists ( targetPath : string | vscode . Uri ) : Promise < boolean > {
28
+ try {
29
+ await vscode . workspace . fs . stat (
30
+ targetPath instanceof vscode . Uri
31
+ ? targetPath
32
+ : vscode . Uri . file ( targetPath ) ) ;
33
+ return true ;
34
+ } catch ( e ) {
35
+ if ( e instanceof vscode . FileSystemError . FileNotFound ) {
36
+ return false ;
37
+ }
38
+ throw e ;
39
+ }
40
+
41
+ }
42
+
24
43
export function getPipePath ( pipeName : string ) {
25
44
if ( os . platform ( ) === "win32" ) {
26
45
return "\\\\.\\pipe\\" + pipeName ;
You can’t perform that action at this time.
0 commit comments