Skip to content
Merged
Show file tree
Hide file tree
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
Binary file modified Dependencies/salesforce-soql-parser-0.19.0.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/language-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/soql-language-server",
"version": "0.3.1",
"version": "0.3.2",
"description": "SOQL Language Server",
"engines": {
"node": "*"
Expand Down
242 changes: 234 additions & 8 deletions packages/language-server/src/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ describe('Code Completion for ORDER BY', () => {
validateCompletionsFor('SELECT id FROM Account ORDER BY |', [
{
kind: CompletionItemKind.Field,
label: '__SOBJECT_FIELDS_PLACEHOLDER:Account',
label: '__SOBJECT_FIELDS_PLACEHOLDER',
data: { soqlContext: { sobjectName: 'Account' } },
},
...expectKeywords('DISTANCE'),
...expectKeywords('DISTANCE('),
]);
});

Expand Down Expand Up @@ -281,14 +282,234 @@ describe('Some keyword candidates after FROM clause', () => {
validateCompletionsFor('SELECT id FROM Account LIMIT |', []);
});

describe('WHERE clause', () => {
validateCompletionsFor('SELECT id FROM Account WHERE |', [
...expectKeywords('DISTANCE(', 'NOT'),
{
kind: CompletionItemKind.Field,
label: '__SOBJECT_FIELDS_PLACEHOLDER',
data: { soqlContext: { sobjectName: 'Account' } },
},
]);
validateCompletionsFor('SELECT id FROM Account WHERE Name |', [
...expectKeywords('IN (', 'NOT IN (', '=', '!=', '<>'),
...expectKeywordsWithFieldData('Account', 'Name', [
'INCLUDES(',
'EXCLUDES(',
'<',
'<=',
'>',
'>=',
'LIKE',
]),
]);
validateCompletionsFor('SELECT id FROM Account WHERE Type IN (|', [
...expectKeywords('SELECT'),
SELECT_snippet,
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'Type',
notNillable: false,
},
},
},
]);
validateCompletionsFor(
"SELECT id FROM Account WHERE Type IN ('Customer', |)",
[
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'Type',
notNillable: false,
},
},
},
]
);
validateCompletionsFor(
"SELECT id FROM Account WHERE Type IN (|, 'Customer')",
[
...expectKeywords('SELECT'),
SELECT_snippet,
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'Type',
notNillable: false,
},
},
},
]
);

// NOTE: Unlike IN(), INCLUDES()/EXCLUDES() never support NULL in the list
validateCompletionsFor(
'SELECT Channel FROM QuickText WHERE Channel INCLUDES(|',
[
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'QuickText',
fieldName: 'Channel',
notNillable: true,
},
},
},
]
);
validateCompletionsFor(
"SELECT Channel FROM QuickText WHERE Channel EXCLUDES('Email', |",
[
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'QuickText',
fieldName: 'Channel',
notNillable: true,
},
},
},
]
);
validateCompletionsFor('SELECT id FROM Account WHERE Type = |', [
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'Type',
notNillable: false,
},
},
},
]);
validateCompletionsFor(
"SELECT id FROM Account WHERE Type = 'Boo' OR Name = |",
[
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'Name',
notNillable: false,
},
},
},
]
);
validateCompletionsFor(
"SELECT id FROM Account WHERE Type = 'Boo' OR Name LIKE |",
[
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'Name',
notNillable: true,
},
},
},
]
);
validateCompletionsFor('SELECT id FROM Account WHERE Account.Type = |', [
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'Type',
notNillable: false,
},
},
},
]);

validateCompletionsFor(
`SELECT Name FROM Account WHERE LastActivityDate < |`,
[
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'LastActivityDate',
notNillable: true,
},
},
},
]
);
validateCompletionsFor(
`SELECT Name FROM Account WHERE LastActivityDate > |`,
[
{
kind: CompletionItemKind.Constant,
label: '__LITERAL_VALUES_FOR_FIELD',
data: {
soqlContext: {
sobjectName: 'Account',
fieldName: 'LastActivityDate',
notNillable: true,
},
},
},
]
);
});

describe('Some special functions', () => {
validateCompletionsFor('SELECT DISTANCE(|) FROM Account', [
{
kind: CompletionItemKind.Field,
label: '__SOBJECT_FIELDS_PLACEHOLDER',
data: { soqlContext: { sobjectName: 'Account' } },
},
]);
});

function expectKeywords(...words: string[]): CompletionItem[] {
return words.map((s) => ({
kind: CompletionItemKind.Keyword,
label: s,
insertText: s + ' ',
insertText: s,
}));
}
function expectKeywordsWithFieldData(
sobjectName: string,
fieldName: string,
words: string[]
): CompletionItem[] {
return words.map((s) => ({
kind: CompletionItemKind.Keyword,
label: s,
insertText: s,
data: {
soqlContext: { sobjectName: sobjectName, fieldName: fieldName },
},
}));
}

function expectItems(
kind: CompletionItemKind,
...labels: string[]
Expand Down Expand Up @@ -319,7 +540,11 @@ function validateCompletionsFor(
line,
column
);
expect(new Set(completions)).toEqual(new Set(expectedItems));

// NOTE: we don't use Sets here because when there are failures, the error
// message is not useful
expectedItems.forEach((item) => expect(completions).toContainEqual(item));
completions.forEach((item) => expect(expectedItems).toContainEqual(item));
});
}

Expand All @@ -331,13 +556,14 @@ function getCursorPosition(text: string, cursorChar: string): [number, number] {
throw new Error(`Cursor ${cursorChar} not found in ${text} !`);
}

function sobjectsFieldsFor(sbojectName: string) {
function sobjectsFieldsFor(sobjectName: string) {
return [
{
kind: CompletionItemKind.Field,
label: '__SOBJECT_FIELDS_PLACEHOLDER:' + sbojectName,
label: '__SOBJECT_FIELDS_PLACEHOLDER',
data: { soqlContext: { sobjectName: sobjectName } },
},
...expectKeywords('TYPEOF', 'DISTANCE', 'COUNT()'),
...expectKeywords('TYPEOF', 'DISTANCE(', 'COUNT()'),
COUNT_snippet,
INNER_SELECT_snippet,
];
Expand Down
Loading