From ddd8dbf9b32e4aaa1845a46fccb0f1cb384c9a52 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Thu, 16 Mar 2017 19:11:02 -0700 Subject: [PATCH] Provide a way to enable/disable gitignore support for #19983 --- src/vs/platform/search/common/search.ts | 1 + .../parts/search/browser/media/git-dark.svg | 1 + .../parts/search/browser/media/git.svg | 1 + .../search/browser/media/searchviewlet.css | 11 +++++++ .../search/browser/patternInputWidget.ts | 33 +++++++++++++++++-- .../parts/search/browser/searchViewlet.ts | 25 ++++++++------ .../parts/search/common/searchQuery.ts | 3 +- .../services/search/node/ripgrepTextSearch.ts | 5 +++ .../workbench/services/search/node/search.ts | 1 + .../services/search/node/searchService.ts | 3 +- 10 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 src/vs/workbench/parts/search/browser/media/git-dark.svg create mode 100644 src/vs/workbench/parts/search/browser/media/git.svg diff --git a/src/vs/platform/search/common/search.ts b/src/vs/platform/search/common/search.ts index e9fb3a1bab9..93e6a577407 100644 --- a/src/vs/platform/search/common/search.ts +++ b/src/vs/platform/search/common/search.ts @@ -36,6 +36,7 @@ export interface IQueryOptions { cacheKey?: string; fileEncoding?: string; useRipgrep?: boolean; + useIgnoreFiles?: boolean; } export interface ISearchQuery extends IQueryOptions { diff --git a/src/vs/workbench/parts/search/browser/media/git-dark.svg b/src/vs/workbench/parts/search/browser/media/git-dark.svg new file mode 100644 index 00000000000..c08b1c2e403 --- /dev/null +++ b/src/vs/workbench/parts/search/browser/media/git-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/vs/workbench/parts/search/browser/media/git.svg b/src/vs/workbench/parts/search/browser/media/git.svg new file mode 100644 index 00000000000..d1049a44d0d --- /dev/null +++ b/src/vs/workbench/parts/search/browser/media/git.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/vs/workbench/parts/search/browser/media/searchviewlet.css b/src/vs/workbench/parts/search/browser/media/searchviewlet.css index 29c80a02fee..32815eb2aa8 100644 --- a/src/vs/workbench/parts/search/browser/media/searchviewlet.css +++ b/src/vs/workbench/parts/search/browser/media/searchviewlet.css @@ -299,6 +299,17 @@ background: url('pattern-dark.svg') center center no-repeat; } +.vs .monaco-workbench .search-viewlet .query-details .file-types .controls>.custom-checkbox.useIgnoreFiles { + background: url('git.svg') center center no-repeat; + background-size: 20px 20px; +} + +.vs-dark .monaco-workbench .search-viewlet .query-details .file-types .controls>.custom-checkbox.useIgnoreFiles, +.hc-black .monaco-workbench .search-viewlet .query-details .file-types .controls>.custom-checkbox.useIgnoreFiles { + background: url('git-dark.svg') center center no-repeat; + background-size: 20px 20px; +} + .search-viewlet .findInFileMatch, .monaco-editor .findInFileMatch { background-color: rgba(234, 92, 0, 0.3); diff --git a/src/vs/workbench/parts/search/browser/patternInputWidget.ts b/src/vs/workbench/parts/search/browser/patternInputWidget.ts index 15bd08c242e..a7e6ded92dd 100644 --- a/src/vs/workbench/parts/search/browser/patternInputWidget.ts +++ b/src/vs/workbench/parts/search/browser/patternInputWidget.ts @@ -36,6 +36,7 @@ export class PatternInputWidget extends Widget { private toDispose: any[]; private pattern: Checkbox; + private useIgnoreFilesBox: Checkbox; private domNode: HTMLElement; private inputNode: HTMLInputElement; @@ -44,7 +45,7 @@ export class PatternInputWidget extends Widget { private _onSubmit = this._register(new Emitter()); public onSubmit: CommonEvent = this._onSubmit.event; - constructor(parent: HTMLElement, private contextViewProvider: IContextViewProvider, options: IOptions = Object.create(null)) { + constructor(parent: HTMLElement, private contextViewProvider: IContextViewProvider, options: IOptions = Object.create(null), private showUseIgnoreFiles = false) { super(); this.onOptionChange = null; this.width = options.width || 100; @@ -53,6 +54,7 @@ export class PatternInputWidget extends Widget { this.toDispose = []; this.pattern = null; + this.useIgnoreFilesBox = null; this.domNode = null; this.inputNode = null; this.inputBox = null; @@ -65,6 +67,7 @@ export class PatternInputWidget extends Widget { public dispose(): void { super.dispose(); this.pattern.dispose(); + this.useIgnoreFilesBox.dispose(); this.toDispose.forEach((element) => { element(); }); @@ -142,6 +145,15 @@ export class PatternInputWidget extends Widget { return this.inputBox.hasFocus(); } + public useIgnoreFiles(): boolean { + return this.useIgnoreFilesBox.checked; + } + + public setUseIgnoreFiles(value: boolean): void { + this.useIgnoreFilesBox.checked = value; + this.setInputWidth(); + } + public isGlobPattern(): boolean { return this.pattern.checked; } @@ -152,7 +164,7 @@ export class PatternInputWidget extends Widget { } private setInputWidth(): void { - let w = this.width - this.pattern.width(); + let w = this.width - this.pattern.width() - this.useIgnoreFilesBox.width(); this.inputBox.width = w; } @@ -191,6 +203,19 @@ export class PatternInputWidget extends Widget { } }); + this.useIgnoreFilesBox = new Checkbox({ + actionClassName: 'useIgnoreFiles', + title: nls.localize('useIgnoreFilesDescription', "Use Ignore Files"), + isChecked: false, + onChange: (viaKeyboard) => { + this.onOptionChange(null); + if (!viaKeyboard) { + this.inputBox.focus(); + } + this.setInputWidth(); + } + }); + $(this.pattern.domNode).on('mouseover', () => { if (this.isGlobPattern()) { this.showGlobHelp(); @@ -205,6 +230,10 @@ export class PatternInputWidget extends Widget { let controls = document.createElement('div'); controls.className = 'controls'; + if (this.showUseIgnoreFiles) { + controls.appendChild(this.useIgnoreFilesBox.domNode); + } + controls.appendChild(this.pattern.domNode); this.domNode.appendChild(controls); diff --git a/src/vs/workbench/parts/search/browser/searchViewlet.ts b/src/vs/workbench/parts/search/browser/searchViewlet.ts index 2ffa4ff941c..9988b6017d4 100644 --- a/src/vs/workbench/parts/search/browser/searchViewlet.ts +++ b/src/vs/workbench/parts/search/browser/searchViewlet.ts @@ -163,6 +163,7 @@ export class SearchViewlet extends Viewlet { let exclusionsUsePattern = this.viewletSettings['query.exclusionsUsePattern']; let includesUsePattern = this.viewletSettings['query.includesUsePattern']; let patternIncludes = this.viewletSettings['query.folderIncludes'] || ''; + let useIgnoreFiles = this.viewletSettings['query.useIgnoreFiles']; this.queryDetails = this.searchWidgetsContainer.div({ 'class': ['query-details'] }, (builder) => { builder.div({ 'class': 'more', 'tabindex': 0, 'role': 'button', 'title': nls.localize('moreSearch', "Toggle Search Details") }) @@ -206,10 +207,11 @@ export class SearchViewlet extends Viewlet { this.inputPatternExclusions = new PatternInputWidget(builder.getContainer(), this.contextViewService, { ariaLabel: nls.localize('label.excludes', 'Search Exclude Patterns') - }); + }, true); this.inputPatternExclusions.setIsGlobPattern(exclusionsUsePattern); this.inputPatternExclusions.setValue(patternExclusions); + this.inputPatternExclusions.setUseIgnoreFiles(useIgnoreFiles); this.inputPatternExclusions .on(FindInput.OPTION_CHANGE, (e) => { @@ -902,14 +904,15 @@ export class SearchViewlet extends Viewlet { } public onQueryChanged(rerunQuery: boolean, preserveFocus?: boolean): void { - let isRegex = this.searchWidget.searchInput.getRegex(); - let isWholeWords = this.searchWidget.searchInput.getWholeWords(); - let isCaseSensitive = this.searchWidget.searchInput.getCaseSensitive(); - let contentPattern = this.searchWidget.searchInput.getValue(); - let patternExcludes = this.inputPatternExclusions.getValue().trim(); - let exclusionsUsePattern = this.inputPatternExclusions.isGlobPattern(); - let patternIncludes = this.inputPatternIncludes.getValue().trim(); - let includesUsePattern = this.inputPatternIncludes.isGlobPattern(); + const isRegex = this.searchWidget.searchInput.getRegex(); + const isWholeWords = this.searchWidget.searchInput.getWholeWords(); + const isCaseSensitive = this.searchWidget.searchInput.getCaseSensitive(); + const contentPattern = this.searchWidget.searchInput.getValue(); + const patternExcludes = this.inputPatternExclusions.getValue().trim(); + const exclusionsUsePattern = this.inputPatternExclusions.isGlobPattern(); + const patternIncludes = this.inputPatternIncludes.getValue().trim(); + const includesUsePattern = this.inputPatternIncludes.isGlobPattern(); + const useIgnoreFiles = this.inputPatternExclusions.useIgnoreFiles(); // store memento this.viewletSettings['query.contentPattern'] = contentPattern; @@ -920,6 +923,7 @@ export class SearchViewlet extends Viewlet { this.viewletSettings['query.exclusionsUsePattern'] = exclusionsUsePattern; this.viewletSettings['query.folderIncludes'] = patternIncludes; this.viewletSettings['query.includesUsePattern'] = includesUsePattern; + this.viewletSettings['query.useIgnoreFiles'] = useIgnoreFiles; if (!rerunQuery) { return; @@ -958,7 +962,8 @@ export class SearchViewlet extends Viewlet { extraFileResources: getOutOfWorkspaceEditorResources(this.editorGroupService, this.contextService), excludePattern: excludes, maxResults: SearchViewlet.MAX_TEXT_RESULTS, - includePattern: includes + includePattern: includes, + useIgnoreFiles }; this.onQueryTriggered(this.queryBuilder.text(content, options), patternExcludes, patternIncludes); diff --git a/src/vs/workbench/parts/search/common/searchQuery.ts b/src/vs/workbench/parts/search/common/searchQuery.ts index 3e9a193f4f4..3ebbbce7528 100644 --- a/src/vs/workbench/parts/search/common/searchQuery.ts +++ b/src/vs/workbench/parts/search/common/searchQuery.ts @@ -43,7 +43,8 @@ export class QueryBuilder { cacheKey: options.cacheKey, fileEncoding: options.fileEncoding, contentPattern: contentPattern, - useRipgrep: configuration.search.useRipgrep + useRipgrep: configuration.search.useRipgrep, + useIgnoreFiles: options.useIgnoreFiles }; } } \ No newline at end of file diff --git a/src/vs/workbench/services/search/node/ripgrepTextSearch.ts b/src/vs/workbench/services/search/node/ripgrepTextSearch.ts index 0be9f0d8aeb..0c9d7638c43 100644 --- a/src/vs/workbench/services/search/node/ripgrepTextSearch.ts +++ b/src/vs/workbench/services/search/node/ripgrepTextSearch.ts @@ -331,6 +331,11 @@ function getRgArgs(config: IRawSearch): { args: string[], siblingClauses: glob.S } } + if (!config.useIgnoreFiles) { + // Don't use .gitignore or .ignore + args.push('--no-ignore'); + } + // Folder to search args.push('--', './'); diff --git a/src/vs/workbench/services/search/node/search.ts b/src/vs/workbench/services/search/node/search.ts index 7552d44c8de..7f4ed33e360 100644 --- a/src/vs/workbench/services/search/node/search.ts +++ b/src/vs/workbench/services/search/node/search.ts @@ -22,6 +22,7 @@ export interface IRawSearch { maxFilesize?: number; fileEncoding?: string; useRipgrep?: boolean; + useIgnoreFiles?: boolean; } export interface IRawSearchService { diff --git a/src/vs/workbench/services/search/node/searchService.ts b/src/vs/workbench/services/search/node/searchService.ts index 0a29f293e6f..141217aa367 100644 --- a/src/vs/workbench/services/search/node/searchService.ts +++ b/src/vs/workbench/services/search/node/searchService.ts @@ -236,7 +236,8 @@ export class DiskSearch { maxResults: query.maxResults, sortByScore: query.sortByScore, cacheKey: query.cacheKey, - useRipgrep: query.useRipgrep + useRipgrep: query.useRipgrep, + useIgnoreFiles: query.useIgnoreFiles }; if (query.type === QueryType.Text) { -- GitLab