Skip to content

Commit

Permalink
feat: implement proposed search api
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Jun 9, 2023
1 parent 422664f commit 26f9b96
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"type": "module",
"main": "dist/api.js",
"module": "dist/api.js",
"enabledApiProposals": ["fileSearchProvider", "textSearchProvider"],
"exports": {
".": {
"default": "./dist/api.js"
Expand Down
5 changes: 4 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference path="./types.d.ts" />
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes'
import * as errors from 'vs/base/common/errors'
import * as commonDebug from 'vs/workbench/contrib/debug/common/debug'
Expand All @@ -12,6 +13,7 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions'
import * as uri from 'vs/base/common/uri'
import * as log from 'vs/platform/log/common/log'
import * as telemetryUtils from 'vs/platform/telemetry/common/telemetryUtils'
import * as searchExtHostTypes from 'vs/workbench/services/search/common/searchExtTypes'
import createL10nApi from './vscode-services/l10n'
import createLanguagesApi from './vscode-services/languages'
import createCommandsApi from './vscode-services/commands'
Expand Down Expand Up @@ -198,7 +200,8 @@ const api: typeof vscode = {
LogLevel: log.LogLevel,
TerminalExitReason: extHostTypes.TerminalExitReason,
CommentThreadState: unsupported,
TelemetryTrustedValue: telemetryUtils.TelemetryTrustedValue
TelemetryTrustedValue: telemetryUtils.TelemetryTrustedValue,
TextSearchCompleteMessageType: searchExtHostTypes.TextSearchCompleteMessageType
}

// @ts-ignore the syntax will be transformed by a typescript transformer in the rollup config
Expand Down
9 changes: 7 additions & 2 deletions src/vscode-services/extHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'
import { ExtHostStatusBar } from 'vs/workbench/api/common/extHostStatusBar'
import { ExtHostTheming } from 'vs/workbench/api/common/extHostTheming'
import { ExtHostTerminalService } from 'vs/workbench/api/node/extHostTerminalService'
import { ExtHostSearch, IExtHostSearch } from 'vs/workbench/api/common/extHostSearch'
import 'vs/workbench/api/browser/mainThreadLocalization'
import 'vs/workbench/api/browser/mainThreadCommands'
import 'vs/workbench/api/browser/mainThreadWindow'
Expand Down Expand Up @@ -90,6 +91,7 @@ import 'vs/workbench/api/browser/mainThreadStatusBar'
import 'vs/workbench/api/browser/mainThreadTheming'
import 'vs/workbench/api/browser/mainThreadTerminalService'
import 'vs/workbench/api/browser/mainThreadEditorTabs'
import 'vs/workbench/api/browser/mainThreadSearch'
import * as errors from 'vs/base/common/errors'
import { Barrier } from 'vs/base/common/async'
import { unsupported } from '../tools'
Expand Down Expand Up @@ -223,6 +225,7 @@ registerSingleton(IExtHostVariableResolverProvider, ExtHostVariableResolverProvi
registerSingleton(IExtHostOutputService, ExtHostOutputService, InstantiationType.Delayed)
registerSingleton(IExtHostTerminalService, ExtHostTerminalService, InstantiationType.Eager)
registerSingleton(IExtHostLocalizationService, ExtHostLocalizationService, InstantiationType.Delayed)
registerSingleton(IExtHostSearch, ExtHostSearch, InstantiationType.Eager)

const mainContext: IMainContext & IInternalExtHostContext = {
remoteAuthority: null,
Expand Down Expand Up @@ -290,7 +293,7 @@ async function createExtHostServices () {
const extHostDocumentsAndEditors = rpcProtocol.set(ExtHostContext.ExtHostDocumentsAndEditors, StandaloneServices.get(IExtHostDocumentsAndEditors))
const extHostLocalization = rpcProtocol.set(ExtHostContext.ExtHostLocalization, StandaloneServices.get(IExtHostLocalizationService))
const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, StandaloneServices.get(IExtHostTerminalService))
const extHostTheming = rpcProtocol.set(ExtHostContext.ExtHostTheming, new ExtHostTheming(rpcProtocol))
const extHostSearch = rpcProtocol.set(ExtHostContext.ExtHostSearch, StandaloneServices.get(IExtHostSearch))

// manually create and register addressable instances
const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, createExtHostQuickOpen(mainContext, <IExtHostWorkspaceProvider><unknown>null, extHostCommands))
Expand All @@ -311,6 +314,7 @@ async function createExtHostServices () {
const extHostDocumentSaveParticipant = rpcProtocol.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(logService, extHostDocuments, rpcProtocol.getProxy(MainContext.MainThreadBulkEdits)))
const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpcProtocol, logService, extHostDocumentsAndEditors))
const extHostTreeViews = rpcProtocol.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(rpcProtocol.getProxy(MainContext.MainThreadTreeViews), extHostCommands, logService))
const extHostTheming = rpcProtocol.set(ExtHostContext.ExtHostTheming, new ExtHostTheming(rpcProtocol))

