mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 09:35:38 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
85
src/vs/workbench/api/node/extHostFileSystem.ts
Normal file
85
src/vs/workbench/api/node/extHostFileSystem.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { MainContext, IMainContext, ExtHostFileSystemShape, MainThreadFileSystemShape } from './extHost.protocol';
|
||||
import * as vscode from 'vscode';
|
||||
import { IStat } from 'vs/platform/files/common/files';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
|
||||
export class ExtHostFileSystem implements ExtHostFileSystemShape {
|
||||
|
||||
private readonly _proxy: MainThreadFileSystemShape;
|
||||
private readonly _provider = new Map<number, vscode.FileSystemProvider>();
|
||||
private _handlePool: number = 0;
|
||||
|
||||
constructor(mainContext: IMainContext) {
|
||||
this._proxy = mainContext.get(MainContext.MainThreadFileSystem);
|
||||
}
|
||||
|
||||
registerFileSystemProvider(scheme: string, provider: vscode.FileSystemProvider) {
|
||||
const handle = this._handlePool++;
|
||||
this._provider.set(handle, provider);
|
||||
this._proxy.$registerFileSystemProvider(handle, scheme);
|
||||
this._proxy.$onDidAddFileSystemRoot(<any>provider.root);
|
||||
let reg: IDisposable;
|
||||
if (provider.onDidChange) {
|
||||
reg = provider.onDidChange(event => this._proxy.$onFileSystemChange(handle, <any>event));
|
||||
}
|
||||
return {
|
||||
dispose: () => {
|
||||
if (reg) {
|
||||
reg.dispose();
|
||||
}
|
||||
this._provider.delete(handle);
|
||||
this._proxy.$unregisterFileSystemProvider(handle);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
$utimes(handle: number, resource: URI, mtime: number, atime: number): TPromise<IStat, any> {
|
||||
return asWinJsPromise(token => this._provider.get(handle).utimes(resource, mtime, atime));
|
||||
}
|
||||
$stat(handle: number, resource: URI): TPromise<IStat, any> {
|
||||
return asWinJsPromise(token => this._provider.get(handle).stat(resource));
|
||||
}
|
||||
$read(handle: number, offset: number, count: number, resource: URI): TPromise<number> {
|
||||
const progress = {
|
||||
report: chunk => {
|
||||
this._proxy.$reportFileChunk(handle, resource, [].slice.call(chunk));
|
||||
}
|
||||
};
|
||||
return asWinJsPromise(token => this._provider.get(handle).read(resource, offset, count, progress));
|
||||
}
|
||||
$write(handle: number, resource: URI, content: number[]): TPromise<void, any> {
|
||||
return asWinJsPromise(token => this._provider.get(handle).write(resource, Buffer.from(content)));
|
||||
}
|
||||
$unlink(handle: number, resource: URI): TPromise<void, any> {
|
||||
return asWinJsPromise(token => this._provider.get(handle).unlink(resource));
|
||||
}
|
||||
$move(handle: number, resource: URI, target: URI): TPromise<IStat, any> {
|
||||
return asWinJsPromise(token => this._provider.get(handle).move(resource, target));
|
||||
}
|
||||
$mkdir(handle: number, resource: URI): TPromise<IStat, any> {
|
||||
return asWinJsPromise(token => this._provider.get(handle).mkdir(resource));
|
||||
}
|
||||
$readdir(handle: number, resource: URI): TPromise<[URI, IStat][], any> {
|
||||
return asWinJsPromise(token => this._provider.get(handle).readdir(resource));
|
||||
}
|
||||
$rmdir(handle: number, resource: URI): TPromise<void, any> {
|
||||
return asWinJsPromise(token => this._provider.get(handle).rmdir(resource));
|
||||
}
|
||||
$fileFiles(handle: number, session: number, query: string): TPromise<void> {
|
||||
const provider = this._provider.get(handle);
|
||||
if (!provider.findFiles) {
|
||||
return TPromise.as(undefined);
|
||||
}
|
||||
const progress = { report: (uri) => this._proxy.$handleSearchProgress(handle, session, uri) };
|
||||
return asWinJsPromise(token => provider.findFiles(query, progress, token));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user