未验证 提交 1026e5fb 编写于 作者: A Alexandru Dima 提交者: GitHub

Merge pull request #51557 from limerickgds/master

fixed:generator method of class autocomplete causes star(*) to be add…
......@@ -31,6 +31,7 @@ const jsTsLanguageConfiguration: vscode.LanguageConfiguration = {
}, {
// e.g. * ...|
beforeText: /^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
oneLineAboveText: /^(\s*(\/\*\*|\*)).*/,
action: { indentAction: vscode.IndentAction.None, appendText: '* ' }
}, {
// e.g. */|
......
......@@ -146,6 +146,10 @@ export interface OnEnterRule {
* This rule will only execute if the text after the cursor matches this regular expression.
*/
afterText?: RegExp;
/**
* This rule will only execute if the text above the this line matches this regular expression.
*/
oneLineAboveText?: RegExp;
/**
* The action to execute.
*/
......
......@@ -48,17 +48,25 @@ export class OnEnterSupport {
// (1): `regExpRules`
for (let i = 0, len = this._regExpRules.length; i < len; i++) {
let rule = this._regExpRules[i];
if (rule.beforeText.test(beforeEnterText)) {
if (rule.afterText) {
if (rule.afterText.test(afterEnterText)) {
return rule.action;
}
} else {
return rule.action;
}
const regResult = [{
reg: rule.beforeText,
text: beforeEnterText
}, {
reg: rule.afterText,
text: afterEnterText
}, {
reg: rule.oneLineAboveText,
text: oneLineAboveText
}].every((obj): boolean => {
return obj.reg ? obj.reg.test(obj.text) : true;
});
if (regResult) {
return rule.action;
}
}
// (2): Special indent-outdent
if (beforeEnterText.length > 0 && afterEnterText.length > 0) {
for (let i = 0, len = this._brackets.length; i < len; i++) {
......
......@@ -9,12 +9,12 @@ import { URI } from 'vs/base/common/uri';
import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import { LanguageIdentifier } from 'vs/editor/common/modes';
import { IndentAction } from 'vs/editor/common/modes/languageConfiguration';
import { TokenSelectionSupport } from 'vs/editor/contrib/smartSelect/tokenSelectionSupport';
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
class MockJSMode extends MockMode {
......@@ -30,34 +30,7 @@ class MockJSMode extends MockMode {
['[', ']']
],
onEnterRules: [
{
// e.g. /** | */
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
},
{
// e.g. /** ...|
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: IndentAction.None, appendText: ' * ' }
},
{
// e.g. * ...|
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: IndentAction.None, appendText: '* ' }
},
{
// e.g. */|
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
},
{
// e.g. *-----*/|
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
}
]
onEnterRules: javascriptOnEnterRules
}));
}
}
......
......@@ -9,12 +9,12 @@ import { ShiftCommand } from 'vs/editor/common/commands/shiftCommand';
import { Selection } from 'vs/editor/common/core/selection';
import { Range } from 'vs/editor/common/core/range';
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
import { IndentAction } from 'vs/editor/common/modes/languageConfiguration';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { getEditOperation, testCommand } from 'vs/editor/test/browser/testCommand';
import { withEditorModel } from 'vs/editor/test/common/editorTestUtils';
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
import { LanguageIdentifier } from 'vs/editor/common/modes';
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
/**
* Create single edit operation
......@@ -39,34 +39,7 @@ class DocBlockCommentMode extends MockMode {
['[', ']']
],
onEnterRules: [
{
// e.g. /** | */
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
},
{
// e.g. /** ...|
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: IndentAction.None, appendText: ' * ' }
},
{
// e.g. * ...|
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: IndentAction.None, appendText: '* ' }
},
{
// e.g. */|
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
},
{
// e.g. *-----*/|
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
}
]
onEnterRules: javascriptOnEnterRules
}));
}
}
......
......@@ -25,6 +25,7 @@ import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
import { NULL_STATE } from 'vs/editor/common/modes/nullMode';
import { TokenizationResult2 } from 'vs/editor/common/core/token';
import { createTextModel, IRelaxedTextModelCreationOptions } from 'vs/editor/test/common/editorTestUtils';
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
const H = Handler;
......@@ -3517,31 +3518,7 @@ suite('Editor Controller - Indentation Rules', () => {
// ^.*\{[^}"']*$
increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/
},
onEnterRules: [
{
// e.g. /** | */
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
}, {
// e.g. /** ...|
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: IndentAction.None, appendText: ' * ' }
}, {
// e.g. * ...|
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: IndentAction.None, appendText: '* ' }
}, {
// e.g. */|
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
},
{
// e.g. *-----*/|
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
}
]
onEnterRules: javascriptOnEnterRules
}));
}
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IndentAction } from 'vs/editor/common/modes/languageConfiguration';
export const javascriptOnEnterRules = [
{
// e.g. /** | */
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
}, {
// e.g. /** ...|
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: IndentAction.None, appendText: ' * ' }
}, {
// e.g. * ...|
beforeText: /^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
oneLineAboveText: /^(\s*(\/\*\*|\*)).*/,
action: { indentAction: IndentAction.None, appendText: '* ' }
}, {
// e.g. */|
beforeText: /^(\t|[ ])*[ ]\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
},
{
// e.g. *-----*/|
beforeText: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
}
];
......@@ -7,6 +7,7 @@
import * as assert from 'assert';
import { CharacterPair, IndentAction } from 'vs/editor/common/modes/languageConfiguration';
import { OnEnterSupport } from 'vs/editor/common/modes/supports/onEnter';
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
suite('OnEnter', () => {
......@@ -49,32 +50,10 @@ suite('OnEnter', () => {
test('uses regExpRules', () => {
let support = new OnEnterSupport({
regExpRules: [
{
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
},
{
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: IndentAction.None, appendText: ' * ' }
},
{
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: IndentAction.None, appendText: '* ' }
},
{
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
},
{
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
}
]
regExpRules: javascriptOnEnterRules
});
let testIndentAction = (beforeText: string, afterText: string, expectedIndentAction: IndentAction, expectedAppendText: string, removeText: number = 0) => {
let actual = support.onEnter('', beforeText, afterText);
let testIndentAction = (oneLineAboveText: string, beforeText: string, afterText: string, expectedIndentAction: IndentAction, expectedAppendText: string, removeText: number = 0) => {
let actual = support.onEnter(oneLineAboveText, beforeText, afterText);
if (expectedIndentAction === null) {
assert.equal(actual, null, 'isNull:' + beforeText);
} else {
......@@ -89,40 +68,70 @@ suite('OnEnter', () => {
}
};
testIndentAction('\t/**', ' */', IndentAction.IndentOutdent, ' * ');
testIndentAction('\t/**', '', IndentAction.None, ' * ');
testIndentAction('\t/** * / * / * /', '', IndentAction.None, ' * ');
testIndentAction('\t/** /*', '', IndentAction.None, ' * ');
testIndentAction('/**', '', IndentAction.None, ' * ');
testIndentAction('\t/**/', '', null, null);
testIndentAction('\t/***/', '', null, null);
testIndentAction('\t/*******/', '', null, null);
testIndentAction('\t/** * * * * */', '', null, null);
testIndentAction('\t/** */', '', null, null);
testIndentAction('\t/** asdfg */', '', null, null);
testIndentAction('\t/* asdfg */', '', null, null);
testIndentAction('\t/* asdfg */', '', null, null);
testIndentAction('\t/** asdfg */', '', null, null);
testIndentAction('*/', '', null, null);
testIndentAction('\t/*', '', null, null);
testIndentAction('\t*', '', null, null);
testIndentAction('\t *', '', IndentAction.None, '* ');
testIndentAction('\t */', '', IndentAction.None, null, 1);
testIndentAction('\t * */', '', IndentAction.None, null, 1);
testIndentAction('\t * * / * / * / */', '', null, null);
testIndentAction('\t * ', '', IndentAction.None, '* ');
testIndentAction(' * ', '', IndentAction.None, '* ');
testIndentAction(' * asdfsfagadfg', '', IndentAction.None, '* ');
testIndentAction(' * asdfsfagadfg * * * ', '', IndentAction.None, '* ');
testIndentAction(' * /*', '', IndentAction.None, '* ');
testIndentAction(' * asdfsfagadfg * / * / * /', '', IndentAction.None, '* ');
testIndentAction(' * asdfsfagadfg * / * / * /*', '', IndentAction.None, '* ');
testIndentAction(' */', '', IndentAction.None, null, 1);
testIndentAction('\t */', '', IndentAction.None, null, 1);
testIndentAction('\t\t */', '', IndentAction.None, null, 1);
testIndentAction(' */', '', IndentAction.None, null, 1);
testIndentAction(' */', '', IndentAction.None, null, 1);
testIndentAction('\t */', '', IndentAction.None, null, 1);
testIndentAction(' *--------------------------------------------------------------------------------------------*/', '', IndentAction.None, null, 1);
testIndentAction('', '\t/**', ' */', IndentAction.IndentOutdent, ' * ');
testIndentAction('', '\t/**', '', IndentAction.None, ' * ');
testIndentAction('', '\t/** * / * / * /', '', IndentAction.None, ' * ');
testIndentAction('', '\t/** /*', '', IndentAction.None, ' * ');
testIndentAction('', '/**', '', IndentAction.None, ' * ');
testIndentAction('', '\t/**/', '', null, null);
testIndentAction('', '\t/***/', '', null, null);
testIndentAction('', '\t/*******/', '', null, null);
testIndentAction('', '\t/** * * * * */', '', null, null);
testIndentAction('', '\t/** */', '', null, null);
testIndentAction('', '\t/** asdfg */', '', null, null);
testIndentAction('', '\t/* asdfg */', '', null, null);
testIndentAction('', '\t/* asdfg */', '', null, null);
testIndentAction('', '\t/** asdfg */', '', null, null);
testIndentAction('', '*/', '', null, null);
testIndentAction('', '\t/*', '', null, null);
testIndentAction('', '\t*', '', null, null);
testIndentAction('\t/**', '\t *', '', IndentAction.None, '* ');
testIndentAction('\t * something', '\t *', '', IndentAction.None, '* ');
testIndentAction('\t *', '\t *', '', IndentAction.None, '* ');
testIndentAction('', '\t */', '', IndentAction.None, null, 1);
testIndentAction('', '\t * */', '', IndentAction.None, null, 1);
testIndentAction('', '\t * * / * / * / */', '', null, null);
testIndentAction('\t/**', '\t * ', '', IndentAction.None, '* ');
testIndentAction('\t * something', '\t * ', '', IndentAction.None, '* ');
testIndentAction('\t *', '\t * ', '', IndentAction.None, '* ');
testIndentAction('/**', ' * ', '', IndentAction.None, '* ');
testIndentAction(' * something', ' * ', '', IndentAction.None, '* ');
testIndentAction(' *', ' * asdfsfagadfg', '', IndentAction.None, '* ');
testIndentAction('/**', ' * asdfsfagadfg * * * ', '', IndentAction.None, '* ');
testIndentAction(' * something', ' * asdfsfagadfg * * * ', '', IndentAction.None, '* ');
testIndentAction(' *', ' * asdfsfagadfg * * * ', '', IndentAction.None, '* ');
testIndentAction('/**', ' * /*', '', IndentAction.None, '* ');
testIndentAction(' * something', ' * /*', '', IndentAction.None, '* ');
testIndentAction(' *', ' * /*', '', IndentAction.None, '* ');
testIndentAction('/**', ' * asdfsfagadfg * / * / * /', '', IndentAction.None, '* ');
testIndentAction(' * something', ' * asdfsfagadfg * / * / * /', '', IndentAction.None, '* ');
testIndentAction(' *', ' * asdfsfagadfg * / * / * /', '', IndentAction.None, '* ');
testIndentAction('/**', ' * asdfsfagadfg * / * / * /*', '', IndentAction.None, '* ');
testIndentAction(' * something', ' * asdfsfagadfg * / * / * /*', '', IndentAction.None, '* ');
testIndentAction(' *', ' * asdfsfagadfg * / * / * /*', '', IndentAction.None, '* ');
testIndentAction('', ' */', '', IndentAction.None, null, 1);
testIndentAction('', '\t */', '', IndentAction.None, null, 1);
testIndentAction('', '\t\t */', '', IndentAction.None, null, 1);
testIndentAction('', ' */', '', IndentAction.None, null, 1);
testIndentAction('', ' */', '', IndentAction.None, null, 1);
testIndentAction('', '\t */', '', IndentAction.None, null, 1);
testIndentAction('', ' *--------------------------------------------------------------------------------------------*/', '', IndentAction.None, null, 1);
// issue #43469
testIndentAction('class A {', ' * test() {', '', IndentAction.Indent, null, 0);
testIndentAction('', ' * test() {', '', IndentAction.Indent, null, 0);
testIndentAction(' ', ' * test() {', '', IndentAction.Indent, null, 0);
testIndentAction('class A {', ' * test() {', '', IndentAction.Indent, null, 0);
testIndentAction('', ' * test() {', '', IndentAction.Indent, null, 0);
testIndentAction(' ', ' * test() {', '', IndentAction.Indent, null, 0);
});
});
\ No newline at end of file
......@@ -4670,6 +4670,10 @@ declare namespace monaco.languages {
* This rule will only execute if the text after the cursor matches this regular expression.
*/
afterText?: RegExp;
/**
* This rule will only execute if the text above the this line matches this regular expression.
*/
oneLineAboveText?: RegExp;
/**
* The action to execute.
*/
......
......@@ -3738,6 +3738,10 @@ declare module 'vscode' {
* This rule will only execute if the text after the cursor matches this regular expression.
*/
afterText?: RegExp;
/**
* This rule will only execute if the text above the this line matches this regular expression.
*/
oneLineAboveText?: RegExp;
/**
* The action to execute.
*/
......
......@@ -402,6 +402,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
return {
beforeText: MainThreadLanguageFeatures._reviveRegExp(onEnterRule.beforeText),
afterText: MainThreadLanguageFeatures._reviveRegExp(onEnterRule.afterText),
oneLineAboveText: MainThreadLanguageFeatures._reviveRegExp(onEnterRule.oneLineAboveText),
action: onEnterRule.action
};
}
......
......@@ -226,6 +226,7 @@ export interface ISerializedIndentationRule {
export interface ISerializedOnEnterRule {
beforeText: ISerializedRegExp;
afterText?: ISerializedRegExp;
oneLineAboveText?: ISerializedRegExp;
action: EnterAction;
}
export interface ISerializedLanguageConfiguration {
......
......@@ -1232,6 +1232,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
return {
beforeText: ExtHostLanguageFeatures._serializeRegExp(onEnterRule.beforeText),
afterText: ExtHostLanguageFeatures._serializeRegExp(onEnterRule.afterText),
oneLineAboveText: ExtHostLanguageFeatures._serializeRegExp(onEnterRule.oneLineAboveText),
action: onEnterRule.action
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册