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

siw: respect 'files.exclude' preference #8433

Merged
merged 1 commit into from
Sep 14, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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