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

SCM - Add document property to expose the text document #171504

Merged
merged 13 commits into from
Apr 14, 2023
6 changes: 4 additions & 2 deletions src/vs/workbench/api/browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
get handle(): number { return this._handle; }
get label(): string { return this._label; }
get rootUri(): URI | undefined { return this._rootUri; }
get inputBoxDocumentUri(): URI { return this._inputBoxDocumentUri; }
get contextValue(): string { return this._contextValue; }

get commitTemplate(): string { return this.features.commitTemplate || ''; }
Expand All @@ -143,6 +144,7 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
private readonly _contextValue: string,
private readonly _label: string,
private readonly _rootUri: URI | undefined,
private readonly _inputBoxDocumentUri: URI,
private readonly _quickDiffService: IQuickDiffService
) { }

Expand Down Expand Up @@ -317,8 +319,8 @@ export class MainThreadSCM implements MainThreadSCMShape {
this._disposables.dispose();
}

$registerSourceControl(handle: number, id: string, label: string, rootUri: UriComponents | undefined): void {
const provider = new MainThreadSCMProvider(this._proxy, handle, id, label, rootUri ? URI.revive(rootUri) : undefined, this.quickDiffService);
$registerSourceControl(handle: number, id: string, label: string, rootUri: UriComponents | undefined, inputBoxDocumentUri: UriComponents): void {
const provider = new MainThreadSCMProvider(this._proxy, handle, id, label, rootUri ? URI.revive(rootUri) : undefined, URI.revive(inputBoxDocumentUri), this.quickDiffService);
const repository = this.scmService.registerSCMProvider(provider);
this._repositories.set(handle, repository);

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures));
const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpcProtocol, extHostLogService, extHostDocumentsAndEditors));
const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, createExtHostQuickOpen(rpcProtocol, extHostWorkspace, extHostCommands));
const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService));
const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostDocumentsAndEditors, extHostLogService));
const extHostQuickDiff = rpcProtocol.set(ExtHostContext.ExtHostQuickDiff, new ExtHostQuickDiff(rpcProtocol, uriTransformer));
const extHostComment = rpcProtocol.set(ExtHostContext.ExtHostComments, createExtHostComments(rpcProtocol, extHostCommands, extHostDocuments));
const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ export type SCMRawResourceSplices = [
];

