Skip to content

Commit

Permalink
Fix some strictPropertyInitialization in search, #78168
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Sep 3, 2019
1 parent 779e29a commit e8fc7db
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 52 deletions.
1 change: 0 additions & 1 deletion src/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"strictBindCallApply": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"strictPropertyInitialization": true,
"baseUrl": ".",
"paths": {
"vs/*": [
Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/contrib/search/browser/patternInputWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export class PatternInputWidget extends Widget {

static OPTION_CHANGE: string = 'optionChange';

inputFocusTracker: dom.IFocusTracker;
inputFocusTracker!: dom.IFocusTracker;

private width: number;
private placeholder: string;
private ariaLabel: string;

private domNode: HTMLElement;
protected inputBox: HistoryInputBox;
private domNode!: HTMLElement;
protected inputBox!: HistoryInputBox;

private _onSubmit = this._register(new Emitter<boolean>());
onSubmit: CommonEvent<boolean> = this._onSubmit.event;
Expand Down Expand Up @@ -148,7 +148,7 @@ export class PatternInputWidget extends Widget {
this.setInputWidth();
}

protected renderSubcontrols(controlsDiv: HTMLDivElement): void {
protected renderSubcontrols(_controlsDiv: HTMLDivElement): void {
}

private onInputKeyUp(keyboardEvent: IKeyboardEvent) {
Expand All @@ -174,7 +174,7 @@ export class ExcludePatternInputWidget extends PatternInputWidget {
super(parent, contextViewProvider, options, themeService, contextKeyService);
}

private useExcludesAndIgnoreFilesBox: Checkbox;
private useExcludesAndIgnoreFilesBox!: Checkbox;

dispose(): void {
super.dispose();
Expand Down Expand Up @@ -209,4 +209,4 @@ export class ExcludePatternInputWidget extends PatternInputWidget {
controlsDiv.appendChild(this.useExcludesAndIgnoreFilesBox.domNode);
super.renderSubcontrols(controlsDiv);
}
}
}
24 changes: 12 additions & 12 deletions src/vs/workbench/contrib/search/browser/searchWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ReplaceAllAction extends Action {
return ReplaceAllAction.fgInstance;
}

private _searchWidget: SearchWidget;
private _searchWidget: SearchWidget | null = null;

constructor() {
super(ReplaceAllAction.ID, '', 'action-replace-all', false);
Expand All @@ -84,25 +84,25 @@ export class SearchWidget extends Widget {
return appendKeyBindingLabel(nls.localize('search.action.replaceAll.enabled.label', "Replace All"), kb, keyBindingService2);
}

domNode: HTMLElement;
domNode!: HTMLElement;

searchInput: FindInput;
searchInputFocusTracker: dom.IFocusTracker;
searchInput!: FindInput;
searchInputFocusTracker!: dom.IFocusTracker;
private searchInputBoxFocused: IContextKey<boolean>;

private replaceContainer: HTMLElement;
replaceInput: HistoryInputBox;
private toggleReplaceButton: Button;
private replaceAllAction: ReplaceAllAction;
private replaceContainer!: HTMLElement;
replaceInput!: HistoryInputBox;
private toggleReplaceButton!: Button;
private replaceAllAction!: ReplaceAllAction;
private replaceActive: IContextKey<boolean>;
private replaceActionBar: ActionBar;
replaceInputFocusTracker: dom.IFocusTracker;
private replaceActionBar!: ActionBar;
replaceInputFocusTracker!: dom.IFocusTracker;
private replaceInputBoxFocused: IContextKey<boolean>;
private _replaceHistoryDelayer: Delayer<void>;
private _preserveCase: Checkbox;
private _preserveCase!: Checkbox;

private ignoreGlobalFindBufferOnNextFocus = false;
private previousGlobalFindBufferValue: string;
private previousGlobalFindBufferValue: string | null = null;

private _onSearchSubmit = this._register(new Emitter<void>());
readonly onSearchSubmit: Event<void> = this._onSearchSubmit.event;
Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/contrib/search/test/common/searchModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { SearchModel } from 'vs/workbench/contrib/search/common/searchModel';
import * as process from 'vs/base/common/process';

const nullEvent = new class {
id: number;
topic: string;
name: string;
description: string;
id: number = -1;
topic!: string;
name!: string;
description!: string;
data: any;

startTime: Date;
stopTime: Date;
startTime!: Date;
stopTime!: Date;

stop(): void {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/services/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export class QueryGlobTester {
private _excludeExpression: glob.IExpression;
private _parsedExcludeExpression: glob.ParsedExpression;

private _parsedIncludeExpression: glob.ParsedExpression;
private _parsedIncludeExpression: glob.ParsedExpression | null = null;

constructor(config: ISearchQuery, folderQuery: IFolderQuery) {
this._excludeExpression = {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/services/search/common/searchExtTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class Range {
this.end = new Position(endLine, endCol);
}

isEmpty: boolean;
isSingleLine: boolean;
isEmpty = false;
isSingleLine = false;
contains(positionOrRange: Position | Range): boolean { return false; }
isEqual(other: Range): boolean { return false; }
intersection(range: Range): Range | undefined { return undefined; }
Expand Down Expand Up @@ -410,4 +410,4 @@ export interface FindTextInFilesOptions {
* Number of lines of context to include after each match.
*/
afterContext?: number;
}
}
2 changes: 1 addition & 1 deletion src/vs/workbench/services/search/common/searchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SearchService extends Disposable implements ISearchService {

_serviceBrand: undefined;

protected diskSearch: ISearchResultProvider;
protected diskSearch: ISearchResultProvider | null = null;
private readonly fileSearchProviders = new Map<string, ISearchResultProvider>();
private readonly textSearchProviders = new Map<string, ISearchResultProvider>();

Expand Down
28 changes: 14 additions & 14 deletions src/vs/workbench/services/search/node/fileSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ process.on('exit', () => {
export class FileWalker {
private config: IFileQuery;
private filePattern: string;
private normalizedFilePatternLowercase: string;
private normalizedFilePatternLowercase: string | null = null;
private includePattern: glob.ParsedExpression | undefined;
private maxResults: number | null;
private exists: boolean;
private maxFilesize: number | null;
private maxFilesize: number | null = null;
private isLimitHit: boolean;
private resultCount: number;
private isCanceled: boolean;
private fileWalkSW: StopWatch;
private isCanceled = false;
private fileWalkSW: StopWatch | null = null;
private directoriesWalked: number;
private filesWalked: number;
private errors: string[];
private cmdSW: StopWatch;
private cmdResultCount: number;
private cmdSW: StopWatch | null = null;
private cmdResultCount: number = 0;

private folderExcludePatterns: Map<string, AbsoluteAndRelativeParsedExpression>;
private globalExcludePattern: glob.ParsedExpression | undefined;
Expand Down Expand Up @@ -139,8 +139,8 @@ export class FileWalker {
rootFolderDone(null, undefined);
}
});
}, (errors, result) => {
this.fileWalkSW.stop();
}, (errors, _result) => {
this.fileWalkSW!.stop();
const err = errors ? arrays.coalesce(errors)[0] : null;
done(err, this.isLimitHit);
});
Expand Down Expand Up @@ -318,9 +318,7 @@ export class FileWalker {
if (err || last) {
onData = () => { };

if (this.cmdSW) {
this.cmdSW.stop();
}
this.cmdSW!.stop();
}
cb(err, stdout, last);
};
Expand Down Expand Up @@ -455,8 +453,8 @@ export class FileWalker {

getStats(): ISearchEngineStats {
return {
cmdTime: this.cmdSW && this.cmdSW.elapsed(),
fileWalkTime: this.fileWalkSW.elapsed(),
cmdTime: this.cmdSW!.elapsed(),
fileWalkTime: this.fileWalkSW!.elapsed(),
directoriesWalked: this.directoriesWalked,
filesWalked: this.filesWalked,
cmdResultCount: this.cmdResultCount
Expand Down Expand Up @@ -578,7 +576,9 @@ export class FileWalker {
return true; // support the all-matching wildcard
}

return strings.fuzzyContains(path, this.normalizedFilePatternLowercase);
if (this.normalizedFilePatternLowercase) {
return strings.fuzzyContains(path, this.normalizedFilePatternLowercase);
}
}

// No patterns means we match all
Expand Down
14 changes: 6 additions & 8 deletions src/vs/workbench/services/search/node/textSearchManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { mapArrayOrNot } from 'vs/base/common/arrays';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import * as glob from 'vs/base/common/glob';
import * as resources from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { toCanonicalName } from 'vs/base/node/encoding';
import * as pfs from 'vs/base/node/pfs';
Expand All @@ -17,9 +16,9 @@ import { TextSearchProvider, TextSearchResult, TextSearchMatch, TextSearchComple

export class TextSearchManager {

private collector: TextSearchResultsCollector;
private collector: TextSearchResultsCollector | null = null;

private isLimitHit: boolean;
private isLimitHit = false;
private resultCount = 0;

constructor(private query: ITextQuery, private provider: TextSearchProvider, private _pfs: typeof pfs = pfs) {
Expand Down Expand Up @@ -52,7 +51,7 @@ export class TextSearchManager {
const newResultSize = this.resultSize(result);
this.resultCount += newResultSize;
if (newResultSize > 0) {
this.collector.add(result, folderIdx);
this.collector!.add(result, folderIdx);
}
}
};
Expand All @@ -62,7 +61,7 @@ export class TextSearchManager {
return this.searchInFolder(fq, r => onResult(r, i), tokenSource.token);
})).then(results => {
tokenSource.dispose();
this.collector.flush();
this.collector!.flush();

const someFolderHitLImit = results.some(result => !!result && !!result.limitHit);
resolve({
Expand Down Expand Up @@ -198,8 +197,7 @@ function patternInfoToQuery(patternInfo: IPatternInfo): TextSearchQuery {
export class TextSearchResultsCollector {
private _batchedCollector: BatchedCollector<IFileMatch>;

private _currentFolderIdx: number;
private _currentUri: URI;
private _currentFolderIdx: number = -1;
private _currentFileMatch: IFileMatch | null = null;

constructor(private _onResult: (result: IFileMatch[]) => void) {
Expand All @@ -210,7 +208,7 @@ export class TextSearchResultsCollector {
// Collects TextSearchResults into IInternalFileMatches and collates using BatchedCollector.
// This is efficient for ripgrep which sends results back one file at a time. It wouldn't be efficient for other search
// providers that send results in random order. We could do this step afterwards instead.
if (this._currentFileMatch && (this._currentFolderIdx !== folderIdx || !resources.isEqual(this._currentUri, data.uri))) {
if (this._currentFileMatch && this._currentFolderIdx !== folderIdx) {
this.pushToCollector();
this._currentFileMatch = null;
}
Expand Down

0 comments on commit e8fc7db

Please sign in to comment.