Skip to content

Commit

Permalink
Replace registerSchemes with tryRegisterSchemes and add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanfly committed Dec 20, 2024
1 parent 30e30af commit b8981ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
33 changes: 22 additions & 11 deletions rascal-vscode-extension/src/fs/RascalFileSystemProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions rascal-vscode-extension/src/fs/VSCodeURIResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 4 additions & 7 deletions rascal-vscode-extension/src/lsp/RascalLSPConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,13 @@ export async function activateLanguageClient(
const schemesReply = client.sendRequest<string[]>("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;
}

Expand Down

0 comments on commit b8981ee

Please sign in to comment.