Skip to content

Commit

Permalink
siw: respect 'files.exclude' preference
Browse files Browse the repository at this point in the history
The commit updates the `search-in-workspace` search to respect
the preference `files.exclude` when performing searches.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
Co-authored-by: Muhammad Anas Shahid <muhammad.shahid@ericsson.com>
  • Loading branch information
vince-fugnitto and Muhammad Anas Shahid committed Sep 14, 2020
1 parent e7a0160 commit 4e000ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
import { CancellationTokenSource, Emitter, Event } from '@theia/core';
import { EditorManager, EditorDecoration, TrackedRangeStickiness, OverviewRulerLane, EditorWidget, ReplaceOperation, EditorOpenerOptions } from '@theia/editor/lib/browser';
import { WorkspaceService } from '@theia/workspace/lib/browser';
import { FileResourceResolver } from '@theia/filesystem/lib/browser';
import { FileResourceResolver, FileSystemPreferences } from '@theia/filesystem/lib/browser';
import { SearchInWorkspaceResult, SearchInWorkspaceOptions, SearchMatch } from '../common/search-in-workspace-interface';
import { SearchInWorkspaceService } from './search-in-workspace-service';
import { MEMORY_TEXT } from './in-memory-text-resource';
Expand Down Expand Up @@ -120,6 +120,7 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
@inject(SearchInWorkspacePreferences) protected readonly searchInWorkspacePreferences: SearchInWorkspacePreferences;
@inject(ProgressService) protected readonly progressService: ProgressService;
@inject(ColorRegistry) protected readonly colorRegistry: ColorRegistry;
@inject(FileSystemPreferences) protected readonly filesystemPreferences: FileSystemPreferences;

constructor(
@inject(TreeProps) readonly props: TreeProps,
Expand Down Expand Up @@ -201,6 +202,10 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
async search(searchTerm: string, searchOptions: SearchInWorkspaceOptions): Promise<void> {
this.searchTerm = searchTerm;
const collapseValue: string = this.searchInWorkspacePreferences['search.collapseResults'];
searchOptions = {
...searchOptions,
exclude: this.getExcludeGlobs(searchOptions.exclude)
};
this.resultTree.clear();
if (this.cancelIndicator) {
this.cancelIndicator.cancel();
Expand Down Expand Up @@ -773,6 +778,18 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
return decorations;
}

/**
* Get the list of exclude globs.
* @param excludeOptions the exclude search option.
*
* @returns the list of exclude globs.
*/
protected getExcludeGlobs(excludeOptions?: string[]): string[] {
const excludePreferences = this.filesystemPreferences['files.exclude'];
const excludePreferencesGlobs = Object.keys(excludePreferences).filter(key => !!excludePreferences[key]);
return [...new Set([...excludePreferencesGlobs, ...excludeOptions])];
}

/**
* Compare two normalized strings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,20 @@ describe('ripgrep-search-in-workspace-server', function (): void {
ripgrepServer.search(pattern, [rootDirAUri], { include: ['*.txt'], matchWholeWord: true });
});

it('should return 1 result when searching for "test" while ignoring all ".txt" files', done => {
const pattern = 'test';

const client = new ResultAccumulator(() => {
const expected: SearchInWorkspaceExpectation[] = [
{ root: rootDirAUri, fileUri: 'glob', line: 1, character: 1, length: pattern.length, lineText: '' },
];
compareSearchResults(expected, client.results);
done();
});
ripgrepServer.setClient(client);
ripgrepServer.search(pattern, [rootDirAUri, rootDirBUri], { exclude: ['*.txt'] });
});

// Try searching in an UTF-8 file.
it('should search in a UTF-8 file', done => {
const pattern = ' jag';
Expand Down

0 comments on commit 4e000ce

Please sign in to comment.