Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -26,12 +26,12 @@ export class BlockCommentCommand implements editorCommon.ICommand {
if (offset < 0) {
return false;
}
var needleLength = needle.length;
var haystackLength = haystack.length;
const needleLength = needle.length;
const haystackLength = haystack.length;
if (offset + needleLength > haystackLength) {
return false;
}
for (var i = 0; i < needleLength; i++) {
for (let i = 0; i < needleLength; i++) {
if (haystack.charCodeAt(offset + i) !== needle.charCodeAt(i)) {
return false;
}
@@ -40,51 +40,75 @@ export class BlockCommentCommand implements editorCommon.ICommand {
}
private _createOperationsForBlockComment(selection: Range, config: ICommentsConfiguration, model: editorCommon.ITokenizedModel, builder: editorCommon.IEditOperationBuilder): void {
var startLineNumber = selection.startLineNumber;
var startColumn = selection.startColumn;
var endLineNumber = selection.endLineNumber;
var endColumn = selection.endColumn;
const startLineNumber = selection.startLineNumber;
const startColumn = selection.startColumn;
const endLineNumber = selection.endLineNumber;
const endColumn = selection.endColumn;
var startToken = config.blockCommentStartToken;
var endToken = config.blockCommentEndToken;
const startLineText = model.getLineContent(startLineNumber);
const endLineText = model.getLineContent(endLineNumber);
var startTokenIndex = model.getLineContent(startLineNumber).lastIndexOf(startToken, startColumn - 1 + startToken.length);
var endTokenIndex = model.getLineContent(endLineNumber).indexOf(endToken, endColumn - 1 - endToken.length);
let startToken = config.blockCommentStartToken;
let endToken = config.blockCommentEndToken;
var ops: editorCommon.IIdentifiedSingleEditOperation[];
let startTokenIndex = startLineText.lastIndexOf(startToken, startColumn - 1 + startToken.length);
let endTokenIndex = endLineText.indexOf(endToken, endColumn - 1 - endToken.length);
if (startTokenIndex !== -1 && endTokenIndex !== -1) {
var endTokenBeforeCursorIndex = model.getLineContent(startLineNumber).lastIndexOf(endToken, startColumn - 1 + endToken.length);
if (endTokenBeforeCursorIndex > startTokenIndex + startToken.length - 1) {
ops = BlockCommentCommand._createAddBlockCommentOperations(selection, startToken, endToken);
this._usedEndToken = ops.length === 1 ? endToken : null;
} else {
// We have to adjust to possible inner white space
// For Space after startToken, add Space to startToken - range math will work out
if (model.getLineContent(startLineNumber).charCodeAt(startTokenIndex + startToken.length) === CharCode.Space) {
startToken += ' ';
if (startLineNumber === endLineNumber) {
const lineBetweenTokens = startLineText.substring(startTokenIndex + startToken.length, endTokenIndex);
if (lineBetweenTokens.indexOf(endToken) >= 0) {
// force to add a block comment
startTokenIndex = -1;
endTokenIndex = -1;
}
// For Space before endToken, add Space before endToken and shift index one left
if (model.getLineContent(endLineNumber).charCodeAt(endTokenIndex - 1) === CharCode.Space) {
} else {
const startLineAfterStartToken = startLineText.substring(startTokenIndex + startToken.length);
const endLineBeforeEndToken = endLineText.substring(0, endTokenIndex);
if (startLineAfterStartToken.indexOf(endToken) >= 0 || endLineBeforeEndToken.indexOf(endToken) >= 0) {
// force to add a block comment
startTokenIndex = -1;
endTokenIndex = -1;
}
}
}
let ops: editorCommon.IIdentifiedSingleEditOperation[];
if (startTokenIndex !== -1 && endTokenIndex !== -1) {
// Consider spaces as part of the comment tokens
if (startTokenIndex + startToken.length < startLineText.length) {
if (startLineText.charCodeAt(startTokenIndex + startToken.length) === CharCode.Space) {
// Pretend the start token contains a trailing space
startToken = startToken + ' ';
}
}
if (endTokenIndex > 0) {
if (endLineText.charCodeAt(endTokenIndex - 1) === CharCode.Space) {
// Pretend the end token contains a leading space
endToken = ' ' + endToken;
endTokenIndex -= 1;
}
ops = BlockCommentCommand._createRemoveBlockCommentOperations(
new Range(startLineNumber, startTokenIndex + 1 + startToken.length, endLineNumber, endTokenIndex + 1), startToken, endToken
);
}
ops = BlockCommentCommand._createRemoveBlockCommentOperations(
new Range(startLineNumber, startTokenIndex + startToken.length + 1, endLineNumber, endTokenIndex + 1), startToken, endToken
);
} else {
ops = BlockCommentCommand._createAddBlockCommentOperations(selection, startToken, endToken);
this._usedEndToken = ops.length === 1 ? endToken : null;
}
for (var i = 0; i < ops.length; i++) {
for (let i = 0; i < ops.length; i++) {
builder.addTrackedEditOperation(ops[i].range, ops[i].text);
}
}
public static _createRemoveBlockCommentOperations(r: Range, startToken: string, endToken: string): editorCommon.IIdentifiedSingleEditOperation[] {
var res: editorCommon.IIdentifiedSingleEditOperation[] = [];
let res: editorCommon.IIdentifiedSingleEditOperation[] = [];
if (!Range.isEmpty(r)) {
// Remove block comment start
@@ -110,7 +134,7 @@ export class BlockCommentCommand implements editorCommon.ICommand {
}
public static _createAddBlockCommentOperations(r: Range, startToken: string, endToken: string): editorCommon.IIdentifiedSingleEditOperation[] {
var res: editorCommon.IIdentifiedSingleEditOperation[] = [];
let res: editorCommon.IIdentifiedSingleEditOperation[] = [];
if (!Range.isEmpty(r)) {
// Insert block comment start
@@ -130,29 +154,27 @@ export class BlockCommentCommand implements editorCommon.ICommand {
}
public getEditOperations(model: editorCommon.ITokenizedModel, builder: editorCommon.IEditOperationBuilder): void {
var startLineNumber = this._selection.startLineNumber;
var startColumn = this._selection.startColumn;
var endLineNumber = this._selection.endLineNumber;
var endColumn = this._selection.endColumn;
const startLineNumber = this._selection.startLineNumber;
const startColumn = this._selection.startColumn;
model.tokenizeIfCheap(startLineNumber);
let languageId = model.getLanguageIdAtPosition(startLineNumber, startColumn);
let config = LanguageConfigurationRegistry.getComments(languageId);
const languageId = model.getLanguageIdAtPosition(startLineNumber, startColumn);
const config = LanguageConfigurationRegistry.getComments(languageId);
if (!config || !config.blockCommentStartToken || !config.blockCommentEndToken) {
// Mode does not support block comments
return;
}
this._createOperationsForBlockComment(
new Range(startLineNumber, startColumn, endLineNumber, endColumn), config, model, builder
this._selection, config, model, builder
);
}
public computeCursorState(model: editorCommon.ITokenizedModel, helper: editorCommon.ICursorStateComputerData): Selection {
var inverseEditOperations = helper.getInverseEditOperations();
const inverseEditOperations = helper.getInverseEditOperations();
if (inverseEditOperations.length === 2) {
var startTokenEditOperation = inverseEditOperations[0];
var endTokenEditOperation = inverseEditOperations[1];
const startTokenEditOperation = inverseEditOperations[0];
const endTokenEditOperation = inverseEditOperations[1];
return new Selection(
startTokenEditOperation.range.endLineNumber,
@@ -161,8 +183,8 @@ export class BlockCommentCommand implements editorCommon.ICommand {
endTokenEditOperation.range.startColumn
);
} else {
var srcRange = inverseEditOperations[0].range;
var deltaColumn = this._usedEndToken ? -this._usedEndToken.length - 1 : 0; // minus 1 space before endToken
const srcRange = inverseEditOperations[0].range;
const deltaColumn = this._usedEndToken ? -this._usedEndToken.length - 1 : 0; // minus 1 space before endToken
return new Selection(
srcRange.endLineNumber,
srcRange.endColumn + deltaColumn,

View File

@@ -200,12 +200,15 @@ export class LineCommentCommand implements editorCommon.ICommand {
ops = LineCommentCommand._createAddLineCommentsOperations(data.lines, s.startLineNumber);
}
var cursorPosition = new Position(s.positionLineNumber, s.positionColumn);
const cursorPosition = new Position(s.positionLineNumber, s.positionColumn);
for (var i = 0, len = ops.length; i < len; i++) {
builder.addEditOperation(ops[i].range, ops[i].text);
if (ops[i].range.isEmpty() && ops[i].range.getStartPosition().equals(cursorPosition)) {
this._deltaColumn = ops[i].text.length;
const lineContent = model.getLineContent(cursorPosition.lineNumber);
if (lineContent.length + 1 === cursorPosition.column) {
this._deltaColumn = ops[i].text.length;
}
}
}
@@ -267,7 +270,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
*/
private _executeBlockComment(model: editorCommon.ITokenizedModel, builder: editorCommon.IEditOperationBuilder, s: Selection): void {
model.tokenizeIfCheap(s.startLineNumber);
let languageId = model.getLanguageIdAtPosition(s.startLineNumber, s.startColumn);
let languageId = model.getLanguageIdAtPosition(s.startLineNumber, 1);
let config = LanguageConfigurationRegistry.getComments(languageId);
if (!config || !config.blockCommentStartToken || !config.blockCommentEndToken) {
// Mode does not support block comments

View File

@@ -457,4 +457,17 @@ suite('Editor Contrib - Block Comment Command', () => {
new Selection(1, 16, 1, 22)
);
});
test('issue #34618', function () {
testBlockCommentCommand(
[
'<0 0> middle end',
],
new Selection(1, 4, 1, 4),
[
' middle end'
],
new Selection(1, 1, 1, 1)
);
});
});

View File

@@ -41,7 +41,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'!@# some text',
'\tsome more text'
],
new Selection(1, 9, 1, 9)
new Selection(1, 5, 1, 5)
);
});
@@ -335,7 +335,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'!@# first!@#',
'\tsecond line'
],
new Selection(1, 9, 1, 9)
new Selection(1, 5, 1, 5)
);
});
@@ -371,7 +371,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'fourth line',
'fifth'
],
new Selection(1, 9, 2, 5)
new Selection(1, 5, 2, 1)
);
});
@@ -392,7 +392,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'fourth line',
'fifth'
],
new Selection(1, 9, 2, 12)
new Selection(1, 5, 2, 8)
);
});
@@ -413,7 +413,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'!@# fourth line',
'fifth'
],
new Selection(3, 9, 4, 12)
new Selection(3, 5, 4, 8)
);
});
@@ -434,7 +434,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'fourth line',
'fifth'
],
new Selection(1, 9, 1, 9)
new Selection(1, 5, 1, 5)
);
testLineCommentCommand(
@@ -474,7 +474,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'fourth line',
'fifth'
],
new Selection(1, 9, 2, 12)
new Selection(1, 5, 2, 8)
);
testLineCommentCommand(
@@ -497,6 +497,71 @@ suite('Editor Contrib - Line Comment Command', () => {
);
});
test('issue #5964: Ctrl+/ to create comment when cursor is at the beginning of the line puts the cursor in a strange position', () => {
testLineCommentCommand(
[
'first',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(1, 1, 1, 1),
[
'!@# first',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(1, 5, 1, 5)
);
});
test('issue #35673: Comment hotkeys throws the cursor before the comment', () => {
testLineCommentCommand(
[
'first',
'',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(2, 1, 2, 1),
[
'first',
'!@# ',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(2, 5, 2, 5)
);
testLineCommentCommand(
[
'first',
'\t',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(2, 2, 2, 2),
[
'first',
'\t!@# ',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(2, 6, 2, 6)
);
});
test('issue #2837 "Add Line Comment" fault when blank lines involved', function () {
testAddLineCommentCommand(
[
@@ -937,4 +1002,20 @@ suite('Editor Contrib - Line Comment in mixed modes', () => {
);
});
test('issue #36173: Commenting code in JSX tag body', () => {
testLineCommentCommand(
[
'<div>',
' {123}',
'</div>',
],
new Selection(2, 4, 2, 4),
[
'<div>',
' {/* {123} */}',
'</div>',
],
new Selection(2, 8, 2, 8),
);
});
});