From bce86a137e61aa2840e71f74864e797d30d4cdff Mon Sep 17 00:00:00 2001 From: digeff Date: Wed, 21 Oct 2020 17:05:24 -0700 Subject: [PATCH] Fixed other context menus using this context --- .../workbench/api/common/extHost.api.impl.ts | 4 ++-- src/vs/workbench/api/common/extHostSearch.ts | 18 ++++++++++++++++-- src/vs/workbench/api/node/extHostSearch.ts | 4 +++- .../contrib/search/browser/searchActions.ts | 8 +++++--- .../contrib/search/browser/searchView.ts | 19 +++++++++++++++---- .../contrib/search/common/searchModel.ts | 12 ++++++++++++ .../api/extHostSearch.test.ts | 4 +++- 7 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 284c6aff854..76d19f58034 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -62,7 +62,7 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation import { IExtHostDecorations } from 'vs/workbench/api/common/extHostDecorations'; import { IExtHostTask } from 'vs/workbench/api/common/extHostTask'; import { IExtHostDebugService } from 'vs/workbench/api/common/extHostDebugService'; -import { IExtHostSearch } from 'vs/workbench/api/common/extHostSearch'; +import { ExtHostSearch } from 'vs/workbench/api/common/extHostSearch'; import { ILogService } from 'vs/platform/log/common/log'; import { IURITransformerService } from 'vs/workbench/api/common/extHostUriTransformerService'; import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; @@ -123,11 +123,11 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I const extHostCommands = rpcProtocol.set(ExtHostContext.ExtHostCommands, accessor.get(IExtHostCommands)); const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, accessor.get(IExtHostTerminalService)); const extHostDebugService = rpcProtocol.set(ExtHostContext.ExtHostDebugService, accessor.get(IExtHostDebugService)); - const extHostSearch = rpcProtocol.set(ExtHostContext.ExtHostSearch, accessor.get(IExtHostSearch)); const extHostTask = rpcProtocol.set(ExtHostContext.ExtHostTask, accessor.get(IExtHostTask)); const extHostOutputService = rpcProtocol.set(ExtHostContext.ExtHostOutputService, accessor.get(IExtHostOutputService)); // manually create and register addressable instances + const extHostSearch = rpcProtocol.set(ExtHostContext.ExtHostSearch, new ExtHostSearch(rpcProtocol, uriTransformer, extHostLogService, extHostCommands)); const extHostUrls = rpcProtocol.set(ExtHostContext.ExtHostUrls, new ExtHostUrls(rpcProtocol)); const extHostDocuments = rpcProtocol.set(ExtHostContext.ExtHostDocuments, new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors)); const extHostDocumentContentProviders = rpcProtocol.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(rpcProtocol, extHostDocumentsAndEditors, extHostLogService)); diff --git a/src/vs/workbench/api/common/extHostSearch.ts b/src/vs/workbench/api/common/extHostSearch.ts index 7ed796455c5..35be0067228 100644 --- a/src/vs/workbench/api/common/extHostSearch.ts +++ b/src/vs/workbench/api/common/extHostSearch.ts @@ -14,6 +14,7 @@ import { ILogService } from 'vs/platform/log/common/log'; import { IRawFileQuery, ISearchCompleteStats, IFileQuery, IRawTextQuery, IRawQuery, ITextQuery, IFolderQuery } from 'vs/workbench/services/search/common/search'; import { URI, UriComponents } from 'vs/base/common/uri'; import { TextSearchManager } from 'vs/workbench/services/search/common/textSearchManager'; +import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands'; export interface IExtHostSearch extends ExtHostSearchShape { registerTextSearchProvider(scheme: string, provider: vscode.TextSearchProvider): IDisposable; @@ -37,8 +38,21 @@ export class ExtHostSearch implements ExtHostSearchShape { constructor( @IExtHostRpcService private extHostRpc: IExtHostRpcService, @IURITransformerService protected _uriTransformer: IURITransformerService, - @ILogService protected _logService: ILogService - ) { } + @ILogService protected _logService: ILogService, + commands: ExtHostCommands, + ) { + commands.registerArgumentProcessor({ + processArgument: arg => { + if (arg.renderableMatch !== undefined) { + const filteredProperties = { ...arg }; + delete filteredProperties.renderableMatch; + return filteredProperties; + } else { + return arg; + } + } + }); + } protected _transformScheme(scheme: string): string { return this._uriTransformer.transformOutgoingScheme(scheme); diff --git a/src/vs/workbench/api/node/extHostSearch.ts b/src/vs/workbench/api/node/extHostSearch.ts index 497f971404b..e0578d6fe2f 100644 --- a/src/vs/workbench/api/node/extHostSearch.ts +++ b/src/vs/workbench/api/node/extHostSearch.ts @@ -19,6 +19,7 @@ import { ExtHostSearch, reviveQuery } from 'vs/workbench/api/common/extHostSearc import { Schemas } from 'vs/base/common/network'; import { NativeTextSearchManager } from 'vs/workbench/services/search/node/textSearchManager'; import { TextSearchManager } from 'vs/workbench/services/search/common/textSearchManager'; +import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands'; export class NativeExtHostSearch extends ExtHostSearch { @@ -32,8 +33,9 @@ export class NativeExtHostSearch extends ExtHostSearch { @IExtHostInitDataService initData: IExtHostInitDataService, @IURITransformerService _uriTransformer: IURITransformerService, @ILogService _logService: ILogService, + commands: ExtHostCommands, ) { - super(extHostRpc, _uriTransformer, _logService); + super(extHostRpc, _uriTransformer, _logService, commands); if (initData.remote.isRemote && initData.remote.authority) { this._registerEHSearchProviders(); diff --git a/src/vs/workbench/contrib/search/browser/searchActions.ts b/src/vs/workbench/contrib/search/browser/searchActions.ts index d2f10840868..9390c58d78e 100644 --- a/src/vs/workbench/contrib/search/browser/searchActions.ts +++ b/src/vs/workbench/contrib/search/browser/searchActions.ts @@ -15,7 +15,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { getSelectionKeyboardEvent, WorkbenchObjectTree } from 'vs/platform/list/browser/listService'; -import { SearchView } from 'vs/workbench/contrib/search/browser/searchView'; +import { IFileMatchContext, IFolderMatchWithResourceContext, IRenderableMatchContext, SearchView } from 'vs/workbench/contrib/search/browser/searchView'; import * as Constants from 'vs/workbench/contrib/search/common/constants'; import { IReplaceService } from 'vs/workbench/contrib/search/common/replace'; import { FolderMatch, FileMatch, FolderMatchWithResource, Match, RenderableMatch, searchMatchComparer, SearchResult } from 'vs/workbench/contrib/search/common/searchModel'; @@ -776,7 +776,8 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { } } -export const copyPathCommand: ICommandHandler = async (accessor, fileMatch: FileMatch | FolderMatchWithResource | undefined) => { +export const copyPathCommand: ICommandHandler = async (accessor, fileMatchArg: IFileMatchContext | IFolderMatchWithResourceContext | undefined) => { + let fileMatch = fileMatchArg?.renderableMatch; if (!fileMatch) { const selection = getSelectedRow(accessor); if (!(selection instanceof FileMatch || selection instanceof FolderMatchWithResource)) { @@ -852,7 +853,8 @@ function folderMatchToString(folderMatch: FolderMatchWithResource | FolderMatch, } const maxClipboardMatches = 1e4; -export const copyMatchCommand: ICommandHandler = async (accessor, match: RenderableMatch | undefined) => { +export const copyMatchCommand: ICommandHandler = async (accessor, matchArg: IRenderableMatchContext | undefined) => { + let match = matchArg?.renderableMatch; if (!match) { const selection = getSelectedRow(accessor); if (!selection) { diff --git a/src/vs/workbench/contrib/search/browser/searchView.ts b/src/vs/workbench/contrib/search/browser/searchView.ts index 91fc96c64f7..efeea9c3368 100644 --- a/src/vs/workbench/contrib/search/browser/searchView.ts +++ b/src/vs/workbench/contrib/search/browser/searchView.ts @@ -98,6 +98,7 @@ export interface IMatchContext { uri: URI; /** location of where the matched text is inside the file */ matchRange: Range; + renderableMatch: Match; } export interface IFileMatchContext { @@ -107,6 +108,7 @@ export interface IFileMatchContext { uri: URI; /** matches for this particular file */ matches: IMatchContext[]; + renderableMatch: FileMatch; } export interface IFolderMatchContext { @@ -118,9 +120,15 @@ export interface IFolderMatchContext { matches: IFileMatchContext[]; /** resource that might be associate with this match */ resource: URI | null; + renderableMatch: FolderMatch; } -export type IRenderableMatchContext = IMatchContext | IFileMatchContext | IFolderMatchContext; +export interface IFolderMatchWithResourceContext extends IFolderMatchContext { + resource: URI; + renderableMatch: FolderMatchWithResource; +} + +export type IRenderableMatchContext = (IMatchContext | IFileMatchContext | IFolderMatchContext); function toMatchContext(match: Match): IMatchContext { return { @@ -129,7 +137,8 @@ function toMatchContext(match: Match): IMatchContext { uri: URI.parse(match.parent().id()), matchedText: match.fullMatchText(), replacementText: match.replaceString, - matchRange: match.range() + matchRange: match.range(), + renderableMatch: match } as IMatchContext; } @@ -137,7 +146,8 @@ function toFileMatchContext(fileMatch: FileMatch): IFileMatchContext { return { matchingKind: 'fileMatch', uri: URI.parse(fileMatch.id()), - matches: fileMatch.matches().map(toMatchContext) + matches: fileMatch.matches().map(toMatchContext), + renderableMatch: fileMatch } as IFileMatchContext; } @@ -145,7 +155,8 @@ function toFolderMatchContext(folderMatch: Folder return { matchingKind: 'folderMatch', matches: folderMatch.matches().map(toFileMatchContext), - id: folderMatch.id() + id: folderMatch.id(), + renderableMatch: folderMatch } as T; } diff --git a/src/vs/workbench/contrib/search/common/searchModel.ts b/src/vs/workbench/contrib/search/common/searchModel.ts index 0c6e0d19457..556d3d83b36 100644 --- a/src/vs/workbench/contrib/search/common/searchModel.ts +++ b/src/vs/workbench/contrib/search/common/searchModel.ts @@ -157,6 +157,10 @@ export class Match { getMatchString(): string { return this._oneLinePreviewText.substring(this._rangeInPreviewText.startColumn - 1, this._rangeInPreviewText.endColumn - 1); } + + toJSON(): object { + return {}; // We send an IRenderableMatchContext to the extensions + } } export class FileMatch extends Disposable implements IFileMatch { @@ -444,6 +448,10 @@ export class FileMatch extends Disposable implements IFileMatch { this._onDispose.fire(); super.dispose(); } + + toJSON(): object { + return {}; // We send an IRenderableMatchContext to the extensions + } } export interface IChangeEvent { @@ -634,6 +642,10 @@ export class FolderMatch extends Disposable { this._onDispose.fire(); super.dispose(); } + + toJSON(): object { + return {}; // We send an IRenderableMatchContext to the extensions + } } /** diff --git a/src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts b/src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts index ff6d95047f9..1b4bf9b654e 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts @@ -23,6 +23,7 @@ import { mock } from 'vs/base/test/common/mock'; import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService'; import { TextSearchManager } from 'vs/workbench/services/search/common/textSearchManager'; import { NativeTextSearchManager } from 'vs/workbench/services/search/node/textSearchManager'; +import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands'; let rpcProtocol: TestRPCProtocol; let extHostSearch: NativeExtHostSearch; @@ -146,7 +147,8 @@ suite('ExtHostSearch', () => { rpcProtocol, new class extends mock() { remote = { isRemote: false, authority: undefined, connectionData: null }; }, new URITransformerService(null), - logService + logService, + new ExtHostCommands(rpcProtocol, new NullLogService()) ); this._pfs = mockPFS as any; }