Strict null on some query and connection (#7300)

* wip

* make connection work with strict-nulls

* change comments

* fix tests; remove unneeded type forcing

* address feedback

* adjust the logic of query editor

* clean up typing
This commit is contained in:
Anthony Dresser
2019-10-21 15:50:12 -07:00
committed by GitHub
parent 6a375fdd8c
commit 06e86e57e7
22 changed files with 367 additions and 369 deletions

View File

@@ -30,7 +30,7 @@ export class GridTableState extends Disposable {
/* The top row of the current scroll */
public scrollPositionY = 0;
public scrollPositionX = 0;
public columnSizes: number[] = undefined;
public columnSizes?: number[] = undefined;
public selection: Slick.Range[];
public activeCell: Slick.Cell;

View File

@@ -276,12 +276,12 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
}
// State update funtions
public runQuery(selection: ISelectionData, executePlanOptions?: ExecutionPlanOptions): void {
public runQuery(selection?: ISelectionData, executePlanOptions?: ExecutionPlanOptions): void {
this._queryModelService.runQuery(this.uri, selection, this, executePlanOptions);
this.state.executing = true;
}
public runQueryStatement(selection: ISelectionData): void {
public runQueryStatement(selection?: ISelectionData): void {
this._queryModelService.runQueryStatement(this.uri, selection, this);
this.state.executing = true;
}
@@ -316,7 +316,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
let isRunningQuery = this._queryModelService.isRunningQuery(this.uri);
if (!isRunningQuery && params && params.runQueryOnCompletion) {
let selection: ISelectionData = params ? params.querySelection : undefined;
let selection: ISelectionData | undefined = params ? params.querySelection : undefined;
if (params.runQueryOnCompletion === RunQueryOnConnectionMode.executeCurrentQuery) {
this.runQueryStatement(selection);
} else if (params.runQueryOnCompletion === RunQueryOnConnectionMode.executeQuery) {
@@ -361,6 +361,6 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
}
public get isSharedSession(): boolean {
return this.uri && this.uri.startsWith('vsls:');
return !!(this.uri && this.uri.startsWith('vsls:'));
}
}

View File

@@ -42,9 +42,9 @@ export class ResultsViewState {
*/
export class QueryResultsInput extends EditorInput {
private _state = new ResultsViewState();
private _state?= new ResultsViewState();
public get state(): ResultsViewState {
public get state(): ResultsViewState | undefined {
return this._state;
}
@@ -53,7 +53,7 @@ export class QueryResultsInput extends EditorInput {
}
close() {
this.state.dispose();
this.state!.dispose();
this._state = undefined;
super.close();
}

View File

@@ -67,12 +67,12 @@ export class ResultSerializer {
/**
* Handle save request by getting filename from user and sending request to service
*/
public saveResults(uri: string, saveRequest: ISaveRequest): Thenable<void> {
public saveResults(uri: string, saveRequest: ISaveRequest): Promise<void> {
const self = this;
return this.promptForFilepath(saveRequest.format, uri).then(filePath => {
if (filePath) {
if (!path.isAbsolute(filePath)) {
filePath = resolveFilePath(uri, filePath, this.rootPath);
filePath = resolveFilePath(uri, filePath, this.rootPath)!;
}
let saveResultsParams = this.getParameters(uri, filePath, saveRequest.batchIndex, saveRequest.resultSetNumber, saveRequest.format, saveRequest.selection ? saveRequest.selection[0] : undefined);
let sendRequest = () => this.sendSaveRequestToService(saveResultsParams);
@@ -98,9 +98,9 @@ export class ResultSerializer {
return this.promptForFilepath(format, uri).then(filePath => {
if (filePath) {
if (!path.isAbsolute(filePath)) {
filePath = resolveFilePath(uri, filePath, this.rootPath);
filePath = resolveFilePath(uri, filePath, this.rootPath)!;
}
return self.doSave(filePath, format, () => sendRequest(filePath));
return self.doSave(filePath, format, () => sendRequest(filePath!));
}
return Promise.resolve();
});
@@ -117,10 +117,10 @@ export class ResultSerializer {
private get outputChannel(): IOutputChannel {
this.ensureOutputChannelExists();
return this._outputService.getChannel(ConnectionConstants.outputChannelName);
return this._outputService.getChannel(ConnectionConstants.outputChannelName)!;
}
private get rootPath(): string {
private get rootPath(): string | undefined {
return getRootPath(this._contextService);
}
@@ -129,7 +129,7 @@ export class ResultSerializer {
}
private promptForFilepath(format: SaveFormat, resourceUri: string): Thenable<string | undefined> {
private promptForFilepath(format: SaveFormat, resourceUri: string): Promise<string | undefined> {
let filepathPlaceHolder = prevSavePath ? path.dirname(prevSavePath) : resolveCurrentDirectory(resourceUri, this.rootPath);
if (filepathPlaceHolder) {
filepathPlaceHolder = path.join(filepathPlaceHolder, this.getResultsDefaultFilename(format));
@@ -171,7 +171,7 @@ export class ResultSerializer {
private getResultsFileExtension(format: SaveFormat): FileFilter[] {
let fileFilters = new Array<FileFilter>();
let fileFilter: { extensions: string[]; name: string } = { extensions: undefined, name: undefined };
let fileFilter: { extensions: string[]; name: string } = Object.create(null);
switch (format) {
case SaveFormat.CSV:
@@ -211,7 +211,7 @@ export class ResultSerializer {
} else if (format === SaveFormat.XML) {
saveResultsParams = this.getConfigForXml();
}
return saveResultsParams;
return saveResultsParams!; // this could be unsafe
}
@@ -280,7 +280,7 @@ export class ResultSerializer {
}
private getParameters(uri: string, filePath: string, batchIndex: number, resultSetNo: number, format: string, selection: Slick.Range): SaveResultsRequestParams {
private getParameters(uri: string, filePath: string, batchIndex: number, resultSetNo: number, format: string, selection?: Slick.Range): SaveResultsRequestParams {
let saveResultsParams = this.getBasicSaveParameters(format);
saveResultsParams.filePath = filePath;
saveResultsParams.ownerUri = uri;
@@ -298,8 +298,8 @@ export class ResultSerializer {
/**
* Check if a range of cells were selected.
*/
private isSelected(selection: Slick.Range): boolean {
return (selection && !((selection.fromCell === selection.toCell) && (selection.fromRow === selection.toRow)));
private isSelected(selection?: Slick.Range): selection is Slick.Range {
return !!(selection && !((selection.fromCell === selection.toCell) && (selection.fromRow === selection.toRow)));
}