mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-26 10:16:01 +01:00
Fix typings issues with TestInstantiationService in search
Addresses #164297
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Keybinding } from 'vs/base/common/keybindings';
|
||||
import { OS } from 'vs/base/common/platform';
|
||||
import { isWindows, OS } from 'vs/base/common/platform';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IModelService } from 'vs/editor/common/services/model';
|
||||
import { ModelService } from 'vs/editor/common/services/modelService';
|
||||
@@ -16,7 +16,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
|
||||
import { IFileMatch } from 'vs/workbench/services/search/common/search';
|
||||
import { getElementToFocusAfterRemoved, getLastNodeFromSameType } from 'vs/workbench/contrib/search/browser/searchActionsRemoveReplace';
|
||||
import { FileMatch, FileMatchOrMatch, Match } from 'vs/workbench/contrib/search/common/searchModel';
|
||||
import { FileMatch, FileMatchOrMatch, FolderMatch, Match, SearchModel } from 'vs/workbench/contrib/search/common/searchModel';
|
||||
import { MockObjectTree } from 'vs/workbench/contrib/search/test/browser/mockSearchTree';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
@@ -109,7 +109,37 @@ suite('Search Actions', () => {
|
||||
resource: URI.file('somepath' + ++counter),
|
||||
results: []
|
||||
};
|
||||
return instantiationService.createInstance(FileMatch, null, null, null, null, rawMatch, null);
|
||||
|
||||
const searchModel = instantiationService.createInstance(SearchModel);
|
||||
const folderMatch = instantiationService.createInstance(FolderMatch, URI.file('somepath'), '', 0, {
|
||||
type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }], contentPattern: {
|
||||
pattern: ''
|
||||
}
|
||||
}, searchModel.searchResult, searchModel, null);
|
||||
return instantiationService.createInstance(FileMatch, {
|
||||
pattern: ''
|
||||
}, undefined, undefined, folderMatch, rawMatch, null);
|
||||
}
|
||||
|
||||
function createFileUriFromPathFromRoot(path?: string): URI {
|
||||
const rootName = getRootName();
|
||||
if (path) {
|
||||
return URI.file(`${rootName}${path}`);
|
||||
} else {
|
||||
if (isWindows) {
|
||||
return URI.file(`${rootName}/`);
|
||||
} else {
|
||||
return URI.file(rootName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRootName(): string {
|
||||
if (isWindows) {
|
||||
return 'c:';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function aMatch(fileMatch: FileMatch): Match {
|
||||
|
||||
@@ -40,7 +40,7 @@ suite('Search - Viewlet', () => {
|
||||
});
|
||||
|
||||
test('Data Source', function () {
|
||||
const result: SearchResult = instantiation.createInstance(SearchResult, null);
|
||||
const result: SearchResult = aSearchResult();
|
||||
result.query = {
|
||||
type: QueryType.Text,
|
||||
contentPattern: { pattern: 'foo' },
|
||||
@@ -166,20 +166,30 @@ suite('Search - Viewlet', () => {
|
||||
|
||||
function aFileMatch(path: string, parentFolder?: FolderMatch, ...lineMatches: ITextSearchMatch[]): FileMatch {
|
||||
const rawMatch: IFileMatch = {
|
||||
resource: createFileUriFromPathFromRoot(path),
|
||||
resource: URI.file('/' + path),
|
||||
results: lineMatches
|
||||
};
|
||||
return instantiation.createInstance(FileMatch, null, null, null, parentFolder, rawMatch, parentFolder);
|
||||
return instantiation.createInstance(FileMatch, {
|
||||
pattern: ''
|
||||
}, undefined, undefined, parentFolder ?? aFolderMatch('', 0), rawMatch, null);
|
||||
}
|
||||
|
||||
function aFolderMatch(path: string, index: number, parent?: SearchResult): FolderMatch {
|
||||
const searchModel = instantiation.createInstance(SearchModel);
|
||||
return instantiation.createInstance(FolderMatch, createFileUriFromPathFromRoot(path), path, index, null, parent, searchModel, parent);
|
||||
return instantiation.createInstance(FolderMatch, createFileUriFromPathFromRoot(path), path, index, {
|
||||
type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }], contentPattern: {
|
||||
pattern: ''
|
||||
}
|
||||
}, parent ?? aSearchResult().folderMatches()[0], searchModel, null);
|
||||
}
|
||||
|
||||
function aSearchResult(): SearchResult {
|
||||
const searchModel = instantiation.createInstance(SearchModel);
|
||||
searchModel.searchResult.query = { type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }] };
|
||||
searchModel.searchResult.query = {
|
||||
type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }], contentPattern: {
|
||||
pattern: ''
|
||||
}
|
||||
};
|
||||
return searchModel.searchResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,12 +65,12 @@ suite('SearchResult', () => {
|
||||
});
|
||||
|
||||
test('File Match', function () {
|
||||
let fileMatch = aFileMatch('folder/file.txt');
|
||||
let fileMatch = aFileMatch('folder/file.txt', aSearchResult());
|
||||
assert.strictEqual(fileMatch.matches().length, 0);
|
||||
assert.strictEqual(fileMatch.resource.toString(), 'file:///folder/file.txt');
|
||||
assert.strictEqual(fileMatch.name(), 'file.txt');
|
||||
|
||||
fileMatch = aFileMatch('file.txt');
|
||||
fileMatch = aFileMatch('file.txt', aSearchResult());
|
||||
assert.strictEqual(fileMatch.matches().length, 0);
|
||||
assert.strictEqual(fileMatch.resource.toString(), 'file:///file.txt');
|
||||
assert.strictEqual(fileMatch.name(), 'file.txt');
|
||||
@@ -147,12 +147,14 @@ suite('SearchResult', () => {
|
||||
});
|
||||
|
||||
test('Match -> FileMatch -> SearchResult hierarchy exists', function () {
|
||||
const searchResult = instantiationService.createInstance(SearchResult, null);
|
||||
|
||||
const searchModel = instantiationService.createInstance(SearchModel);
|
||||
const searchResult = instantiationService.createInstance(SearchResult, searchModel);
|
||||
const fileMatch = aFileMatch('far/boo', searchResult);
|
||||
const lineMatch = new Match(fileMatch, ['foo bar'], new OneLineRange(0, 0, 3), new OneLineRange(1, 0, 3));
|
||||
|
||||
assert(lineMatch.parent() === fileMatch);
|
||||
assert(fileMatch.parent() === searchResult);
|
||||
assert(fileMatch.parent() === searchResult.folderMatches()[0]);
|
||||
});
|
||||
|
||||
test('Adding a raw match will add a file match with line matches', function () {
|
||||
@@ -467,17 +469,24 @@ suite('SearchResult', () => {
|
||||
|
||||
});
|
||||
|
||||
function aFileMatch(path: string, searchResult?: SearchResult, ...lineMatches: ITextSearchMatch[]): FileMatch {
|
||||
function aFileMatch(path: string, searchResult: SearchResult, ...lineMatches: ITextSearchMatch[]): FileMatch {
|
||||
const rawMatch: IFileMatch = {
|
||||
resource: URI.file('/' + path),
|
||||
results: lineMatches
|
||||
};
|
||||
return instantiationService.createInstance(FileMatch, null, null, null, searchResult, rawMatch, searchResult);
|
||||
const root = searchResult?.folderMatches()[0];
|
||||
return instantiationService.createInstance(FileMatch, {
|
||||
pattern: ''
|
||||
}, undefined, undefined, root, rawMatch, null);
|
||||
}
|
||||
|
||||
function aSearchResult(): SearchResult {
|
||||
const searchModel = instantiationService.createInstance(SearchModel);
|
||||
searchModel.searchResult.query = { type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }] };
|
||||
searchModel.searchResult.query = {
|
||||
type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }], contentPattern: {
|
||||
pattern: ''
|
||||
}
|
||||
};
|
||||
return searchModel.searchResult;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user