Files
azuredatastudio/src/sql/workbench/services/languageAssociation/common/doHandleUpgrade.ts
Anthony Dresser 9327624930 Add more to strict nulls (#11871)
* add more to strict nulls

* maintain error handling properly

* fix lint
2020-08-19 18:38:34 -07:00

31 lines
1.5 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { EditorInput } from 'vs/workbench/common/editor';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { Extensions as ILanguageAssociationExtensions, ILanguageAssociationRegistry } from 'sql/workbench/services/languageAssociation/common/languageAssociation';
import { Registry } from 'vs/platform/registry/common/platform';
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
const languageRegistry = Registry.as<ILanguageAssociationRegistry>(ILanguageAssociationExtensions.LanguageAssociations);
export function doHandleUpgrade(editor?: EditorInput): EditorInput | undefined {
if (editor instanceof UntitledTextEditorInput || editor instanceof FileEditorInput) {
let language: string | undefined;
if (editor instanceof UntitledTextEditorInput) {
language = editor.getMode();
} else {
language = editor.getPreferredMode();
}
if (language) {
const association = languageRegistry.getAssociationForLanguage(language);
if (association && association.syncConvertinput) {
return association.syncConvertinput(editor);
}
}
}
return editor;
}