Skip to content

Commit

Permalink
Fixes #88012: consider pairs like (r',') to be symmetric
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jan 24, 2020
1 parent 951202b commit 1d93480
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/vs/editor/common/controller/cursorTypeOperations.ts
Expand Up @@ -492,15 +492,20 @@ export class TypeOperations {
});
}

private static _autoClosingPairIsSymmetric(autoClosingPair: StandardAutoClosingPairConditional): boolean {
const { open, close } = autoClosingPair;
return (open.indexOf(close) >= 0 || close.indexOf(open) >= 0);
}

private static _isBeforeClosingBrace(config: CursorConfiguration, autoClosingPair: StandardAutoClosingPairConditional, characterAfter: string) {
const otherAutoClosingPairs = config.autoClosingPairsClose2.get(characterAfter);
if (!otherAutoClosingPairs) {
return false;
}

const thisBraceIsSymmetric = (autoClosingPair.open === autoClosingPair.close);
const thisBraceIsSymmetric = TypeOperations._autoClosingPairIsSymmetric(autoClosingPair);
for (const otherAutoClosingPair of otherAutoClosingPairs) {
const otherBraceIsSymmetric = (otherAutoClosingPair.open === otherAutoClosingPair.close);
const otherBraceIsSymmetric = TypeOperations._autoClosingPairIsSymmetric(otherAutoClosingPair);
if (!thisBraceIsSymmetric && otherBraceIsSymmetric) {
continue;
}
Expand Down
45 changes: 45 additions & 0 deletions src/vs/editor/test/browser/controller/cursor.test.ts
Expand Up @@ -4901,6 +4901,51 @@ suite('autoClosingPairs', () => {
mode.dispose();
});

test('issue #85983 - editor.autoClosingBrackets: beforeWhitespace is incorrect for Python', () => {
const languageId = new LanguageIdentifier('pythonMode', 5);
class PythonMode extends MockMode {
constructor() {
super(languageId);
this._register(LanguageConfigurationRegistry.register(this.getLanguageIdentifier(), {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '\"', close: '\"', notIn: ['string'] },
{ open: 'r\"', close: '\"', notIn: ['string', 'comment'] },
{ open: 'R\"', close: '\"', notIn: ['string', 'comment'] },
{ open: 'u\"', close: '\"', notIn: ['string', 'comment'] },
{ open: 'U\"', close: '\"', notIn: ['string', 'comment'] },
{ open: 'f\"', close: '\"', notIn: ['string', 'comment'] },
{ open: 'F\"', close: '\"', notIn: ['string', 'comment'] },
{ open: 'b\"', close: '\"', notIn: ['string', 'comment'] },
{ open: 'B\"', close: '\"', notIn: ['string', 'comment'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: 'r\'', close: '\'', notIn: ['string', 'comment'] },
{ open: 'R\'', close: '\'', notIn: ['string', 'comment'] },
{ open: 'u\'', close: '\'', notIn: ['string', 'comment'] },
{ open: 'U\'', close: '\'', notIn: ['string', 'comment'] },
{ open: 'f\'', close: '\'', notIn: ['string', 'comment'] },
{ open: 'F\'', close: '\'', notIn: ['string', 'comment'] },
{ open: 'b\'', close: '\'', notIn: ['string', 'comment'] },
{ open: 'B\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string'] }
],
}));
}
}
const mode = new PythonMode();
usingCursor({
text: [
'foo\'hello\''
],
languageIdentifier: mode.getLanguageIdentifier()
}, (model, cursor) => {
assertType(model, cursor, 1, 4, '(', '(', `does not auto close @ (1, 4)`);
});
mode.dispose();
});

test('issue #78975 - Parentheses swallowing does not work when parentheses are inserted by autocomplete', () => {
let mode = new AutoClosingMode();
usingCursor({
Expand Down

0 comments on commit 1d93480

Please sign in to comment.