Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,13 @@ export class ResolvedLanguageConfiguration {
const comments: ICommentsConfiguration = {};

if (commentRule.lineComment) {
// Surrounding whitespace is not part of the comment marker; spacing on
// insertion is controlled by the `editor.comments.insertSpace` setting.
// Keeping it would break comment toggling, see #249958.
if (typeof commentRule.lineComment === 'string') {
comments.lineCommentToken = commentRule.lineComment;
comments.lineCommentToken = commentRule.lineComment.trim();
} else {
comments.lineCommentToken = commentRule.lineComment.comment;
comments.lineCommentToken = commentRule.lineComment.comment.trim();
Comment thread
verifizieren marked this conversation as resolved.
comments.lineCommentNoIndent = commentRule.lineComment.noIndent;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,72 @@ suite('Editor Contrib - Line Comment Command', () => {
);
});

test('toggle line comment when the comment token has surrounding whitespace (#249958)', function () {
const testLineCommentCommand = createTestCommandHelper(
{ lineComment: ' !@# ' },
(accessor, sel) => new LineCommentCommand(accessor.get(ILanguageConfigurationService), sel, 4, Type.Toggle, true, true)
);

// Adds the trimmed comment token
testLineCommentCommand(
[
'some text'
],
new Selection(1, 1, 1, 1),
[
'!@# some text'
],
new Selection(1, 5, 1, 5)
);

// Toggling again removes it instead of stacking another comment
testLineCommentCommand(
[
'!@# some text'
],
new Selection(1, 1, 1, 1),
[
'some text'
],
new Selection(1, 1, 1, 1)
);
});

test('toggle line comment when the object-form comment token has surrounding whitespace (#249958)', function () {
const testLineCommentCommand = createTestCommandHelper(
{ lineComment: { comment: ' !@# ', noIndent: true } },
(accessor, sel) => new LineCommentCommand(accessor.get(ILanguageConfigurationService), sel, 4, Type.Toggle, true, true)
);

// Adds the trimmed comment token at the first column (noIndent)
testLineCommentCommand(
[
'some text',
'\tsome more text'
],
new Selection(2, 1, 2, 1),
[
'some text',
'!@# \tsome more text'
],
new Selection(2, 5, 2, 5)
);

// Toggling again removes it instead of stacking another comment
testLineCommentCommand(
[
'some text',
'!@# \tsome more text'
],
new Selection(2, 1, 2, 1),
[
'some text',
'\tsome more text'
],
new Selection(2, 1, 2, 1)
);
});

function createSimpleModel(lines: string[]): ISimpleModel {
return {
getLineContent: (lineNumber: number) => {
Expand Down