Skip to content

Commit d233a66

Browse files
committed
Self review
1 parent 4803858 commit d233a66

File tree

5 files changed

+41
-53
lines changed

5 files changed

+41
-53
lines changed

packages/language-support/src/autocompletion/completionCoreCompletions.ts

+2-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CypherLexer from '../generated-parser/CypherCmdLexer';
1010
import CypherParser, {
1111
Expression2Context,
1212
} from '../generated-parser/CypherCmdParser';
13-
import { rulesDefiningVariables } from '../helpers';
13+
import { findPreviousNonSpace, rulesDefiningVariables } from '../helpers';
1414
import {
1515
CypherTokenType,
1616
lexerKeywords,
@@ -571,21 +571,6 @@ function completeAliasName({
571571
];
572572
}
573573

574-
function findPreviousNonSpace(
575-
tokens: Token[],
576-
index: number,
577-
): Token | undefined {
578-
let i = index;
579-
while (i > 0) {
580-
const token = tokens[--i];
581-
582-
if (token.type !== CypherParser.SPACE) {
583-
return token;
584-
}
585-
}
586-
587-
return undefined;
588-
}
589574
function completeSymbolicName({
590575
candidateRule,
591576
dbSchema,
@@ -609,7 +594,7 @@ function completeSymbolicName({
609594
const afterToToken = previousToken.type === CypherParser.TO;
610595
const ruleList = candidateRule.ruleList;
611596

612-
// avoid suggesting existing database names when creating a new user or role
597+
// avoid suggesting existing user names or role names when creating a new one
613598
if (
614599
rulesCreatingNewUserOrRole.some((rule) => ruleList.includes(rule)) ||
615600
// We are suggesting an user as target for the renaming

packages/language-support/src/helpers.ts

+16
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,22 @@ export function splitIntoStatements(
176176
return result;
177177
}
178178

179+
export function findPreviousNonSpace(
180+
tokens: Token[],
181+
index: number,
182+
): Token | undefined {
183+
let i = index;
184+
while (i > 0) {
185+
const token = tokens[--i];
186+
187+
if (token.type !== CypherParser.SPACE) {
188+
return token;
189+
}
190+
}
191+
192+
return undefined;
193+
}
194+
179195
export const rulesDefiningVariables = [
180196
CypherParser.RULE_returnItem,
181197
CypherParser.RULE_unwindClause,

packages/language-support/src/tests/autocompletion/parameterCompletions.test.ts

+21-13
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,6 @@ describe('Completes parameters outside of databases, roles, user names', () => {
6565
});
6666
});
6767

68-
test('Correctly suggests parameter in ENABLE SERVER', () => {
69-
const query = 'ENABLE SERVER ';
70-
testCompletions({
71-
query,
72-
dbSchema,
73-
expected: [{ label: '$stringParam', kind: CompletionItemKind.Variable }],
74-
excluded: [
75-
{ label: '$intParam', kind: CompletionItemKind.Variable },
76-
{ label: '$mapParam', kind: CompletionItemKind.Variable },
77-
],
78-
});
79-
});
80-
8168
test('Suggests parameter as map properties', () => {
8269
const query = 'match (v :Movie ';
8370

@@ -175,4 +162,25 @@ describe('Completes parameters outside of databases, roles, user names', () => {
175162
});
176163
});
177164
});
165+
166+
test('Suggests parameters for passwords', () => {
167+
const cases = [
168+
'ALTER CURRENT USER SET PASSWORD FROM ',
169+
'ALTER CURRENT USER SET PASSWORD FROM $pw to ',
170+
'ALTER USER foo IF EXISTS SET PASSWORD ',
171+
];
172+
cases.forEach((query) => {
173+
testCompletions({
174+
query,
175+
dbSchema,
176+
expected: [
177+
{ label: '$stringParam', kind: CompletionItemKind.Variable },
178+
],
179+
excluded: [
180+
{ label: '$intParam', kind: CompletionItemKind.Variable },
181+
{ label: '$mapParam', kind: CompletionItemKind.Variable },
182+
],
183+
});
184+
});
185+
});
178186
});

packages/language-support/src/tests/autocompletion/roleNameCompletion.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ describe('Can complete role names', () => {
306306
);
307307
});
308308

309-
test('Correctly completes parameters and existing user names in GRANT database privilege', () => {
309+
test('Correctly completes parameters and existing role names in GRANT database privilege', () => {
310310
const cases = [
311311
'GRANT TERMINATE TRANSACTION (user) ON DATABASE neo4j TO ',
312312
'GRANT TERMINATE TRANSACTION (user) ON DATABASE neo4j TO role, ',
@@ -321,7 +321,7 @@ describe('Can complete role names', () => {
321321
{ label: 'foo', kind: CompletionItemKind.Value },
322322
{ label: 'bar', kind: CompletionItemKind.Value },
323323
],
324-
// do not suggest non-string parameters or existing user names
324+
// do not suggest non-string parameters or existing role names
325325
excluded: [
326326
{ label: '$intParam', kind: CompletionItemKind.Variable },
327327
{ label: '$mapParam', kind: CompletionItemKind.Variable },

packages/language-support/src/tests/autocompletion/userNameCompletion.test.ts

-21
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,6 @@ describe('Can complete user names', () => {
126126
);
127127
});
128128

129-
test('Suggests parameters for passwords', () => {
130-
const cases = [
131-
'ALTER CURRENT USER SET PASSWORD FROM ',
132-
'ALTER CURRENT USER SET PASSWORD FROM $pw to ',
133-
'ALTER USER foo IF EXISTS SET PASSWORD ',
134-
];
135-
cases.forEach((query) => {
136-
testCompletions({
137-
query,
138-
dbSchema,
139-
expected: [
140-
{ label: '$stringParam', kind: CompletionItemKind.Variable },
141-
],
142-
excluded: [
143-
{ label: '$intParam', kind: CompletionItemKind.Variable },
144-
{ label: '$mapParam', kind: CompletionItemKind.Variable },
145-
],
146-
});
147-
});
148-
});
149-
150129
test('Correctly completes parameters and existing user names in GRANT ROLE TO USER', () => {
151130
const cases = ['GRANT ROLE abc TO ', 'GRANT ROLE abc TO user, '];
152131

0 commit comments

Comments
 (0)