mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 22:12:26 +01:00
Git - remove git.experimental.inputValidation setting (#205550)
* Git - remove git.experimental.inputValidation setting * Fix compilation error * Fix migration code
This commit is contained in:
@@ -21,14 +21,38 @@ export class GitCommitInputBoxDiagnosticsManager {
|
||||
constructor(private readonly model: Model) {
|
||||
this.diagnostics = languages.createDiagnosticCollection();
|
||||
|
||||
mapEvent(filterEvent(workspace.onDidChangeTextDocument, e => e.document.uri.scheme === 'vscode-scm'), e => e.document)(this.onDidChangeTextDocument, this, this.disposables);
|
||||
filterEvent(workspace.onDidChangeConfiguration, e => e.affectsConfiguration('git.experimental.inputValidation'))(this.onDidChangeConfiguration, this, this.disposables);
|
||||
this.migrateInputValidationSettings()
|
||||
.then(() => {
|
||||
mapEvent(filterEvent(workspace.onDidChangeTextDocument, e => e.document.uri.scheme === 'vscode-scm'), e => e.document)(this.onDidChangeTextDocument, this, this.disposables);
|
||||
filterEvent(workspace.onDidChangeConfiguration, e => e.affectsConfiguration('git.inputValidation'))(this.onDidChangeConfiguration, this, this.disposables);
|
||||
});
|
||||
}
|
||||
|
||||
public getDiagnostics(uri: Uri): ReadonlyArray<Diagnostic> {
|
||||
return this.diagnostics.get(uri) ?? [];
|
||||
}
|
||||
|
||||
private async migrateInputValidationSettings(): Promise<void> {
|
||||
try {
|
||||
const config = workspace.getConfiguration('git');
|
||||
const inputValidation = config.inspect<'always' | 'warn' | 'off' | boolean>('inputValidation');
|
||||
|
||||
if (inputValidation === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Workspace setting
|
||||
if (typeof inputValidation.workspaceValue === 'string') {
|
||||
await config.update('inputValidation', inputValidation.workspaceValue !== 'off', false);
|
||||
}
|
||||
|
||||
// User setting
|
||||
if (typeof inputValidation.globalValue === 'string') {
|
||||
await config.update('inputValidation', inputValidation.workspaceValue !== 'off', true);
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
private onDidChangeConfiguration(): void {
|
||||
for (const repository of this.model.repositories) {
|
||||
this.onDidChangeTextDocument(repository.inputBox.document);
|
||||
@@ -37,7 +61,7 @@ export class GitCommitInputBoxDiagnosticsManager {
|
||||
|
||||
private onDidChangeTextDocument(document: TextDocument): void {
|
||||
const config = workspace.getConfiguration('git');
|
||||
const inputValidation = config.get<boolean>('experimental.inputValidation', false) === true;
|
||||
const inputValidation = config.get<boolean>('inputValidation', false);
|
||||
if (!inputValidation) {
|
||||
this.diagnostics.set(document.uri, undefined);
|
||||
return;
|
||||
|
||||
@@ -975,10 +975,9 @@ export class Repository implements Disposable {
|
||||
this.setCountBadge();
|
||||
}
|
||||
|
||||
validateInput(text: string, position: number): SourceControlInputBoxValidation | undefined {
|
||||
let tooManyChangesWarning: SourceControlInputBoxValidation | undefined;
|
||||
validateInput(text: string, _: number): SourceControlInputBoxValidation | undefined {
|
||||
if (this.isRepositoryHuge) {
|
||||
tooManyChangesWarning = {
|
||||
return {
|
||||
message: l10n.t('Too many changes were detected. Only the first {0} changes will be shown below.', this.isRepositoryHuge.limit),
|
||||
type: SourceControlInputBoxValidationType.Warning
|
||||
};
|
||||
@@ -993,59 +992,7 @@ export class Repository implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
const config = workspace.getConfiguration('git');
|
||||
const setting = config.get<'always' | 'warn' | 'off'>('inputValidation');
|
||||
|
||||
if (setting === 'off') {
|
||||
return tooManyChangesWarning;
|
||||
}
|
||||
|
||||
if (/^\s+$/.test(text)) {
|
||||
return {
|
||||
message: l10n.t('Current commit message only contains whitespace characters'),
|
||||
type: SourceControlInputBoxValidationType.Warning
|
||||
};
|
||||
}
|
||||
|
||||
let lineNumber = 0;
|
||||
let start = 0;
|
||||
let match: RegExpExecArray | null;
|
||||
const regex = /\r?\n/g;
|
||||
|
||||
while ((match = regex.exec(text)) && position > match.index) {
|
||||
start = match.index + match[0].length;
|
||||
lineNumber++;
|
||||
}
|
||||
|
||||
const end = match ? match.index : text.length;
|
||||
|
||||
const line = text.substring(start, end);
|
||||
|
||||
let threshold = config.get<number>('inputValidationLength', 50);
|
||||
|
||||
if (lineNumber === 0) {
|
||||
const inputValidationSubjectLength = config.get<number | null>('inputValidationSubjectLength', null);
|
||||
|
||||
if (inputValidationSubjectLength !== null) {
|
||||
threshold = inputValidationSubjectLength;
|
||||
}
|
||||
}
|
||||
|
||||
if (line.length <= threshold) {
|
||||
if (setting !== 'always') {
|
||||
return tooManyChangesWarning;
|
||||
}
|
||||
|
||||
return {
|
||||
message: l10n.t('{0} characters left in current line', threshold - line.length),
|
||||
type: SourceControlInputBoxValidationType.Information
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
message: l10n.t('{0} characters over {1} in current line', line.length - threshold, threshold),
|
||||
type: SourceControlInputBoxValidationType.Warning
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user