Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct suggestions after count command #215

Merged
merged 3 commits into from
Nov 10, 2021
Merged
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 @@ -158,7 +158,13 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
nextStats = splittedModel.length;
return fillSuggestions(str, prefix, statsCommands);
} else if (nextStats === splittedModel.length - 1) {
if (splittedModel[splittedModel.length - 2] !== 'count()') {
if (statsCommands.filter(c => c.label === splittedModel[splittedModel.length - 2]).length > 0) {
if (splittedModel[splittedModel.length - 2] === 'count()') {
return [
{ label: str + 'by', input: str, suggestion: 'by'.substring(prefix.length), itemName: 'by' }
].filter(({ label }) => label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(label.toLowerCase())
);
} else {
const numberFields = fieldsFromBackend.filter(
(field: { label: string, type: string }) =>
field.label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(field.label.toLowerCase()) && (field.type === 'float' || field.type === 'integer')
Expand All @@ -173,10 +179,15 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
});
}
return fullSuggestions;
}
}
} else if (nextStats === splittedModel.length - 2 && splittedModel[splittedModel.length - 3] === 'count()') {
return fillSuggestions(str, prefix, fieldsFromBackend);
} else if (nextStats === splittedModel.length - 3) {
return [{ label: str + 'by', input: str, suggestion: 'by'.substring(prefix.length), itemName: 'by' }].filter(
({ label }) => label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(label.toLowerCase())
return [
{ label: str + 'by', input: str, suggestion: 'by'.substring(prefix.length), itemName: 'by' },
{ label: str + '|', input: str, suggestion: '|', itemName: '|' }
].filter(({ label }) => label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(label.toLowerCase())
);
} else if (nextStats === splittedModel.length - 4) {
return fillSuggestions(str, prefix, fieldsFromBackend);
Expand Down Expand Up @@ -215,7 +226,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
);
}
return [];
} else if (nextWhere === splittedModel.length - 3 || nextStats === splittedModel.length - 5 || nextWhere === splitteModel.length - 5) {
} else if (nextWhere === splittedModel.length - 3 || nextStats === splittedModel.length - 5 || nextWhere === splittedModel.length - 5) {
return [{ label: str + '|', input: str, suggestion: '|', itemName: '|' }].filter(
({ label }) => label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(label.toLowerCase())
);
Expand Down