mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 10:12:34 -05:00
Merge from vscode 777931080477e28b7c27e8f7d4b0d69897945946 (#9220)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { DefaultEndOfLine, IIdentifiedSingleEditOperation, ITextBuffer, ITextBufferBuilder } from 'vs/editor/common/model';
|
||||
import { DefaultEndOfLine, ITextBuffer, ITextBufferBuilder, ValidAnnotatedEditOperation } from 'vs/editor/common/model';
|
||||
|
||||
export function getRandomInt(min: number, max: number): number {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
@@ -31,7 +31,7 @@ export function getRandomString(minLength: number, maxLength: number): string {
|
||||
return r;
|
||||
}
|
||||
|
||||
export function generateRandomEdits(chunks: string[], editCnt: number): IIdentifiedSingleEditOperation[] {
|
||||
export function generateRandomEdits(chunks: string[], editCnt: number): ValidAnnotatedEditOperation[] {
|
||||
let lines: string[] = [];
|
||||
for (const chunk of chunks) {
|
||||
let newLines = chunk.split(/\r\n|\r|\n/);
|
||||
@@ -43,7 +43,7 @@ export function generateRandomEdits(chunks: string[], editCnt: number): IIdentif
|
||||
}
|
||||
}
|
||||
|
||||
let ops: IIdentifiedSingleEditOperation[] = [];
|
||||
let ops: ValidAnnotatedEditOperation[] = [];
|
||||
|
||||
for (let i = 0; i < editCnt; i++) {
|
||||
let line = getRandomInt(1, lines.length);
|
||||
@@ -54,17 +54,14 @@ export function generateRandomEdits(chunks: string[], editCnt: number): IIdentif
|
||||
text = getRandomString(5, 10);
|
||||
}
|
||||
|
||||
ops.push({
|
||||
text: text,
|
||||
range: new Range(line, startColumn, line, endColumn)
|
||||
});
|
||||
ops.push(new ValidAnnotatedEditOperation(null, new Range(line, startColumn, line, endColumn), text, false, false, false));
|
||||
lines[line - 1] = lines[line - 1].substring(0, startColumn - 1) + text + lines[line - 1].substring(endColumn - 1);
|
||||
}
|
||||
|
||||
return ops;
|
||||
}
|
||||
|
||||
export function generateSequentialInserts(chunks: string[], editCnt: number): IIdentifiedSingleEditOperation[] {
|
||||
export function generateSequentialInserts(chunks: string[], editCnt: number): ValidAnnotatedEditOperation[] {
|
||||
let lines: string[] = [];
|
||||
for (const chunk of chunks) {
|
||||
let newLines = chunk.split(/\r\n|\r|\n/);
|
||||
@@ -76,7 +73,7 @@ export function generateSequentialInserts(chunks: string[], editCnt: number): II
|
||||
}
|
||||
}
|
||||
|
||||
let ops: IIdentifiedSingleEditOperation[] = [];
|
||||
let ops: ValidAnnotatedEditOperation[] = [];
|
||||
|
||||
for (let i = 0; i < editCnt; i++) {
|
||||
let line = lines.length;
|
||||
@@ -90,16 +87,13 @@ export function generateSequentialInserts(chunks: string[], editCnt: number): II
|
||||
lines[line - 1] += text;
|
||||
}
|
||||
|
||||
ops.push({
|
||||
text: text,
|
||||
range: new Range(line, column, line, column)
|
||||
});
|
||||
ops.push(new ValidAnnotatedEditOperation(null, new Range(line, column, line, column), text, false, false, false));
|
||||
}
|
||||
|
||||
return ops;
|
||||
}
|
||||
|
||||
export function generateRandomReplaces(chunks: string[], editCnt: number, searchStringLen: number, replaceStringLen: number): IIdentifiedSingleEditOperation[] {
|
||||
export function generateRandomReplaces(chunks: string[], editCnt: number, searchStringLen: number, replaceStringLen: number): ValidAnnotatedEditOperation[] {
|
||||
let lines: string[] = [];
|
||||
for (const chunk of chunks) {
|
||||
let newLines = chunk.split(/\r\n|\r|\n/);
|
||||
@@ -111,7 +105,7 @@ export function generateRandomReplaces(chunks: string[], editCnt: number, search
|
||||
}
|
||||
}
|
||||
|
||||
let ops: IIdentifiedSingleEditOperation[] = [];
|
||||
let ops: ValidAnnotatedEditOperation[] = [];
|
||||
let chunkSize = Math.max(1, Math.floor(lines.length / editCnt));
|
||||
let chunkCnt = Math.floor(lines.length / chunkSize);
|
||||
let replaceString = getRandomString(replaceStringLen, replaceStringLen);
|
||||
@@ -125,10 +119,7 @@ export function generateRandomReplaces(chunks: string[], editCnt: number, search
|
||||
let startColumn = getRandomInt(1, maxColumn);
|
||||
let endColumn = Math.min(maxColumn, startColumn + searchStringLen);
|
||||
|
||||
ops.push({
|
||||
text: replaceString,
|
||||
range: new Range(line, startColumn, line, endColumn)
|
||||
});
|
||||
ops.push(new ValidAnnotatedEditOperation(null, new Range(line, startColumn, line, endColumn), replaceString, false, false, false));
|
||||
previousChunksLength = endLine;
|
||||
}
|
||||
|
||||
@@ -166,4 +157,4 @@ export function generateRandomChunkWithLF(minLength: number, maxLength: number):
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user