-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add filesystem abstraction and remove node API calls
- Loading branch information
1 parent
802fb83
commit c5705dd
Showing
6 changed files
with
152 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { FileSystemProvider, FileType } from "../../jsonLanguageTypes"; | ||
import { URI } from 'vscode-uri'; | ||
import { stat as fsStat } from 'fs'; | ||
|
||
export function getFsProvider(): FileSystemProvider { | ||
return { | ||
stat(documentUriString: string) { | ||
return new Promise((c, e) => { | ||
const documentUri = URI.parse(documentUriString); | ||
if (documentUri.scheme !== 'file') { | ||
e(new Error('Protocol not supported: ' + documentUri.scheme)); | ||
return; | ||
} | ||
fsStat(documentUri.fsPath, (err, stats) => { | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
return c({ | ||
type: FileType.Unknown, | ||
ctime: -1, | ||
mtime: -1, | ||
size: -1 | ||
}); | ||
} else { | ||
return e(err); | ||
} | ||
} | ||
|
||
let type = FileType.Unknown; | ||
if (stats.isFile()) { | ||
type = FileType.File; | ||
} else if (stats.isDirectory()) { | ||
type = FileType.Directory; | ||
} else if (stats.isSymbolicLink()) { | ||
type = FileType.SymbolicLink; | ||
} | ||
|
||
c({ | ||
type, | ||
ctime: stats.ctime.getTime(), | ||
mtime: stats.mtime.getTime(), | ||
size: stats.size | ||
}); | ||
}); | ||
}); | ||
}, | ||
}; | ||
} |