VSCode merge (#4610)

* Merge from vscode e388c734f30757875976c7e326d6cfeee77710de

* fix yarn lcoks

* remove small issue
This commit is contained in:
Anthony Dresser
2019-03-20 10:39:09 -07:00
committed by GitHub
parent 87765e8673
commit c814b92557
310 changed files with 6606 additions and 2129 deletions

View File

@@ -28,26 +28,18 @@ export interface IResourceEncoding {
export interface IFileService {
_serviceBrand: any;
/**
* Helper to determine read/write encoding for resources.
*/
encoding: IResourceEncodings;
/**
* Allows to listen for file changes. The event will fire for every file within the opened workspace
* (if any) as well as all files that have been watched explicitly using the #watchFileChanges() API.
*/
onFileChanges: Event<FileChangesEvent>;
/**
* An event that is fired upon successful completion of a certain file operation.
*/
onAfterOperation: Event<FileOperationEvent>;
//#region File System Provider
/**
* An event that is fired when a file system provider is added or removed
*/
onDidChangeFileSystemProviderRegistrations: Event<IFileSystemProviderRegistrationEvent>;
readonly onDidChangeFileSystemProviderRegistrations: Event<IFileSystemProviderRegistrationEvent>;
/**
* An event that is fired when a file system provider is about to be activated. Listeners
* can join this event with a long running promise to help in the activation process.
*/
readonly onWillActivateFileSystemProvider: Event<IFileSystemProviderActivationEvent>;
/**
* Registers a file system provider for a certain scheme.
@@ -64,6 +56,24 @@ export interface IFileService {
*/
canHandleResource(resource: URI): boolean;
//#endregion
/**
* Helper to determine read/write encoding for resources.
*/
encoding: IResourceEncodings;
/**
* Allows to listen for file changes. The event will fire for every file within the opened workspace
* (if any) as well as all files that have been watched explicitly using the #watchFileChanges() API.
*/
readonly onFileChanges: Event<FileChangesEvent>;
/**
* An event that is fired upon successful completion of a certain file operation.
*/
readonly onAfterOperation: Event<FileOperationEvent>;
/**
* Resolve the properties of a file identified by the resource.
*
@@ -129,12 +139,6 @@ export interface IFileService {
*/
createFile(resource: URI, content?: string, options?: ICreateFileOptions): Promise<IFileStat>;
/**
* Reads a folder's content with the given path. The returned promise
* will have the list of children as a result.
*/
readFolder(resource: URI): Promise<string[]>;
/**
* Creates a new folder with the given path. The returned promise
* will have the stat model object as a result.
@@ -234,12 +238,88 @@ export interface IFileSystemProvider {
write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number>;
}
export enum FileSystemProviderErrorCode {
FileExists = 'EntryExists',
FileNotFound = 'EntryNotFound',
FileNotADirectory = 'EntryNotADirectory',
FileIsADirectory = 'EntryIsADirectory',
NoPermissions = 'NoPermissions',
Unavailable = 'Unavailable'
}
export class FileSystemProviderError extends Error {
constructor(message: string, public readonly code?: FileSystemProviderErrorCode) {
super(message);
}
}
export function createFileSystemProviderError(error: Error, code?: FileSystemProviderErrorCode): FileSystemProviderError {
const providerError = new FileSystemProviderError(error.toString(), code);
markAsFileSystemProviderError(providerError);
return providerError;
}
export function markAsFileSystemProviderError(error: Error, code?: FileSystemProviderErrorCode): Error {
error.name = code ? `${code} (FileSystemError)` : `FileSystemError`;
return error;
}
export function toFileSystemProviderErrorCode(error: Error): FileSystemProviderErrorCode | undefined {
// FileSystemProviderError comes with the code
if (error instanceof FileSystemProviderError) {
return error.code;
}
// Any other error, check for name match by assuming that the error
// went through the markAsFileSystemProviderError() method
const match = /^(.+) \(FileSystemError\)$/.exec(error.name);
if (!match) {
return undefined;
}
switch (match[1]) {
case FileSystemProviderErrorCode.FileExists: return FileSystemProviderErrorCode.FileExists;
case FileSystemProviderErrorCode.FileIsADirectory: return FileSystemProviderErrorCode.FileIsADirectory;
case FileSystemProviderErrorCode.FileNotADirectory: return FileSystemProviderErrorCode.FileNotADirectory;
case FileSystemProviderErrorCode.FileNotFound: return FileSystemProviderErrorCode.FileNotFound;
case FileSystemProviderErrorCode.NoPermissions: return FileSystemProviderErrorCode.NoPermissions;
case FileSystemProviderErrorCode.Unavailable: return FileSystemProviderErrorCode.Unavailable;
}
return undefined;
}
export function toFileOperationResult(error: Error): FileOperationResult {
switch (toFileSystemProviderErrorCode(error)) {
case FileSystemProviderErrorCode.FileNotFound:
return FileOperationResult.FILE_NOT_FOUND;
case FileSystemProviderErrorCode.FileIsADirectory:
return FileOperationResult.FILE_IS_DIRECTORY;
case FileSystemProviderErrorCode.NoPermissions:
return FileOperationResult.FILE_PERMISSION_DENIED;
case FileSystemProviderErrorCode.FileExists:
return FileOperationResult.FILE_MOVE_CONFLICT;
case FileSystemProviderErrorCode.FileNotADirectory:
default:
return FileOperationResult.FILE_OTHER_ERROR;
}
}
export interface IFileSystemProviderRegistrationEvent {
added: boolean;
scheme: string;
provider?: IFileSystemProvider;
}
export interface IFileSystemProviderActivationEvent {
scheme: string;
join(promise: Promise<void>): void;
}
export const enum FileOperation {
CREATE,
DELETE,
@@ -655,7 +735,8 @@ export const enum FileOperationResult {
FILE_PERMISSION_DENIED,
FILE_TOO_LARGE,
FILE_INVALID_PATH,
FILE_EXCEED_MEMORY_LIMIT
FILE_EXCEED_MEMORY_LIMIT,
FILE_OTHER_ERROR
}
export const AutoSaveConfiguration = {
@@ -942,3 +1023,38 @@ export enum FileKind {
export const MIN_MAX_MEMORY_SIZE_MB = 2048;
export const FALLBACK_MAX_MEMORY_SIZE_MB = 4096;
// TODO@ben remove traces of legacy file service
export const ILegacyFileService = createDecorator<ILegacyFileService>('legacyFileService');
export interface ILegacyFileService {
_serviceBrand: any;
encoding: IResourceEncodings;
onFileChanges: Event<FileChangesEvent>;
onAfterOperation: Event<FileOperationEvent>;
resolveFile(resource: URI, options?: IResolveFileOptions): Promise<IFileStat>;
resolveFiles(toResolve: { resource: URI, options?: IResolveFileOptions }[]): Promise<IResolveFileResult[]>;
existsFile(resource: URI): Promise<boolean>;
resolveContent(resource: URI, options?: IResolveContentOptions): Promise<IContent>;
resolveStreamContent(resource: URI, options?: IResolveContentOptions): Promise<IStreamContent>;
updateContent(resource: URI, value: string | ITextSnapshot, options?: IUpdateContentOptions): Promise<IFileStat>;
moveFile(source: URI, target: URI, overwrite?: boolean): Promise<IFileStat>;
copyFile(source: URI, target: URI, overwrite?: boolean): Promise<IFileStat>;
createFile(resource: URI, content?: string, options?: ICreateFileOptions): Promise<IFileStat>;
del(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): Promise<void>;
watchFileChanges(resource: URI): void;
unwatchFileChanges(resource: URI): void;
}