diff --git a/rascal-vscode-extension/src/fs/RascalFileSystemProviders.ts b/rascal-vscode-extension/src/fs/RascalFileSystemProviders.ts index 54dd0b3c..3eb1dc8c 100644 --- a/rascal-vscode-extension/src/fs/RascalFileSystemProviders.ts +++ b/rascal-vscode-extension/src/fs/RascalFileSystemProviders.ts @@ -47,19 +47,30 @@ export class RascalFileSystemProvider implements vscode.FileSystemProvider { }); } - - - registerSchemes(schemes:string[]):void { - schemes + /** + * Attemptes to register all schemes. + * @param schemes The list of schemes to register for this provider + * @returns `true` if all schemes were registered successfully; `false` if any schemes failed to register. + */ + tryRegisterSchemes(schemes: string[]): boolean { + return schemes .filter(s => !this.protectedSchemes.includes(s)) + // we add support for schemes that look inside a jar + .concat(schemes + .filter(s => s !== "jar" && s !== "zip" && s !== "compressed") + .map(s => "jar+" + s)) .filter(isUnknownFileSystem) - .forEach(s => vscode.workspace.registerFileSystemProvider(s, this)); - // we add support for schemes that look inside a jar - schemes - .filter(s => s !== "jar" && s !== "zip" && s !== "compressed") - .map(s => "jar+" + s) - .filter(isUnknownFileSystem) - .forEach(s => vscode.workspace.registerFileSystemProvider(s, this)); + .map(s => { + try { + vscode.workspace.registerFileSystemProvider(s, this); + this.client.info(`Scheme registered: ${s}`); + return true; + } catch (error) { + this.client.error(`Unable to register scheme: ${s}\n${error}`); + return false; + } + }) + .every(b => b); } watch(uri: vscode.Uri, options: { recursive: boolean; excludes: string[]; }): vscode.Disposable { diff --git a/rascal-vscode-extension/src/fs/VSCodeURIResolver.ts b/rascal-vscode-extension/src/fs/VSCodeURIResolver.ts index 17519660..a5e0bdd1 100644 --- a/rascal-vscode-extension/src/fs/VSCodeURIResolver.ts +++ b/rascal-vscode-extension/src/fs/VSCodeURIResolver.ts @@ -220,10 +220,6 @@ export class VSCodeUriResolverServer implements Disposable { toIgnore.forEach(v => this.rascalNativeSchemes.add(v)); } - getIgnoredSchemes(): string[] { - return Array.from(this.rascalNativeSchemes.values()); - } - dispose() { this.server.close(); this.activeClients.forEach(c => c.dispose()); diff --git a/rascal-vscode-extension/src/lsp/RascalLSPConnection.ts b/rascal-vscode-extension/src/lsp/RascalLSPConnection.ts index e8c6c1e5..b46a59da 100644 --- a/rascal-vscode-extension/src/lsp/RascalLSPConnection.ts +++ b/rascal-vscode-extension/src/lsp/RascalLSPConnection.ts @@ -62,16 +62,13 @@ export async function activateLanguageClient( const schemesReply = client.sendRequest("rascal/filesystem/schemes"); schemesReply.then( schemes => { - // avoid registering the same schemes multiple times - const knownRascalNativeSchemes = vfsServer.getIgnoredSchemes(); - const remainingSchemes = schemes.filter(s => !knownRascalNativeSchemes.includes(s)); - if (remainingSchemes.length) { - vfsServer.ignoreSchemes(remainingSchemes); - new RascalFileSystemProvider(client).registerSchemes(schemes); + vfsServer.ignoreSchemes(schemes); + const allRegistered = new RascalFileSystemProvider(client).tryRegisterSchemes(schemes); + if (!allRegistered) { + client.warn("At least one of the expected schemes failed to register.", { expectedSchemes: schemes }); } }); - return client; }