Skip to content

Commit

Permalink
fix: Some editting bugs in Lu editor (#2285)
Browse files Browse the repository at this point in the history
* fix some known LU LSP editing bugs

* remove console.log
  • Loading branch information
cosmicshuai committed Mar 17, 2020
1 parent 97b9698 commit abb576e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Composer/packages/lib/code-editor/src/languages/lu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export function registerLULanguage(monaco: typeof monacoEditor) {
[/^\s*>\s*[\s\S]*$/, { token: 'comments' }],
[/^\s*-/, { token: 'utterrance-indentifier', next: 'utterrance' }],
[
/(@\s*)(prebuilt\s*)(age|datetimeV2|dimension|email|geographyV2|keyPhrase|money|number|ordinal|ordinalV2|percentage|personName|phonenumber|temperature|url|datetime)(\s*[\w_,\s]+)/,
/(@\s*)(prebuilt\s+)(age|datetimeV2|dimension|email|geographyV2|keyPhrase|money|number|ordinal|ordinalV2|percentage|personName|phonenumber|temperature|url|datetime)(\s+[\w_,\s]+)/,
['intent-indentifier', 'entity-type', 'prebult-type', 'entity-name'],
],
[
// eslint-disable-next-line security/detect-unsafe-regex
/(@\s*)(ml|prebuilt|regex|list|composite|Pattern\.Any|phraseList)(\s*[\w_]+)/,
/(@\s*)(ml|prebuilt|regex|list|composite|Pattern\.Any|phraseList)(\s+[\w_]+)/,
['intent-indentifier', 'entity-type', 'entity-name'],
],
[/(@\s*)(\s*[\w_]+)/, ['intent-indentifier', 'entity-name']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ export class LUServer {
const range = Range.create(position.lineNumber - 1, 0, position.lineNumber - 1, position.column);
const curLineContent = document.getText(range);
// eslint-disable-next-line security/detect-unsafe-regex
const labeledUtterRegex = /^\s*-([^{}]*\s*\{[\w.@:\s]+\s*=\s*[\w.]+\}[^{}]*)+$/;

const labeledUtterRegex = /^\s*-([^{}]*\s*\{[\w.@:\s]+\s*=\s*[\w.\s]+\}[^{}]*)+$/;
if (labeledUtterRegex.test(curLineContent)) {
const newText = util.removeLabelsInUtterance(curLineContent);

const newPos = Position.create(position.lineNumber, 0);
const newUnlalbelText = newText + '\n';
const editPreviousLine: TextEdit = TextEdit.insert(newPos, newUnlalbelText);
Expand Down Expand Up @@ -229,7 +227,7 @@ export class LUServer {

const pos = params.position;
if (key === '\n' && inputState === 'utterance' && lastLineContent.trim() !== '-') {
const newPos = Position.create(pos.line + 1, 0);
const newPos = Position.create(pos.line, 0);
const item: TextEdit = TextEdit.insert(newPos, '- ');
edits.push(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function extractEntityNameInUseFeature(lineContent: string): string {
}

export function removeLabelsInUtterance(lineContent: string): string {
const entityLabelRegex = /\{\s*[\w.@:\s]+\s*=\s*[\w.]+\s*\}/g;
const entityLabelRegex = /\{\s*[\w.@:\s]+\s*=\s*[\w.@:\s]+\s*\}/g;
let match: RegExpMatchArray | null;
let resultStr = '';
let startIdx = 0;
Expand Down

0 comments on commit abb576e

Please sign in to comment.