Fix SQL/Notebook editors opening as plaintext (#16442)

* Register overrides at startup

* Always wait for extensions

* Fix compile errors
This commit is contained in:
Charles Gagnon
2021-07-27 13:46:16 -07:00
committed by GitHub
parent 7a35d4aeeb
commit 2d8e0d648a
3 changed files with 85 additions and 80 deletions

View File

@@ -43,7 +43,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
private _contributionPoints: Map<string | glob.IRelativePattern, ContributionPoints> = new Map<string | glob.IRelativePattern, ContributionPoints>();
private static readonly overrideCacheStorageID = 'editorOverrideService.cache';
private cache: Set<string> | undefined;
// private cache: Set<string> | undefined; {{SQL CARBON EDIT}} Remove unused
constructor(
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@@ -56,7 +56,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
) {
super();
// Read in the cache on statup
this.cache = new Set<string>(JSON.parse(this.storageService.get(EditorOverrideService.overrideCacheStorageID, StorageScope.GLOBAL, JSON.stringify([]))));
// this.cache = new Set<string>(JSON.parse(this.storageService.get(EditorOverrideService.overrideCacheStorageID, StorageScope.GLOBAL, JSON.stringify([])))); {{SQL CARBON EDIT}} Remove unused
this.storageService.remove(EditorOverrideService.overrideCacheStorageID, StorageScope.GLOBAL);
this._register(this.storageService.onWillSaveState(() => {
@@ -65,16 +65,18 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
}));
// When extensions have registered we no longer need the cache
/* {{SQL CARBON EDIT}} Remove unused
this.extensionService.onDidRegisterExtensions(() => {
this.cache = undefined;
});
*/
}
async resolveEditorOverride(editor: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup): Promise<IEditorInputWithOptionsAndGroup | undefined> {
// If it was an override before we await for the extensions to activate and then proceed with overriding or else they won't be registered
if (this.cache && editor.resource && this.resourceMatchesCache(editor.resource)) {
await this.extensionService.whenInstalledExtensionsRegistered();
}
//if (this.cache && editor.resource && this.resourceMatchesCache(editor.resource)) { // {{SQL CARBON EDIT}} Always wait for extensions so that our language-based overrides (SQL/Notebooks) will always have those registered
await this.extensionService.whenInstalledExtensionsRegistered();
//}
if (options?.override === EditorOverride.DISABLED) {
throw new Error(`Calling resolve editor override when override is explicitly disabled!`);
@@ -547,6 +549,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
this.storageService.store(EditorOverrideService.overrideCacheStorageID, JSON.stringify(Array.from(cacheStorage)), StorageScope.GLOBAL, StorageTarget.MACHINE);
}
/* {{SQL CARBON EDIT}} Remove unused
private resourceMatchesCache(resource: URI): boolean {
if (!this.cache) {
return false;
@@ -559,6 +562,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
}
return false;
}
*/
}
registerSingleton(IEditorOverrideService, EditorOverrideService);