diff --git a/src/vs/workbench/contrib/search/browser/search.contribution.ts b/src/vs/workbench/contrib/search/browser/search.contribution.ts index 16bcfbec09f..517e588a6fd 100644 --- a/src/vs/workbench/contrib/search/browser/search.contribution.ts +++ b/src/vs/workbench/contrib/search/browser/search.contribution.ts @@ -27,7 +27,7 @@ import { SymbolsQuickAccessProvider } from './symbolsQuickAccess.js'; import { ISearchHistoryService, SearchHistoryService } from '../common/searchHistoryService.js'; import { SearchViewModelWorkbenchService } from './searchTreeModel/searchModel.js'; import { ISearchViewModelWorkbenchService } from './searchTreeModel/searchViewModelWorkbenchService.js'; -import { SearchSortOrder, SEARCH_EXCLUDE_CONFIG, VIEWLET_ID, ViewMode, VIEW_ID, DEFAULT_MAX_SEARCH_RESULTS } from '../../../services/search/common/search.js'; +import { SearchSortOrder, SEARCH_EXCLUDE_CONFIG, VIEWLET_ID, ViewMode, VIEW_ID, DEFAULT_MAX_SEARCH_RESULTS, AutoSemanticSearch } from '../../../services/search/common/search.js'; import { CommandsRegistry } from '../../../../platform/commands/common/commands.js'; import { assertType } from '../../../../base/common/types.js'; import { getWorkspaceSymbols, IWorkspaceSymbol } from '../common/search.js'; @@ -388,10 +388,17 @@ configurationRegistry.registerConfiguration({ description: nls.localize('search.experimental.closedNotebookResults', "Show notebook editor rich content results for closed notebooks. Please refresh your search results after changing this setting."), default: false }, - 'search.experimental.autoAISearchResults': { - type: 'boolean', - description: nls.localize('search.experimental.autoAISearchResults', "Automatically request search results from the AI search provider"), - default: false + 'search.searchView.autoSemanticSearchResults': { + type: 'string', + description: nls.localize('search.searchView.autoSemanticSearchResults', "Automatically request semantic search results in the search view."), + enum: [AutoSemanticSearch.Disabled, AutoSemanticSearch.OnEmptyResults, AutoSemanticSearch.Enabled], + default: AutoSemanticSearch.Disabled, + enumDescriptions: [ + nls.localize('search.searchView.autoSemanticSearchResults.disabled', "Disable automatic semantic search results."), + nls.localize('search.searchView.autoSemanticSearchResults.onEmptyResults', "Only automatically request semantic results when text search results are empty."), + nls.localize('search.searchView.autoSemanticSearchResults.enabled', "Enable automatic semantic search results.") + ], + tags: ['preview'], }, } }); diff --git a/src/vs/workbench/contrib/search/browser/searchView.ts b/src/vs/workbench/contrib/search/browser/searchView.ts index e662dd7f781..8b278ba91cc 100644 --- a/src/vs/workbench/contrib/search/browser/searchView.ts +++ b/src/vs/workbench/contrib/search/browser/searchView.ts @@ -70,7 +70,7 @@ import { createEditorFromSearchResult } from '../../searchEditor/browser/searchE import { ACTIVE_GROUP, IEditorService, SIDE_GROUP } from '../../../services/editor/common/editorService.js'; import { IPreferencesService, ISettingsEditorOptions } from '../../../services/preferences/common/preferences.js'; import { ITextQueryBuilderOptions, QueryBuilder } from '../../../services/search/common/queryBuilder.js'; -import { IPatternInfo, ISearchComplete, ISearchConfiguration, ISearchConfigurationProperties, ISearchService, ITextQuery, SearchCompletionExitCode, SearchSortOrder, TextSearchCompleteMessageType, ViewMode } from '../../../services/search/common/search.js'; +import { AutoSemanticSearch, IPatternInfo, ISearchComplete, ISearchConfiguration, ISearchConfigurationProperties, ISearchService, ITextQuery, SearchCompletionExitCode, SearchSortOrder, TextSearchCompleteMessageType, ViewMode } from '../../../services/search/common/search.js'; import { AISearchKeyword, TextSearchCompleteMessage } from '../../../services/search/common/searchExtTypes.js'; import { ITextFileService } from '../../../services/textfile/common/textfiles.js'; import { INotebookService } from '../../notebook/common/notebookService.js'; @@ -628,11 +628,11 @@ export class SearchView extends ViewPane { } this._register(this.searchWidget.onSearchSubmit(options => { - const shouldRenderAIResults = this.configurationService.getValue('search').experimental?.autoAISearchResults; + const shouldRenderAIResults = this.configurationService.getValue('search').searchView.autoAISearchResults; this.triggerQueryChange({ ...options, shouldKeepAIResults: false, - shouldUpdateAISearch: shouldRenderAIResults, + shouldUpdateAISearch: shouldRenderAIResults === AutoSemanticSearch.Enabled, }); })); this._register(this.searchWidget.onSearchCancel(({ focus }) => this.cancelSearch(focus))); @@ -1879,6 +1879,10 @@ export class SearchView extends ViewPane { return result.asyncResults.then((complete) => { clearTimeout(slowTimer); + const config = this.configurationService.getValue('search').searchView.autoAISearchResults; + if (complete.results.length === 0 && config === AutoSemanticSearch.OnEmptyResults) { + this.model.searchResult.aiTextSearchResult.hidden = false; + } return this.onSearchComplete(progressComplete, excludePatternText, includePatternText, complete); }, (e) => { clearTimeout(slowTimer); diff --git a/src/vs/workbench/services/search/common/search.ts b/src/vs/workbench/services/search/common/search.ts index dfe6e292a27..d064b86b9c2 100644 --- a/src/vs/workbench/services/search/common/search.ts +++ b/src/vs/workbench/services/search/common/search.ts @@ -416,6 +416,12 @@ export const enum SearchSortOrder { CountAscending = 'countAscending' } +export const enum AutoSemanticSearch { + Enabled = 'enabled', + Disabled = 'disabled', + OnEmptyResults = 'onEmptyResults', +} + export interface ISearchConfigurationProperties { exclude: glob.IExpression; useRipgrep: boolean; @@ -460,7 +466,9 @@ export interface ISearchConfigurationProperties { defaultViewMode: ViewMode; experimental: { closedNotebookRichContentResults: boolean; - autoAISearchResults: boolean; + }; + searchView: { + autoAISearchResults: string; }; }