mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 09:35:37 -05:00
Fix SQL/Notebook editors opening as plaintext (#16442)
* Register overrides at startup * Always wait for extensions * Fix compile errors
This commit is contained in:
@@ -677,47 +677,48 @@ export class NotebookEditorOverrideContribution extends Disposable implements IW
|
||||
@IModeService private _modeService: IModeService
|
||||
) {
|
||||
super();
|
||||
this.registerEditorOverride();
|
||||
}
|
||||
|
||||
private registerEditorOverride(): void {
|
||||
this.registerEditorOverrides();
|
||||
// Refresh the editor overrides whenever the languages change so we ensure we always have
|
||||
// the latest up to date list of extensions for each language
|
||||
this._modeService.onLanguagesMaybeChanged(() => {
|
||||
this._registeredOverrides.clear();
|
||||
// List of language IDs to associate the query editor for. These are case sensitive.
|
||||
NotebookEditorInputAssociation.languages.map(lang => {
|
||||
const langExtensions = this._modeService.getExtensions(lang);
|
||||
if (langExtensions.length === 0) {
|
||||
return;
|
||||
this.registerEditorOverrides();
|
||||
});
|
||||
}
|
||||
|
||||
private registerEditorOverrides(): void {
|
||||
this._registeredOverrides.clear();
|
||||
// List of language IDs to associate the query editor for. These are case sensitive.
|
||||
NotebookEditorInputAssociation.languages.map(lang => {
|
||||
const langExtensions = this._modeService.getExtensions(lang);
|
||||
if (langExtensions.length === 0) {
|
||||
return;
|
||||
}
|
||||
// Create the selector from the list of all the language extensions we want to associate with the
|
||||
// notebook editor (filtering out any languages which didn't have any extensions registered yet)
|
||||
const selector = `*{${langExtensions.join(',')}}`;
|
||||
this._registeredOverrides.add(this._editorOverrideService.registerContributionPoint(
|
||||
selector,
|
||||
{
|
||||
id: NotebookEditor.ID,
|
||||
label: NotebookEditor.LABEL,
|
||||
describes: (currentEditor) => currentEditor instanceof FileNotebookInput,
|
||||
priority: ContributedEditorPriority.builtin
|
||||
},
|
||||
{},
|
||||
(resource, options, group) => {
|
||||
const fileInput = this._editorService.createEditorInput({
|
||||
resource: resource
|
||||
}) as FileEditorInput;
|
||||
// Try to convert the input, falling back to just a plain file input if we're unable to
|
||||
const newInput = this.tryConvertInput(fileInput, lang) ?? fileInput;
|
||||
return { editor: newInput, options: options, group: group };
|
||||
},
|
||||
(diffEditorInput, options, group) => {
|
||||
// Try to convert the input, falling back to the original input if we're unable to
|
||||
const newInput = this.tryConvertInput(diffEditorInput, lang) ?? diffEditorInput;
|
||||
return { editor: newInput, options: options, group: group };
|
||||
}
|
||||
// Create the selector from the list of all the language extensions we want to associate with the
|
||||
// notebook editor (filtering out any languages which didn't have any extensions registered yet)
|
||||
const selector = `*{${langExtensions.join(',')}}`;
|
||||
this._registeredOverrides.add(this._editorOverrideService.registerContributionPoint(
|
||||
selector,
|
||||
{
|
||||
id: NotebookEditor.ID,
|
||||
label: NotebookEditor.LABEL,
|
||||
describes: (currentEditor) => currentEditor instanceof FileNotebookInput,
|
||||
priority: ContributedEditorPriority.builtin
|
||||
},
|
||||
{},
|
||||
(resource, options, group) => {
|
||||
const fileInput = this._editorService.createEditorInput({
|
||||
resource: resource
|
||||
}) as FileEditorInput;
|
||||
// Try to convert the input, falling back to just a plain file input if we're unable to
|
||||
const newInput = this.tryConvertInput(fileInput, lang) ?? fileInput;
|
||||
return { editor: newInput, options: options, group: group };
|
||||
},
|
||||
(diffEditorInput, options, group) => {
|
||||
// Try to convert the input, falling back to the original input if we're unable to
|
||||
const newInput = this.tryConvertInput(diffEditorInput, lang) ?? diffEditorInput;
|
||||
return { editor: newInput, options: options, group: group };
|
||||
}
|
||||
));
|
||||
});
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -733,4 +734,4 @@ export class NotebookEditorOverrideContribution extends Disposable implements IW
|
||||
}
|
||||
|
||||
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
|
||||
.registerWorkbenchContribution(NotebookEditorOverrideContribution, LifecyclePhase.Restored);
|
||||
.registerWorkbenchContribution(NotebookEditorOverrideContribution, LifecyclePhase.Starting);
|
||||
|
||||
@@ -510,47 +510,47 @@ export class QueryEditorOverrideContribution extends Disposable implements IWork
|
||||
) {
|
||||
super();
|
||||
this.registerEditorOverrides();
|
||||
}
|
||||
|
||||
private registerEditorOverrides(): void {
|
||||
// Refresh the editor overrides whenever the languages change so we ensure we always have
|
||||
// the latest up to date list of extensions for each language
|
||||
this._modeService.onLanguagesMaybeChanged(() => {
|
||||
this._registeredOverrides.clear();
|
||||
// List of language IDs to associate the query editor for. These are case sensitive.
|
||||
QueryEditorLanguageAssociation.languages.map(lang => {
|
||||
const langExtensions = this._modeService.getExtensions(lang);
|
||||
if (langExtensions.length === 0) {
|
||||
return;
|
||||
}
|
||||
// Create the selector from the list of all the language extensions we want to associate with the
|
||||
// query editor (filtering out any languages which didn't have any extensions registered yet)
|
||||
const selector = `*{${langExtensions.join(',')}}`;
|
||||
this._registeredOverrides.add(this._editorOverrideService.registerContributionPoint(
|
||||
selector,
|
||||
{
|
||||
id: QueryEditor.ID,
|
||||
label: QueryEditor.LABEL,
|
||||
describes: (currentEditor) => currentEditor instanceof FileQueryEditorInput,
|
||||
priority: ContributedEditorPriority.builtin
|
||||
},
|
||||
{},
|
||||
(resource, options, group) => {
|
||||
const fileInput = this._editorService.createEditorInput({
|
||||
resource: resource
|
||||
}) as FileEditorInput;
|
||||
const langAssociation = languageAssociationRegistry.getAssociationForLanguage(lang);
|
||||
const queryEditorInput = langAssociation?.syncConvertinput?.(fileInput);
|
||||
if (!queryEditorInput) {
|
||||
this._logService.warn('Unable to create input for overriding editor ', resource);
|
||||
return undefined;
|
||||
}
|
||||
return { editor: queryEditorInput, options: options, group: group };
|
||||
this.registerEditorOverrides();
|
||||
});
|
||||
}
|
||||
|
||||
private registerEditorOverrides(): void {
|
||||
this._registeredOverrides.clear();
|
||||
// List of language IDs to associate the query editor for. These are case sensitive.
|
||||
QueryEditorLanguageAssociation.languages.map(lang => {
|
||||
const langExtensions = this._modeService.getExtensions(lang);
|
||||
if (langExtensions.length === 0) {
|
||||
return;
|
||||
}
|
||||
// Create the selector from the list of all the language extensions we want to associate with the
|
||||
// query editor (filtering out any languages which didn't have any extensions registered yet)
|
||||
const selector = `*{${langExtensions.join(',')}}`;
|
||||
this._registeredOverrides.add(this._editorOverrideService.registerContributionPoint(
|
||||
selector,
|
||||
{
|
||||
id: QueryEditor.ID,
|
||||
label: QueryEditor.LABEL,
|
||||
describes: (currentEditor) => currentEditor instanceof FileQueryEditorInput,
|
||||
priority: ContributedEditorPriority.builtin
|
||||
},
|
||||
{},
|
||||
(resource, options, group) => {
|
||||
const fileInput = this._editorService.createEditorInput({
|
||||
resource: resource
|
||||
}) as FileEditorInput;
|
||||
const langAssociation = languageAssociationRegistry.getAssociationForLanguage(lang);
|
||||
const queryEditorInput = langAssociation?.syncConvertinput?.(fileInput);
|
||||
if (!queryEditorInput) {
|
||||
this._logService.warn('Unable to create input for overriding editor ', resource);
|
||||
return undefined;
|
||||
}
|
||||
));
|
||||
});
|
||||
return { editor: queryEditorInput, options: options, group: group };
|
||||
}
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
workbenchRegistry.registerWorkbenchContribution(QueryEditorOverrideContribution, LifecyclePhase.Restored);
|
||||
workbenchRegistry.registerWorkbenchContribution(QueryEditorOverrideContribution, LifecyclePhase.Starting);
|
||||
|
||||
Reference in New Issue
Block a user