Skip to content

Commit 371f630

Browse files
authored
Merge pull request #106378 from mjbvz/add-isWritableFileSystem
Add isWritableFileSystem api
2 parents 44699b0 + a1e2114 commit 371f630

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

src/vs/vscode.proposed.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,4 +2207,26 @@ declare module 'vscode' {
22072207
}): Disposable;
22082208
}
22092209
//#endregion
2210+
2211+
//#region
2212+
2213+
export interface FileSystem {
2214+
/**
2215+
* Check if a given file system supports writing files.
2216+
*
2217+
* Keep in mind that just because a file system supports writing, that does
2218+
* not mean that writes will always succeed. There may be permissions issues
2219+
* or other errors that prevent writing a file.
2220+
*
2221+
* @param scheme The scheme of the filesystem, for example `file` or `git`.
2222+
*
2223+
* @return `true` if the file system supports writing, `false` if it does not
2224+
* support writing (i.e. it is readonly), and `undefined` if VS Code does not
2225+
* know about the filesystem.
2226+
*/
2227+
isWritableFileSystem(scheme: string): boolean | undefined;
2228+
}
2229+
2230+
2231+
//#endregion
22102232
}

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
135135
const extHostEditorInsets = rpcProtocol.set(ExtHostContext.ExtHostEditorInsets, new ExtHostEditorInsets(rpcProtocol.getProxy(MainContext.MainThreadEditorInsets), extHostEditors, initData.environment));
136136
const extHostDiagnostics = rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(rpcProtocol, extHostLogService));
137137
const extHostLanguageFeatures = rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(rpcProtocol, uriTransformer, extHostDocuments, extHostCommands, extHostDiagnostics, extHostLogService, extHostApiDeprecation));
138-
const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures));
138+
const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures, extHostConsumerFileSystem));
139139
const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpcProtocol, extHostLogService, extHostDocumentsAndEditors));
140140
const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(rpcProtocol, extHostWorkspace, extHostCommands));
141141
const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService));

src/vs/workbench/api/common/extHostFileSystem.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { State, StateMachine, LinkComputer, Edge } from 'vs/editor/common/modes/
1616
import { commonPrefixLength } from 'vs/base/common/strings';
1717
import { CharCode } from 'vs/base/common/charCode';
1818
import { VSBuffer } from 'vs/base/common/buffer';
19+
import { IExtHostConsumerFileSystem } from 'vs/workbench/api/common/extHostFileSystemConsumer';
1920

2021
class FsLinkProvider {
2122

@@ -119,7 +120,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
119120
private _linkProviderRegistration?: IDisposable;
120121
private _handlePool: number = 0;
121122

122-
constructor(mainContext: IMainContext, private _extHostLanguageFeatures: ExtHostLanguageFeatures) {
123+
constructor(mainContext: IMainContext, private _extHostLanguageFeatures: ExtHostLanguageFeatures, private readonly _fileSystemConsumer: IExtHostConsumerFileSystem) {
123124
this._proxy = mainContext.getProxy(MainContext.MainThreadFileSystem);
124125

125126
// register used schemes
@@ -142,6 +143,8 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
142143
throw new Error(`a provider for the scheme '${scheme}' is already registered`);
143144
}
144145

146+
const schemeRegistration = this._fileSystemConsumer._registerScheme(scheme, options);
147+
145148
//
146149
this._registerLinkProviderIfNotYetRegistered();
147150

@@ -197,6 +200,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
197200

198201
return toDisposable(() => {
199202
subscription.dispose();
203+
schemeRegistration.dispose();
200204
this._linkProvider.delete(scheme);
201205
this._usedSchemes.delete(scheme);
202206
this._fsProvider.delete(handle);

src/vs/workbench/api/common/extHostFileSystemConsumer.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import { FileSystemError } from 'vs/workbench/api/common/extHostTypes';
1010
import { VSBuffer } from 'vs/base/common/buffer';
1111
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1212
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
13+
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
1314

1415
export class ExtHostConsumerFileSystem implements vscode.FileSystem {
1516

1617
readonly _serviceBrand: undefined;
1718

1819
private readonly _proxy: MainThreadFileSystemShape;
1920

21+
private readonly _schemes = new Map<string, { readonly isReadonly?: boolean }>();
22+
2023
constructor(@IExtHostRpcService extHostRpc: IExtHostRpcService) {
2124
this._proxy = extHostRpc.getProxy(MainContext.MainThreadFileSystem);
2225
}
@@ -45,6 +48,14 @@ export class ExtHostConsumerFileSystem implements vscode.FileSystem {
4548
copy(source: vscode.Uri, destination: vscode.Uri, options?: { overwrite?: boolean; }): Promise<void> {
4649
return this._proxy.$copy(source, destination, { ...{ overwrite: false }, ...options }).catch(ExtHostConsumerFileSystem._handleError);
4750
}
51+
isWritableFileSystem(scheme: string): boolean | undefined {
52+
const entry = this._schemes.get(scheme);
53+
if (entry) {
54+
return !entry.isReadonly;
55+
}
56+
return undefined;
57+
}
58+
4859
private static _handleError(err: any): never {
4960
// generic error
5061
if (!(err instanceof Error)) {
@@ -68,6 +79,14 @@ export class ExtHostConsumerFileSystem implements vscode.FileSystem {
6879
default: throw new FileSystemError(err.message, err.name as files.FileSystemProviderErrorCode);
6980
}
7081
}
82+
83+
/* internal */ _registerScheme(scheme: string, options: { readonly isReadonly?: boolean }): IDisposable {
84+
this._schemes.set(scheme, options);
85+
86+
return toDisposable(() => {
87+
return this._schemes.delete(scheme);
88+
});
89+
}
7190
}
7291

7392
export interface IExtHostConsumerFileSystem extends ExtHostConsumerFileSystem { }

0 commit comments

Comments
 (0)