mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Merge branch 'scm-input-validation-provider'
This commit is contained in:
@@ -602,6 +602,7 @@ export function createApiFactory(
|
||||
StatusBarAlignment: extHostTypes.StatusBarAlignment,
|
||||
SymbolInformation: extHostTypes.SymbolInformation,
|
||||
SymbolKind: extHostTypes.SymbolKind,
|
||||
SourceControlInputBoxValidationType: extHostTypes.SourceControlInputBoxValidationType,
|
||||
TextDocumentSaveReason: extHostTypes.TextDocumentSaveReason,
|
||||
TextEdit: extHostTypes.TextEdit,
|
||||
TextEditorCursorStyle: TextEditorCursorStyle,
|
||||
|
||||
@@ -431,7 +431,7 @@ export interface MainThreadSCMShape extends IDisposable {
|
||||
|
||||
$setInputBoxValue(sourceControlHandle: number, value: string): void;
|
||||
$setInputBoxPlaceholder(sourceControlHandle: number, placeholder: string): void;
|
||||
$setLineWarningLength(sourceControlHandle: number, lineWarningLength: number): void;
|
||||
$setValidationProviderIsEnabled(sourceControlHandle: number, enabled: boolean): void;
|
||||
}
|
||||
|
||||
export type DebugSessionUUID = string;
|
||||
@@ -694,6 +694,7 @@ export interface ExtHostSCMShape {
|
||||
$provideOriginalResource(sourceControlHandle: number, uri: string): TPromise<string>;
|
||||
$onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise<void>;
|
||||
$executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void>;
|
||||
$validateInput(sourceControlHandle: number, value: string, cursorPosition: number): TPromise<[string, number] | undefined>;
|
||||
}
|
||||
|
||||
export interface ExtHostTaskShape {
|
||||
|
||||
@@ -110,6 +110,10 @@ function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.S
|
||||
return result;
|
||||
}
|
||||
|
||||
export interface IValidateInput {
|
||||
(value: string, cursorPosition: number): vscode.ProviderResult<vscode.SourceControlInputBoxValidation | undefined | null>;
|
||||
}
|
||||
|
||||
export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
|
||||
|
||||
private _value: string = '';
|
||||
@@ -140,18 +144,31 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
|
||||
this._placeholder = placeholder;
|
||||
}
|
||||
|
||||
private _lineWarningLength: number | undefined;
|
||||
private _validateInput: IValidateInput;
|
||||
|
||||
get lineWarningLength(): number | undefined {
|
||||
return this._lineWarningLength;
|
||||
get validateInput(): IValidateInput {
|
||||
if (!this._extension.enableProposedApi) {
|
||||
throw new Error(`[${this._extension.id}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${this._extension.id}`);
|
||||
}
|
||||
|
||||
return this._validateInput;
|
||||
}
|
||||
|
||||
set lineWarningLength(lineWarningLength: number) {
|
||||
this._proxy.$setLineWarningLength(this._sourceControlHandle, lineWarningLength);
|
||||
this._lineWarningLength = lineWarningLength;
|
||||
set validateInput(fn: IValidateInput) {
|
||||
if (!this._extension.enableProposedApi) {
|
||||
throw new Error(`[${this._extension.id}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${this._extension.id}`);
|
||||
}
|
||||
|
||||
if (fn && typeof fn !== 'function') {
|
||||
console.warn('Invalid SCM input box validation function');
|
||||
return;
|
||||
}
|
||||
|
||||
this._validateInput = fn;
|
||||
this._proxy.$setValidationProviderIsEnabled(this._sourceControlHandle, !!fn);
|
||||
}
|
||||
|
||||
constructor(private _proxy: MainThreadSCMShape, private _sourceControlHandle: number) {
|
||||
constructor(private _extension: IExtensionDescription, private _proxy: MainThreadSCMShape, private _sourceControlHandle: number) {
|
||||
// noop
|
||||
}
|
||||
|
||||
@@ -381,13 +398,14 @@ class ExtHostSourceControl implements vscode.SourceControl {
|
||||
private handle: number = ExtHostSourceControl._handlePool++;
|
||||
|
||||
constructor(
|
||||
_extension: IExtensionDescription,
|
||||
private _proxy: MainThreadSCMShape,
|
||||
private _commands: ExtHostCommands,
|
||||
private _id: string,
|
||||
private _label: string,
|
||||
private _rootUri?: vscode.Uri
|
||||
) {
|
||||
this._inputBox = new ExtHostSCMInputBox(this._proxy, this.handle);
|
||||
this._inputBox = new ExtHostSCMInputBox(_extension, this._proxy, this.handle);
|
||||
this._proxy.$registerSourceControl(this.handle, _id, _label, _rootUri && _rootUri.toString());
|
||||
}
|
||||
|
||||
@@ -503,7 +521,7 @@ export class ExtHostSCM implements ExtHostSCMShape {
|
||||
this.logService.trace('ExtHostSCM#createSourceControl', extension.id, id, label, rootUri);
|
||||
|
||||
const handle = ExtHostSCM._handlePool++;
|
||||
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands, id, label, rootUri);
|
||||
const sourceControl = new ExtHostSourceControl(extension, this._proxy, this._commands, id, label, rootUri);
|
||||
this._sourceControls.set(handle, sourceControl);
|
||||
|
||||
const sourceControls = this._sourceControlsByExtension.get(extension.id) || [];
|
||||
@@ -567,4 +585,26 @@ export class ExtHostSCM implements ExtHostSCMShape {
|
||||
|
||||
await group.$executeResourceCommand(handle);
|
||||
}
|
||||
|
||||
async $validateInput(sourceControlHandle: number, value: string, cursorPosition: number): TPromise<[string, number] | undefined> {
|
||||
this.logService.trace('ExtHostSCM#$validateInput', sourceControlHandle);
|
||||
|
||||
const sourceControl = this._sourceControls.get(sourceControlHandle);
|
||||
|
||||
if (!sourceControl) {
|
||||
return TPromise.as(undefined);
|
||||
}
|
||||
|
||||
if (!sourceControl.inputBox.validateInput) {
|
||||
return TPromise.as(undefined);
|
||||
}
|
||||
|
||||
const result = await sourceControl.inputBox.validateInput(value, cursorPosition);
|
||||
|
||||
if (!result) {
|
||||
return TPromise.as(undefined);
|
||||
}
|
||||
|
||||
return [result.message, result.type];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1200,6 +1200,12 @@ export enum ColorFormat {
|
||||
HSL = 2
|
||||
}
|
||||
|
||||
export enum SourceControlInputBoxValidationType {
|
||||
Error = 0,
|
||||
Warning = 1,
|
||||
Information = 2
|
||||
}
|
||||
|
||||
export enum TaskRevealKind {
|
||||
Always = 1,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user