File tree Expand file tree Collapse file tree 3 files changed +26
-12
lines changed
Expand file tree Collapse file tree 3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- import * as fs from "fs" ;
54import path = require( "path" ) ;
5+ import utils = require( "../utils" )
66import vscode = require( "vscode" ) ;
77
88export class ExamplesFeature implements vscode . Disposable {
99 private command : vscode . Disposable ;
10- private examplesPath : string ;
10+ private examplesPath : vscode . Uri ;
1111
1212 constructor ( ) {
13- this . examplesPath = path . resolve ( __dirname , "../examples" ) ;
13+ this . examplesPath = vscode . Uri . file ( path . resolve ( __dirname , "../examples" ) ) ;
1414 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 ) ;
2016 // Return existence of the path for testing. The `vscode.openFolder`
2117 // command should do this, but doesn't (yet).
22- return fs . existsSync ( this . examplesPath )
18+ return utils . fileExists ( this . examplesPath ) ;
2319 } ) ;
2420 }
2521
Original file line number Diff line number Diff line change 22// Licensed under the MIT License.
33
44import * as path from "path" ;
5- import * as fs from "fs" ;
65import vscode = require( "vscode" ) ;
76import { SessionManager } from "../session" ;
87import Settings = require( "../settings" ) ;
@@ -144,7 +143,7 @@ export class PesterTestsFeature implements vscode.Disposable {
144143 //
145144 // Ensure the necessary script exists (for testing). The debugger will
146145 // start regardless, but we also pass its success along.
147- return fs . existsSync ( this . invokePesterStubScriptPath )
146+ return utils . fileExists ( this . invokePesterStubScriptPath )
148147 && vscode . debug . startDebugging ( vscode . workspace . workspaceFolders [ 0 ] , launchConfig ) ;
149148 }
150149}
Original file line number Diff line number Diff line change 66import fs = require( "fs" ) ;
77import os = require( "os" ) ;
88import path = require( "path" ) ;
9+ import vscode = require( "vscode" ) ;
910
1011export const PowerShellLanguageId = "powershell" ;
1112
12- export function ensurePathExists ( targetPath : string ) {
13+ export function ensurePathExists ( targetPath : string ) : void {
1314 // Ensure that the path exists
1415 try {
16+ // TODO: Use vscode.workspace.fs
1517 fs . mkdirSync ( targetPath ) ;
1618 } catch ( e ) {
1719 // If the exception isn't to indicate that the folder exists already, rethrow it.
@@ -21,6 +23,23 @@ export function ensurePathExists(targetPath: string) {
2123 }
2224}
2325
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+
2443export function getPipePath ( pipeName : string ) {
2544 if ( os . platform ( ) === "win32" ) {
2645 return "\\\\.\\pipe\\" + pipeName ;
You can’t perform that action at this time.
0 commit comments