Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use label service #149001

Merged
merged 3 commits into from Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 36 additions & 22 deletions src/vs/workbench/contrib/search/common/searchModel.ts
Expand Up @@ -5,33 +5,32 @@

import { RunOnceScheduler } from 'vs/base/common/async';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { compareFileExtensions, compareFileNames, comparePaths } from 'vs/base/common/comparers';
import { memoize } from 'vs/base/common/decorators';
import * as errors from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { getBaseLabel } from 'vs/base/common/labels';
import { Disposable, IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { ResourceMap, TernarySearchTree } from 'vs/base/common/map';
import { Schemas } from 'vs/base/common/network';
import { lcut } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { Range } from 'vs/editor/common/core/range';
import { FindMatch, IModelDeltaDecoration, ITextModel, OverviewRulerLane, TrackedRangeStickiness, MinimapPosition } from 'vs/editor/common/model';
import { FindMatch, IModelDeltaDecoration, ITextModel, MinimapPosition, OverviewRulerLane, TrackedRangeStickiness } from 'vs/editor/common/model';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { IModelService } from 'vs/editor/common/services/model';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IFileService, IFileStatWithPartialMetadata } from 'vs/platform/files/common/files';
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILabelService } from 'vs/platform/label/common/label';
import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress';
import { ReplacePattern } from 'vs/workbench/services/search/common/replace';
import { IFileMatch, IPatternInfo, ISearchComplete, ISearchProgressItem, ISearchConfigurationProperties, ISearchService, ITextQuery, ITextSearchPreviewOptions, ITextSearchMatch, ITextSearchStats, resultIsMatch, ISearchRange, OneLineRange, ITextSearchContext, ITextSearchResult, SearchSortOrder, SearchCompletionExitCode } from 'vs/workbench/services/search/common/search';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { overviewRulerFindMatchForeground, minimapFindMatch } from 'vs/platform/theme/common/colorRegistry';
import { minimapFindMatch, overviewRulerFindMatchForeground } from 'vs/platform/theme/common/colorRegistry';
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { editorMatchesToTextSearchResults, addContextToEditorMatches } from 'vs/workbench/services/search/common/searchHelpers';
import { withNullAsUndefined } from 'vs/base/common/types';
import { memoize } from 'vs/base/common/decorators';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { compareFileNames, compareFileExtensions, comparePaths } from 'vs/base/common/comparers';
import { IFileService, IFileStatWithPartialMetadata } from 'vs/platform/files/common/files';
import { Schemas } from 'vs/base/common/network';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { ReplacePattern } from 'vs/workbench/services/search/common/replace';
import { IFileMatch, IPatternInfo, ISearchComplete, ISearchConfigurationProperties, ISearchProgressItem, ISearchRange, ISearchService, ITextQuery, ITextSearchContext, ITextSearchMatch, ITextSearchPreviewOptions, ITextSearchResult, ITextSearchStats, OneLineRange, resultIsMatch, SearchCompletionExitCode, SearchSortOrder } from 'vs/workbench/services/search/common/search';
import { addContextToEditorMatches, editorMatchesToTextSearchResults } from 'vs/workbench/services/search/common/searchHelpers';

