mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 01:25:39 -05:00
strict null check contrib/editorReplace and services/queryEditor (#12166)
This commit is contained in:
@@ -50,7 +50,7 @@ export class EditDataInput extends EditorInput implements IConnectableInput {
|
||||
super();
|
||||
this._hasBootstrapped = false;
|
||||
this._updateTaskbar = new Emitter<EditDataInput>();
|
||||
this._showResultsEditor = new Emitter<EditDataInput>();
|
||||
this._showResultsEditor = new Emitter<EditDataInput | undefined>();
|
||||
this._editorInitializing = new Emitter<boolean>();
|
||||
this._setup = false;
|
||||
this._stopButtonEnabled = false;
|
||||
@@ -86,7 +86,7 @@ export class EditDataInput extends EditorInput implements IConnectableInput {
|
||||
this._register(
|
||||
this._queryModelService.onEditSessionReady((result) => {
|
||||
if (this.uri === result.ownerUri) {
|
||||
this._results.editDataGridPanel.onRefreshComplete.then(() => {
|
||||
this._results.editDataGridPanel!.onRefreshComplete.then(() => {
|
||||
this.initEditEnd(result);
|
||||
});
|
||||
}
|
||||
@@ -218,7 +218,7 @@ export class EditDataInput extends EditorInput implements IConnectableInput {
|
||||
}
|
||||
|
||||
public resolve(refresh?: boolean): Promise<IUntitledTextEditorModel & IResolvedTextEditorModel> { return this._sql.resolve(); }
|
||||
public getEncoding(): string { return this._sql.getEncoding(); }
|
||||
public getEncoding(): string | undefined { return this._sql.getEncoding(); }
|
||||
public getName(): string { return this._sql.getName(); }
|
||||
public get hasAssociatedFilePath(): boolean { return this._sql.model.hasAssociatedFilePath; }
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export class EditDataResultsInput extends EditorInput {
|
||||
|
||||
public readonly onRestoreViewStateEmitter = new Emitter<void>();
|
||||
public readonly onSaveViewStateEmitter = new Emitter<void>();
|
||||
private _editDataGridPanel: IGridPanel;
|
||||
private _editDataGridPanel?: IGridPanel;
|
||||
|
||||
constructor(private _uri: string) {
|
||||
super();
|
||||
@@ -37,11 +37,11 @@ export class EditDataResultsInput extends EditorInput {
|
||||
this._hasBootstrapped = false;
|
||||
}
|
||||
|
||||
get editDataGridPanel(): IGridPanel {
|
||||
get editDataGridPanel(): IGridPanel | undefined {
|
||||
return this._editDataGridPanel;
|
||||
}
|
||||
|
||||
set editDataGridPanel(gridPanel: IGridPanel) {
|
||||
set editDataGridPanel(gridPanel: IGridPanel | undefined) {
|
||||
this._editDataGridPanel = gridPanel;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ export abstract class QueryEditorInput extends EditorInput implements IConnectab
|
||||
public get state(): QueryEditorState { return this._state; }
|
||||
|
||||
constructor(
|
||||
private _description: string,
|
||||
private _description: string | undefined,
|
||||
protected _text: AbstractTextResourceEditorInput,
|
||||
protected _results: QueryResultsInput,
|
||||
@IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService,
|
||||
@@ -173,7 +173,7 @@ export abstract class QueryEditorInput extends EditorInput implements IConnectab
|
||||
public get text(): AbstractTextResourceEditorInput { return this._text; }
|
||||
public get results(): QueryResultsInput { return this._results; }
|
||||
// Description is shown beside the tab name in the combobox of open editors
|
||||
public getDescription(): string { return this._description; }
|
||||
public getDescription(): string | undefined { return this._description; }
|
||||
public supportsSplitEditor(): boolean { return false; }
|
||||
public revert(group: GroupIdentifier, options?: IRevertOptions): Promise<void> {
|
||||
return this._text.revert(group, options);
|
||||
|
||||
@@ -19,7 +19,7 @@ export class UntitledQueryEditorInput extends QueryEditorInput implements IEncod
|
||||
public static readonly ID = 'workbench.editorInput.untitledQueryInput';
|
||||
|
||||
constructor(
|
||||
description: string,
|
||||
description: string | undefined,
|
||||
text: UntitledTextEditorInput,
|
||||
results: QueryResultsInput,
|
||||
@IConnectionManagementService connectionManagementService: IConnectionManagementService,
|
||||
|
||||
@@ -17,6 +17,7 @@ import * as path from 'vs/base/common/path';
|
||||
import { ILanguageAssociationRegistry, Extensions as LanguageAssociationExtensions } from 'sql/workbench/services/languageAssociation/common/languageAssociation';
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
|
||||
import { isThenable } from 'vs/base/common/async';
|
||||
import { withNullAsUndefined } from 'vs/base/common/types';
|
||||
|
||||
const languageAssociationRegistry = Registry.as<ILanguageAssociationRegistry>(LanguageAssociationExtensions.LanguageAssociations);
|
||||
|
||||
@@ -44,7 +45,7 @@ export class EditorReplacementContribution implements IWorkbenchContribution {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let language: string;
|
||||
let language: string | undefined;
|
||||
if (editor instanceof FileEditorInput) {
|
||||
language = editor.getPreferredMode();
|
||||
} else if (editor instanceof UntitledTextEditorInput) {
|
||||
@@ -52,7 +53,7 @@ export class EditorReplacementContribution implements IWorkbenchContribution {
|
||||
}
|
||||
|
||||
if (!language) { // in the case the input doesn't have a preferred mode set we will attempt to guess the mode from the file path
|
||||
language = this.modeService.getModeIdByFilepathOrFirstLine(editor.resource);
|
||||
language = withNullAsUndefined(this.modeService.getModeIdByFilepathOrFirstLine(editor.resource));
|
||||
}
|
||||
|
||||
if (!language) {
|
||||
@@ -66,7 +67,7 @@ export class EditorReplacementContribution implements IWorkbenchContribution {
|
||||
editor.setMode(defaultInputCreator[0]);
|
||||
const newInput = defaultInputCreator[1].convertInput(editor);
|
||||
if (newInput) {
|
||||
return { override: isThenable(newInput) ? newInput.then(input => this.editorService.openEditor(input, options, group)) : this.editorService.openEditor(newInput, options, group) };
|
||||
return { override: isThenable(newInput) ? newInput.then(input => this.editorService.openEditor(input ?? editor, options, group)) : this.editorService.openEditor(newInput, options, group) };
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -74,7 +75,7 @@ export class EditorReplacementContribution implements IWorkbenchContribution {
|
||||
if (inputCreator) {
|
||||
const newInput = inputCreator.convertInput(editor);
|
||||
if (newInput) {
|
||||
return { override: isThenable(newInput) ? newInput.then(input => this.editorService.openEditor(input, options, group)) : this.editorService.openEditor(newInput, options, group) };
|
||||
return { override: isThenable(newInput) ? newInput.then(input => this.editorService.openEditor(input ?? editor, options, group)) : this.editorService.openEditor(newInput, options, group) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
|
||||
export interface IEditorDescriptorService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
getEditor(input: EditorInput): IEditorDescriptor;
|
||||
getEditor(input: EditorInput): IEditorDescriptor | undefined;
|
||||
}
|
||||
|
||||
export class EditorDescriptorService implements IEditorDescriptorService {
|
||||
@@ -21,7 +21,7 @@ export class EditorDescriptorService implements IEditorDescriptorService {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public getEditor(input: EditorInput): IEditorDescriptor {
|
||||
public getEditor(input: EditorInput): IEditorDescriptor | undefined {
|
||||
return Registry.as<IEditorRegistry>(Extensions.Editors).getEditor(input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,11 +53,11 @@ export class QueryEditorService implements IQueryEditorService {
|
||||
|
||||
// Create a sql document pane with accoutrements
|
||||
const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: this._connectionManagementService.getProviderLanguageMode(connectionProviderName) }) as UntitledTextEditorInput;
|
||||
let untitledEditorModel = await fileInput.resolve() as UntitledTextEditorModel;
|
||||
let untitledEditorModel = await fileInput.resolve();
|
||||
if (options.initalContent) {
|
||||
untitledEditorModel.textEditorModel.setValue(options.initalContent);
|
||||
if (options.dirty === false || (options.dirty === undefined && !this._configurationService.getValue<IQueryEditorConfiguration>('queryEditor').promptToSaveGeneratedFiles)) {
|
||||
untitledEditorModel.setDirty(false);
|
||||
(untitledEditorModel as UntitledTextEditorModel).setDirty(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,9 +82,9 @@ export class QueryEditorService implements IQueryEditorService {
|
||||
|
||||
// Create a sql document pane with accoutrements
|
||||
const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: 'sql' }) as UntitledTextEditorInput;
|
||||
const m = await fileInput.resolve() as UntitledTextEditorModel;
|
||||
const m = await fileInput.resolve();
|
||||
//when associatedResource editor is created it is dirty, this must be set to false to be able to detect changes to the editor.
|
||||
m.setDirty(false);
|
||||
(m as UntitledTextEditorModel).setDirty(false);
|
||||
// Create an EditDataInput for editing
|
||||
const resultsInput: EditDataResultsInput = this._instantiationService.createInstance(EditDataResultsInput, docUri.toString());
|
||||
let editDataInput: EditDataInput = this._instantiationService.createInstance(EditDataInput, docUri, schemaName, tableName, fileInput, sqlContent, resultsInput);
|
||||
@@ -94,7 +94,7 @@ export class QueryEditorService implements IQueryEditorService {
|
||||
//Setting the value of the textEditorModel to sqlContent marks editor as dirty, editDataInput handles it.
|
||||
m.textEditorModel.setValue(sqlContent);
|
||||
}
|
||||
const editor = await this._editorService.openEditor(editDataInput, { pinned: true });
|
||||
const editor = (await this._editorService.openEditor(editDataInput, { pinned: true }))!;
|
||||
let params = editor.input as EditDataInput;
|
||||
return params;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user