Skip to content

Commit

Permalink
update the diagnostic path
Browse files Browse the repository at this point in the history
  • Loading branch information
lei9444 committed Dec 25, 2019
1 parent 0dd2282 commit 7a4ef0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function parseTypeToFragment(type: string, property: string): string {
case 'prompt':
return PromptTab.BOT_ASKS;
case 'property':
case 'choices':
case 'outputFormat':
return PromptTab.USER_INPUT;
default:
Expand Down
22 changes: 17 additions & 5 deletions Composer/packages/lib/indexers/src/dialogUtils/dialogChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ import { CheckerFunc } from './types';

const ExpressionParser = new ExpressionEngine();

export const checkExpression = (exp: string, required: boolean, path: string): Diagnostic | null => {
const createPath = (path: string, type: string): string => {
const steps = ['triggers', 'actions', 'elseActions'];
let list = path.split('.');
const matchs = list.filter(x => !steps.every(step => !x.startsWith(step)));

const focused = matchs.join('.');
list = path.split(`${focused}.`);
if (list.length !== 2) return path;

return `${list[0]}${focused}#${type}#${list[1]}`;
};

export const checkExpression = (exp: string, required: boolean, path: string, type: string): Diagnostic | null => {
let message = '';
if (!exp && required) {
message = formatMessage(`is missing or empty`);
Expand All @@ -24,7 +36,7 @@ export const checkExpression = (exp: string, required: boolean, path: string): D
}
if (message) {
const diagnostic = new Diagnostic(message, '');
diagnostic.path = path;
diagnostic.path = createPath(path, type);
return diagnostic;
}

Expand Down Expand Up @@ -57,7 +69,7 @@ export const IsExpression: CheckerFunc = (path, value, type, schema) => {
const itemsSchema = schema.properties[key].items;
if (itemsSchema?.$role === 'expression') {
property.forEach((child, index) => {
const diagnostic = checkExpression(child, !!requiredTypes[key], `${path}#${type}#${key}[${index}]`);
const diagnostic = checkExpression(child, !!requiredTypes[key], `${path}.${key}[${index}]`, type);
if (diagnostic) diagnostics.push(diagnostic);
});
} else if (itemsSchema?.type === 'object') {
Expand All @@ -67,7 +79,7 @@ export const IsExpression: CheckerFunc = (path, value, type, schema) => {
});
}
} else if (get(schema.properties[key], '$role') === 'expression') {
const diagnostic = checkExpression(property, !!requiredTypes[key], `${path}#${type}#${key}`);
const diagnostic = checkExpression(property, !!requiredTypes[key], `${path}.${key}`, type);
if (diagnostic) diagnostics.push(diagnostic);
}
});
Expand All @@ -79,7 +91,7 @@ export const checkChoices: CheckerFunc = (path, value, type, schema) => {
if (type === 'Microsoft.ChoiceInput') {
const choices = value.choices;
if (typeof choices === 'string') {
const diagnostic = checkExpression(choices, false, `${path}#${type}#choices`);
const diagnostic = checkExpression(choices, false, `${path}.choices`, type);
if (diagnostic) return [diagnostic];
}
}
Expand Down

0 comments on commit 7a4ef0c

Please sign in to comment.