const extHostStorage = new ExtHostStorage(rpcProtocol, logService)

Expand Down Expand Up @@ -385,7 +389,8 @@ async function createExtHostServices () {
extHostTerminalService,
extHostEditorTabs,
extHostDecorations,
extHostTheming
extHostTheming,
extHostSearch
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/vscode-services/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/// <reference path="../../vscode.proposed.fileSearchProvider.d.ts" />
/// <reference path="../../vscode.proposed.textSearchProvider.d.ts" />
import type * as vscode from 'vscode'
import { URI } from 'vs/base/common/uri'
import { combinedDisposable } from 'vs/base/common/lifecycle'
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { Event } from 'vs/base/common/event'
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions'
import { getConfigProvider, getExtHostServices } from './extHost'
import { unsupported } from '../tools'

Expand All @@ -12,6 +15,18 @@ export default function create (getExtension: () => IExtensionDescription): type
const { extHostConsumerFileSystem } = getExtHostServices()
return extHostConsumerFileSystem.value
},
registerFileSearchProvider: (scheme: string, provider: vscode.FileSearchProvider) => {
const { extHostSearch } = getExtHostServices()
const extension = getExtension()
checkProposedApiEnabled(extension, 'fileSearchProvider')
return extHostSearch.registerFileSearchProvider(scheme, provider)
},
registerTextSearchProvider: (scheme: string, provider: vscode.TextSearchProvider) => {
const { extHostSearch } = getExtHostServices()
const extension = getExtension()
checkProposedApiEnabled(extension, 'textSearchProvider')
return extHostSearch.registerTextSearchProvider(scheme, provider)
},
get workspaceFile () {
const { extHostWorkspace } = getExtHostServices()
return extHostWorkspace.workspaceFile
Expand Down
67 changes: 67 additions & 0 deletions vscode.proposed.fileSearchProvider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'vscode' {

// https://github.com/microsoft/vscode/issues/73524

/**
* The parameters of a query for file search.
*/
export interface FileSearchQuery {
/**
* The search pattern to match against file paths.
*/
pattern: string;
}

/**
* Options that apply to file search.
*/
export interface FileSearchOptions extends SearchOptions {
/**
* The maximum number of results to be returned.
*/
maxResults?: number;

/**
* A CancellationToken that represents the session for this search query. If the provider chooses to, this object can be used as the key for a cache,
* and searches with the same session object can search the same cache. When the token is cancelled, the session is complete and the cache can be cleared.
*/
session?: CancellationToken;
}

/**
* A FileSearchProvider provides search results for files in the given folder that match a query string. It can be invoked by quickopen or other extensions.
*
* A FileSearchProvider is the more powerful of two ways to implement file search in the editor. Use a FileSearchProvider if you wish to search within a folder for
* all files that match the user's query.
*
* The FileSearchProvider will be invoked on every keypress in quickopen. When `workspace.findFiles` is called, it will be invoked with an empty query string,
* and in that case, every file in the folder should be returned.
*/
export interface FileSearchProvider {
/**
* Provide the set of files that match a certain file path pattern.
* @param query The parameters for this query.
* @param options A set of options to consider while searching files.
* @param token A cancellation token.
*/
provideFileSearchResults(query: FileSearchQuery, options: FileSearchOptions, token: CancellationToken): ProviderResult<Uri[]>;
}

export namespace workspace {
/**
* Register a search provider.
*
* Only one provider can be registered per scheme.
*
* @param scheme The provider will be invoked for workspace folders that have this file scheme.
* @param provider The provider.
* @return A {@link Disposable} that unregisters this provider when being disposed.
*/
export function registerFileSearchProvider(scheme: string, provider: FileSearchProvider): Disposable;
}
}
Loading

0 comments on commit 26f9b96

Please sign in to comment.