提交 42c716dc 编写于 作者: R Rob Lourens

Strict null check more search files

上级 1d44116f
......@@ -654,10 +654,14 @@
"./vs/workbench/services/part/common/partService.ts",
"./vs/workbench/services/scm/common/scm.ts",
"./vs/workbench/services/scm/common/scmService.ts",
"./vs/workbench/services/search/common/searchHelpers.ts",
"./vs/workbench/services/search/node/fileSearchManager.ts",
"./vs/workbench/services/search/node/legacy/search.ts",
"./vs/workbench/services/search/node/ripgrepSearchUtils.ts",
"./vs/workbench/services/search/node/search.ts",
"./vs/workbench/services/search/node/searchHistoryService.ts",
"./vs/workbench/services/search/node/searchIpc.ts",
"./vs/workbench/services/search/node/textSearchManager.ts",
"./vs/workbench/services/textMate/electron-browser/TMGrammars.ts",
"./vs/workbench/services/textMate/electron-browser/TMHelper.ts",
"./vs/workbench/services/textMate/electron-browser/textMateService.ts",
......@@ -669,8 +673,6 @@
"./vs/workbench/services/title/common/titleService.ts",
"./vs/workbench/services/workspace/common/workspaceEditing.ts",
"./vs/workbench/test/electron-browser/api/mock.ts",
"./vs/workbench/services/search/node/ripgrepSearchUtils.ts",
"./vs/workbench/services/search/node/textSearchManager.ts"
],
"exclude": [
"./typings/require-monaco.d.ts",
......
......@@ -233,7 +233,7 @@ declare module 'vscode' {
/**
* The maximum number of results to be returned.
*/
maxResults: number;
maxResults?: number;
}
/**
......
......@@ -51,7 +51,7 @@ export function addContextToEditorMatches(matches: ITextSearchMatch[], model: IT
let prevLine = -1;
for (let i = 0; i < matches.length; i++) {
const { start: matchStartLine, end: matchEndLine } = getMatchStartEnd(matches[i]);
if (query.beforeContext > 0) {
if (typeof query.beforeContext === 'number' && query.beforeContext > 0) {
const beforeContextStartLine = Math.max(prevLine + 1, matchStartLine - query.beforeContext);
for (let b = beforeContextStartLine; b < matchStartLine; b++) {
results.push(<ITextSearchContext>{
......@@ -65,7 +65,7 @@ export function addContextToEditorMatches(matches: ITextSearchMatch[], model: IT
const nextMatch = matches[i + 1];
let nextMatchStartLine = nextMatch ? getMatchStartEnd(nextMatch).start : Number.MAX_VALUE;
if (query.afterContext > 0) {
if (typeof query.afterContext === 'number' && query.afterContext > 0) {
const afterContextToLine = Math.min(nextMatchStartLine - 1, matchEndLine + query.afterContext, model.getLineCount() - 1);
for (let a = matchEndLine + 1; a <= afterContextToLine; a++) {
results.push(<ITextSearchContext>{
......
......@@ -36,25 +36,23 @@ export interface IDirectoryTree {
class FileSearchEngine {
private filePattern: string;
private includePattern: glob.ParsedExpression;
private maxResults: number;
private exists: boolean;
private isLimitHit: boolean;
private resultCount: number;
private isCanceled: boolean;
private filePattern?: string;
private includePattern?: glob.ParsedExpression;
private maxResults?: number;
private exists?: boolean;
private isLimitHit = false;
private resultCount = 0;
private isCanceled = false;
private activeCancellationTokens: Set<CancellationTokenSource>;
private globalExcludePattern: glob.ParsedExpression;
private globalExcludePattern?: glob.ParsedExpression;
constructor(private config: IFileQuery, private provider: vscode.FileSearchProvider) {
this.filePattern = config.filePattern;
this.includePattern = config.includePattern && glob.parse(config.includePattern);
this.maxResults = config.maxResults || null;
this.maxResults = config.maxResults || undefined;
this.exists = config.exists;
this.resultCount = 0;
this.isLimitHit = false;
this.activeCancellationTokens = new Set<CancellationTokenSource>();
this.globalExcludePattern = config.excludePattern && glob.parse(config.excludePattern);
......@@ -67,7 +65,7 @@ class FileSearchEngine {
}
public search(_onResult: (match: IInternalFileMatch) => void): TPromise<IInternalSearchComplete> {
const folderQueries = this.config.folderQueries;
const folderQueries = this.config.folderQueries || [];
return new TPromise((resolve, reject) => {
const onResult = (match: IInternalFileMatch) => {
......@@ -101,7 +99,7 @@ class FileSearchEngine {
})).then(stats => {
resolve({
limitHit: this.isLimitHit,
stats: stats[0] // Only looking at single-folder workspace stats...
stats: stats[0] || undefined // Only looking at single-folder workspace stats...
});
}, (errs: Error[]) => {
const errMsg = errs
......@@ -113,7 +111,7 @@ class FileSearchEngine {
});
}
private searchInFolder(fq: IFolderQuery<URI>, onResult: (match: IInternalFileMatch) => void): TPromise<IFileSearchProviderStats> {
private searchInFolder(fq: IFolderQuery<URI>, onResult: (match: IInternalFileMatch) => void): TPromise<IFileSearchProviderStats | null> {
let cancellation = new CancellationTokenSource();
return new TPromise((resolve, reject) => {
const options = this.getSearchOptionsForFolder(fq);
......@@ -267,7 +265,7 @@ class FileSearchEngine {
}
private matchFile(onResult: (result: IInternalFileMatch) => void, candidate: IInternalFileMatch): void {
if (!this.includePattern || this.includePattern(candidate.relativePath, candidate.basename)) {
if (!this.includePattern || (candidate.relativePath && this.includePattern(candidate.relativePath, candidate.basename))) {
if (this.exists || (this.maxResults && this.resultCount >= this.maxResults)) {
this.isLimitHit = true;
this.cancel();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册