Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)

* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
This commit is contained in:
Anthony Dresser
2019-07-15 22:35:46 -07:00
committed by GitHub
parent f720ec642f
commit 0b7e7ddbf9
2406 changed files with 59140 additions and 35464 deletions

View File

@@ -110,7 +110,9 @@ suite('ModelLinesTokens', () => {
for (let lineIndex = 0; lineIndex < initial.length; lineIndex++) {
const lineTokens = initial[lineIndex].tokens;
const lineTextLength = model.getLineMaxColumn(lineIndex + 1) - 1;
model._tokens._setTokens(0, lineIndex, lineTextLength, TestToken.toTokens(lineTokens));
const tokens = TestToken.toTokens(lineTokens);
LineTokens.convertToEndOffset(tokens, lineTextLength);
model.setLineTokens(lineIndex + 1, tokens);
}
model.applyEdits(edits.map((ed) => ({
@@ -441,14 +443,16 @@ suite('ModelLinesTokens', () => {
test('insertion on empty line', () => {
const model = new TextModel('some text', TextModel.DEFAULT_CREATION_OPTIONS, new LanguageIdentifier('test', 0));
model._tokens._setTokens(0, 0, model.getLineMaxColumn(1) - 1, TestToken.toTokens([new TestToken(0, 1)]));
const tokens = TestToken.toTokens([new TestToken(0, 1)]);
LineTokens.convertToEndOffset(tokens, model.getLineMaxColumn(1) - 1);
model.setLineTokens(1, tokens);
model.applyEdits([{
range: new Range(1, 1, 1, 10),
text: ''
}]);
model._tokens._setTokens(0, 0, model.getLineMaxColumn(1) - 1, new Uint32Array(0));
model.setLineTokens(1, new Uint32Array(0));
model.applyEdits([{
range: new Range(1, 1, 1, 1),
@@ -660,7 +664,7 @@ suite('ModelLinesTokens', () => {
test('updates tokens on insertion 10', () => {
testLineEditTokens(
'',
null!,
[],
[{
startColumn: 1,
endColumn: 1,

View File

@@ -29,7 +29,7 @@ suite('Editor Model - Model Modes 1', () => {
tokenize: undefined!,
tokenize2: (line: string, state: modes.IState): TokenizationResult2 => {
calledFor.push(line.charAt(0));
return new TokenizationResult2(null!, state);
return new TokenizationResult2(new Uint32Array(0), state);
}
};
@@ -170,37 +170,23 @@ suite('Editor Model - Model Modes 2', () => {
}
}
let calledFor: string[] = [];
function checkAndClear(arr: string[]): void {
assert.deepEqual(calledFor, arr);
calledFor = [];
}
const tokenizationSupport: modes.ITokenizationSupport = {
getInitialState: () => new ModelState2(''),
tokenize: undefined!,
tokenize2: (line: string, state: modes.IState): TokenizationResult2 => {
calledFor.push(line);
(<ModelState2>state).prevLineContent = line;
return new TokenizationResult2(null!, state);
return new TokenizationResult2(new Uint32Array(0), state);
}
};
function invalidEqual(model: TextModel, expected: number[]): void {
let actual: number[] = [];
for (let i = 0, len = model.getLineCount(); i < len; i++) {
if (model._tokens._isInvalid(i)) {
actual.push(i);
}
}
assert.deepEqual(actual, expected);
}
function stateEqual(state: modes.IState, content: string): void {
assert.equal((<ModelState2>state).prevLineContent, content);
}
function statesEqual(model: TextModel, states: string[]): void {
let i, len = states.length - 1;
for (i = 0; i < len; i++) {
stateEqual(model._tokens._getState(i)!, states[i]);
}
stateEqual((<any>model)._tokens._lastState, states[len]);
}
let thisModel: TextModel;
let languageRegistration: IDisposable;
@@ -223,64 +209,54 @@ suite('Editor Model - Model Modes 2', () => {
test('getTokensForInvalidLines one text insert', () => {
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
thisModel.applyEdits([EditOperation.insert(new Position(1, 6), '-')]);
invalidEqual(thisModel, [0]);
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', 'Line1-', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['Line1-', 'Line2']);
});
test('getTokensForInvalidLines two text insert', () => {
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
thisModel.applyEdits([
EditOperation.insert(new Position(1, 6), '-'),
EditOperation.insert(new Position(3, 6), '-')
]);
invalidEqual(thisModel, [0, 2]);
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', 'Line1-', 'Line2', 'Line3-', 'Line4', 'Line5']);
checkAndClear(['Line1-', 'Line2', 'Line3-', 'Line4']);
});
test('getTokensForInvalidLines one multi-line text insert, one small text insert', () => {
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
thisModel.applyEdits([EditOperation.insert(new Position(1, 6), '\nNew line\nAnother new line')]);
invalidEqual(thisModel, [0, 1, 2]);
thisModel.applyEdits([EditOperation.insert(new Position(5, 6), '-')]);
invalidEqual(thisModel, [0, 1, 2, 4]);
thisModel.forceTokenization(7);
statesEqual(thisModel, ['', 'Line1', 'New line', 'Another new line', 'Line2', 'Line3-', 'Line4', 'Line5']);
checkAndClear(['Line1', 'New line', 'Another new line', 'Line2', 'Line3-', 'Line4']);
});
test('getTokensForInvalidLines one delete text', () => {
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
thisModel.applyEdits([EditOperation.delete(new Range(1, 1, 1, 5))]);
invalidEqual(thisModel, [0]);
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', '1', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['1', 'Line2']);
});
test('getTokensForInvalidLines one line delete text', () => {
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
thisModel.applyEdits([EditOperation.delete(new Range(1, 1, 2, 1))]);
invalidEqual(thisModel, [0]);
statesEqual(thisModel, ['', 'Line2', 'Line3', 'Line4', 'Line5']);
thisModel.forceTokenization(4);
statesEqual(thisModel, ['', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['Line2']);
});
test('getTokensForInvalidLines multiple lines delete text', () => {
thisModel.forceTokenization(5);
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
thisModel.applyEdits([EditOperation.delete(new Range(1, 1, 3, 3))]);
invalidEqual(thisModel, [0]);
statesEqual(thisModel, ['', 'Line3', 'Line4', 'Line5']);
thisModel.forceTokenization(3);
statesEqual(thisModel, ['', 'ne3', 'Line4', 'Line5']);
checkAndClear(['ne3', 'Line4']);
});
});

View File

@@ -26,17 +26,21 @@ function testGuessIndentation(defaultInsertSpaces: boolean, defaultTabSize: numb
assert.equal(r.tabSize, expectedTabSize, msg);
}
function assertGuess(expectedInsertSpaces: boolean | undefined, expectedTabSize: number | undefined, text: string[], msg?: string): void {
function assertGuess(expectedInsertSpaces: boolean | undefined, expectedTabSize: number | undefined | [number], text: string[], msg?: string): void {
if (typeof expectedInsertSpaces === 'undefined') {
// cannot guess insertSpaces
if (typeof expectedTabSize === 'undefined') {
// cannot guess tabSize
testGuessIndentation(true, 13370, true, 13370, text, msg);
testGuessIndentation(false, 13371, false, 13371, text, msg);
} else {
} else if (typeof expectedTabSize === 'number') {
// can guess tabSize
testGuessIndentation(true, 13370, true, expectedTabSize, text, msg);
testGuessIndentation(false, 13371, false, expectedTabSize, text, msg);
} else {
// can only guess tabSize when insertSpaces is true
testGuessIndentation(true, 13370, true, expectedTabSize[0], text, msg);
testGuessIndentation(false, 13371, false, 13371, text, msg);
}
} else {
// can guess insertSpaces
@@ -44,10 +48,19 @@ function assertGuess(expectedInsertSpaces: boolean | undefined, expectedTabSize:
// cannot guess tabSize
testGuessIndentation(true, 13370, expectedInsertSpaces, 13370, text, msg);
testGuessIndentation(false, 13371, expectedInsertSpaces, 13371, text, msg);
} else {
} else if (typeof expectedTabSize === 'number') {
// can guess tabSize
testGuessIndentation(true, 13370, expectedInsertSpaces, expectedTabSize, text, msg);
testGuessIndentation(false, 13371, expectedInsertSpaces, expectedTabSize, text, msg);
} else {
// can only guess tabSize when insertSpaces is true
if (expectedInsertSpaces === true) {
testGuessIndentation(true, 13370, expectedInsertSpaces, expectedTabSize[0], text, msg);
testGuessIndentation(false, 13371, expectedInsertSpaces, expectedTabSize[0], text, msg);
} else {
testGuessIndentation(true, 13370, expectedInsertSpaces, 13370, text, msg);
testGuessIndentation(false, 13371, expectedInsertSpaces, 13371, text, msg);
}
}
}
}
@@ -219,7 +232,7 @@ suite('Editor Model - TextModel', () => {
'\tx'
], '7xTAB');
assertGuess(undefined, 2, [
assertGuess(undefined, [2], [
'\tx',
' x',
'\tx',
@@ -239,7 +252,7 @@ suite('Editor Model - TextModel', () => {
'\tx',
' x'
], '4x1, 4xTAB');
assertGuess(false, 2, [
assertGuess(false, undefined, [
'\tx',
'\tx',
' x',
@@ -250,7 +263,7 @@ suite('Editor Model - TextModel', () => {
'\tx',
' x',
], '4x2, 5xTAB');
assertGuess(false, 2, [
assertGuess(false, undefined, [
'\tx',
'\tx',
'x',
@@ -261,7 +274,7 @@ suite('Editor Model - TextModel', () => {
'\tx',
' x',
], '1x2, 5xTAB');
assertGuess(false, 4, [
assertGuess(false, undefined, [
'\tx',
'\tx',
'x',
@@ -272,7 +285,7 @@ suite('Editor Model - TextModel', () => {
'\tx',
' x',
], '1x4, 5xTAB');
assertGuess(false, 2, [
assertGuess(false, undefined, [
'\tx',
'\tx',
'x',
@@ -524,7 +537,7 @@ suite('Editor Model - TextModel', () => {
' \t x',
'\tx'
], 'mixed whitespace 1');
assertGuess(false, 4, [
assertGuess(false, undefined, [
'\tx',
'\t x'
], 'mixed whitespace 2');
@@ -575,6 +588,26 @@ suite('Editor Model - TextModel', () => {
]);
});
test('issue #70832: Broken indentation detection', () => {
assertGuess(false, undefined, [
'x',
'x',
'x',
'x',
' x',
' x',
' x',
' x',
' x',
' x',
' x',
' x',
' x',
' x',
'x',
]);
});
test('validatePosition', () => {
let m = TextModel.createFromString('line one\nline two');