export class Match {

Expand Down Expand Up @@ -217,8 +216,15 @@ export class FileMatch extends Disposable implements IFileMatch {
return new Map(this._context);
}

constructor(private _query: IPatternInfo, private _previewOptions: ITextSearchPreviewOptions | undefined, private _maxResults: number | undefined, private _parent: FolderMatch, private rawMatch: IFileMatch,
@IModelService private readonly modelService: IModelService, @IReplaceService private readonly replaceService: IReplaceService
constructor(
private _query: IPatternInfo,
private _previewOptions: ITextSearchPreviewOptions | undefined,
private _maxResults: number | undefined,
private _parent: FolderMatch,
private rawMatch: IFileMatch,
@IModelService private readonly modelService: IModelService,
@IReplaceService private readonly replaceService: IReplaceService,
@ILabelService private readonly labelService: ILabelService,
) {
super();
this._resource = this.rawMatch.resource;
Expand Down Expand Up @@ -407,7 +413,7 @@ export class FileMatch extends Disposable implements IFileMatch {
}

name(): string {
return getBaseLabel(this.resource);
return this.labelService.getUriBasenameLabel(this.resource);
}

addContext(results: ITextSearchResult[] | undefined) {
Expand Down Expand Up @@ -472,9 +478,16 @@ export class FolderMatch extends Disposable {
private _unDisposedFileMatches: ResourceMap<FileMatch>;
private _replacingAll: boolean = false;

constructor(protected _resource: URI | null, private _id: string, private _index: number, private _query: ITextQuery, private _parent: SearchResult, private _searchModel: SearchModel,
constructor(
protected _resource: URI | null,
private _id: string,
private _index: number,
private _query: ITextQuery,
private _parent: SearchResult,
private _searchModel: SearchModel,
@IReplaceService private readonly replaceService: IReplaceService,
@IInstantiationService private readonly instantiationService: IInstantiationService
@IInstantiationService private readonly instantiationService: IInstantiationService,
@ILabelService private readonly labelService: ILabelService,
) {
super();
this._fileMatches = new ResourceMap<FileMatch>();
Expand Down Expand Up @@ -506,7 +519,7 @@ export class FolderMatch extends Disposable {
}

name(): string {
return getBaseLabel(withNullAsUndefined(this.resource)) || '';
return this.resource ? this.labelService.getUriBasenameLabel(this.resource) : '';
}

parent(): SearchResult {
Expand Down Expand Up @@ -651,9 +664,10 @@ export class FolderMatch extends Disposable {
export class FolderMatchWithResource extends FolderMatch {
constructor(_resource: URI, _id: string, _index: number, _query: ITextQuery, _parent: SearchResult, _searchModel: SearchModel,
@IReplaceService replaceService: IReplaceService,
@IInstantiationService instantiationService: IInstantiationService
@IInstantiationService instantiationService: IInstantiationService,
@ILabelService labelService: ILabelService
) {
super(_resource, _id, _index, _query, _parent, _searchModel, replaceService, instantiationService);
super(_resource, _id, _index, _query, _parent, _searchModel, replaceService, instantiationService, labelService);
}

override get resource(): URI {
Expand Down
23 changes: 13 additions & 10 deletions src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts
Expand Up @@ -3,26 +3,28 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { isWindows } from 'vs/base/common/platform';
import { URI as uri } from 'vs/base/common/uri';
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
import { IModelService } from 'vs/editor/common/services/model';
import { ModelService } from 'vs/editor/common/services/modelService';
import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { FileService } from 'vs/platform/files/common/fileService';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { IFileMatch, ITextSearchMatch, OneLineRange, QueryType, SearchSortOrder } from 'vs/workbench/services/search/common/search';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
import { FileMatch, Match, searchMatchComparer, SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
import { isWindows } from 'vs/base/common/platform';
import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices';
import { ILabelService } from 'vs/platform/label/common/label';
import { NullLogService } from 'vs/platform/log/common/log';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { FileService } from 'vs/platform/files/common/fileService';
import { NullLogService } from 'vs/platform/log/common/log';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService';
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
import { FileMatch, Match, searchMatchComparer, SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
import { MockLabelService } from 'vs/workbench/services/label/test/common/mockLabelService';
import { IFileMatch, ITextSearchMatch, OneLineRange, QueryType, SearchSortOrder } from 'vs/workbench/services/search/common/search';
import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices';

suite('Search - Viewlet', () => {
let instantiation: TestInstantiationService;
Expand All @@ -33,6 +35,7 @@ suite('Search - Viewlet', () => {
instantiation.stub(IModelService, stubModelService(instantiation));
instantiation.set(IWorkspaceContextService, new TestContextService(TestWorkspace));
instantiation.stub(IUriIdentityService, new UriIdentityService(new FileService(new NullLogService())));
instantiation.stub(ILabelService, new MockLabelService());
});

test('Data Source', function () {
Expand Down
Expand Up @@ -22,6 +22,8 @@ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService';
import { FileService } from 'vs/platform/files/common/fileService';
import { NullLogService } from 'vs/platform/log/common/log';
import { ILabelService } from 'vs/platform/label/common/label';
import { MockLabelService } from 'vs/workbench/services/label/test/common/mockLabelService';

const lineOneRange = new OneLineRange(1, 0, 1);

Expand All @@ -36,6 +38,7 @@ suite('SearchResult', () => {
instantiationService.stub(IUriIdentityService, new UriIdentityService(new FileService(new NullLogService())));
instantiationService.stubPromise(IReplaceService, {});
instantiationService.stubPromise(IReplaceService, 'replace', null);
instantiationService.stub(ILabelService, new MockLabelService());
});

test('Line Match', function () {
Expand Down
41 changes: 41 additions & 0 deletions src/vs/workbench/services/label/test/common/mockLabelService.ts
@@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Emitter, Event } from 'vs/base/common/event';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { basename, normalize } from 'vs/base/common/path';
import { URI } from 'vs/base/common/uri';
import { IFormatterChangeEvent, ILabelService, ResourceLabelFormatter } from 'vs/platform/label/common/label';
import { IWorkspace, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';

export class MockLabelService implements ILabelService {
_serviceBrand: undefined;

registerCachedFormatter(formatter: ResourceLabelFormatter): IDisposable {
throw new Error('Method not implemented.');
}
getUriLabel(resource: URI, options?: { relative?: boolean | undefined; noPrefix?: boolean | undefined }): string {
return normalize(resource.fsPath);
}
getUriBasenameLabel(resource: URI): string {
return basename(resource.fsPath);
}
getWorkspaceLabel(workspace: URI | IWorkspaceIdentifier | IWorkspace, options?: { verbose: boolean }): string {
return '';
}
getHostLabel(scheme: string, authority?: string): string {
return '';
}
public getHostTooltip(): string | undefined {
return '';
}
getSeparator(scheme: string, authority?: string): '/' | '\\' {
return '/';
}
registerFormatter(formatter: ResourceLabelFormatter): IDisposable {
return Disposable.None;
}
onDidChangeFormatters: Event<IFormatterChangeEvent> = new Emitter<IFormatterChangeEvent>().event;
}