export interface MainThreadSCMShape extends IDisposable {
$registerSourceControl(handle: number, id: string, label: string, rootUri: UriComponents | undefined): void;
$registerSourceControl(handle: number, id: string, label: string, rootUri: UriComponents | undefined, inputBoxDocumentUri: UriComponents): void;
$updateSourceControl(handle: number, features: SCMProviderFeatures): void;
$unregisterSourceControl(handle: number): void;

Expand Down
29 changes: 25 additions & 4 deletions src/vs/workbench/api/common/extHostSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { ThemeIcon } from 'vs/base/common/themables';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { MarkdownString } from 'vs/workbench/api/common/extHostTypeConverters';
import { checkProposedApiEnabled, isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { Schemas } from 'vs/base/common/network';

type ProviderHandle = number;
type GroupHandle = number;
Expand Down Expand Up @@ -283,7 +285,18 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
this.#proxy.$setInputBoxVisibility(this._sourceControlHandle, visible);
}

constructor(private _extension: IExtensionDescription, proxy: MainThreadSCMShape, private _sourceControlHandle: number) {
get document(): vscode.TextDocument {
checkProposedApiEnabled(this._extension, 'scmTextDocument');

const data = this._extHostDocument.getDocument(this._documentUri);
if (!data) {
lszomoru marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`MISSING extHostDocument for source control input box: ${this._documentUri.toString()}`);
}

return data.document;
}

constructor(private _extension: IExtensionDescription, private _extHostDocument: ExtHostDocumentsAndEditors, proxy: MainThreadSCMShape, private _sourceControlHandle: number, private _documentUri: URI) {
this.#proxy = proxy;
}

Expand Down Expand Up @@ -584,6 +597,7 @@ class ExtHostSourceControl implements vscode.SourceControl {

constructor(
private readonly _extension: IExtensionDescription,
_extHostDocument: ExtHostDocumentsAndEditors,
proxy: MainThreadSCMShape,
private _commands: ExtHostCommands,
private _id: string,
Expand All @@ -592,8 +606,14 @@ class ExtHostSourceControl implements vscode.SourceControl {
) {
this.#proxy = proxy;

this._inputBox = new ExtHostSCMInputBox(_extension, this.#proxy, this.handle);
this.#proxy.$registerSourceControl(this.handle, _id, _label, _rootUri);
const inputBoxDocumentUri = URI.from({
scheme: Schemas.vscodeSourceControl,
path: `${_id}/scm${this.handle}/input`,
query: _rootUri ? `rootUri=${encodeURIComponent(_rootUri.toString())}` : undefined
});

this._inputBox = new ExtHostSCMInputBox(_extension, _extHostDocument, this.#proxy, this.handle, inputBoxDocumentUri);
this.#proxy.$registerSourceControl(this.handle, _id, _label, _rootUri, inputBoxDocumentUri);
}

private createdResourceGroups = new Map<ExtHostSourceControlResourceGroup, IDisposable>();
Expand Down Expand Up @@ -699,6 +719,7 @@ export class ExtHostSCM implements ExtHostSCMShape {
constructor(
mainContext: IMainContext,
private _commands: ExtHostCommands,
private _extHostDocument: ExtHostDocumentsAndEditors,
@ILogService private readonly logService: ILogService
) {
this._proxy = mainContext.getProxy(MainContext.MainThreadSCM);
Expand Down Expand Up @@ -757,7 +778,7 @@ export class ExtHostSCM implements ExtHostSCMShape {
});

const handle = ExtHostSCM._handlePool++;
const sourceControl = new ExtHostSourceControl(extension, this._proxy, this._commands, id, label, rootUri);
const sourceControl = new ExtHostSourceControl(extension, this._extHostDocument, this._proxy, this._commands, id, label, rootUri);
this._sourceControls.set(handle, sourceControl);

const sourceControls = this._sourceControlsByExtension.get(extension.identifier) || [];
Expand Down
15 changes: 2 additions & 13 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import * as platform from 'vs/base/common/platform';
import { compare, format } from 'vs/base/common/strings';
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController';
import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2';
import { Schemas } from 'vs/base/common/network';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ModesHoverController } from 'vs/editor/contrib/hover/browser/hover';
import { ColorDetector } from 'vs/editor/contrib/colorPicker/browser/colorDetector';
Expand Down Expand Up @@ -92,6 +91,7 @@ import { defaultButtonStyles, defaultCountBadgeStyles } from 'vs/platform/theme/
import { GhostTextController } from 'vs/editor/contrib/inlineCompletions/browser/ghostTextController';
import { CodeActionController } from 'vs/editor/contrib/codeAction/browser/codeActionController';
import { IResolvedTextEditorModel, ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
import { Schemas } from 'vs/base/common/network';

type TreeElement = ISCMRepository | ISCMInput | ISCMActionButton | ISCMResourceGroup | IResourceNode<ISCMResource, ISCMResourceGroup> | ISCMResource;

Expand Down Expand Up @@ -1763,18 +1763,7 @@ class SCMInputWidget {
return;
}

let query: string | undefined;

if (input.repository.provider.rootUri) {
query = `rootUri=${encodeURIComponent(input.repository.provider.rootUri.toString())}`;
}

const uri = URI.from({
scheme: Schemas.vscodeSourceControl,
path: `${input.repository.provider.contextValue}/${input.repository.provider.id}/input`,
query
});

const uri = input.repository.provider.inputBoxDocumentUri;
if (this.configurationService.getValue('editor.wordBasedSuggestions', { resource: uri }) !== false) {
this.configurationService.updateValue('editor.wordBasedSuggestions', false, { resource: uri }, ConfigurationTarget.MEMORY);
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/scm/common/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface ISCMProvider extends IDisposable {
readonly onDidChangeResources: Event<void>;

readonly rootUri?: URI;
readonly inputBoxDocumentUri: URI;
readonly count?: number;
readonly commitTemplate: string;
readonly onDidChangeCommitTemplate: Event<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const allApiProposals = Object.freeze({
resolvers: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.resolvers.d.ts',
scmActionButton: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmActionButton.d.ts',
scmSelectedProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts',
scmTextDocument: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmTextDocument.d.ts',
scmValidation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmValidation.d.ts',
showLocal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.showLocal.d.ts',
tabInputTextMerge: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts',
Expand Down
19 changes: 19 additions & 0 deletions src/vscode-dts/vscode.proposed.scmTextDocument.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* 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/166615

/**
* Represents the input box in the Source Control viewlet.
*/
export interface SourceControlInputBox {

/**
* The {@link TextDocument text} of the input box.
*/
readonly document: TextDocument;
}
}