Skip to content

Commit

Permalink
split dbname and label/reltype/propkey backticks. Removed backticking…
Browse files Browse the repository at this point in the history
… of parameters (for now)
  • Loading branch information
anderson4j committed Dec 9, 2024
1 parent 4fa3bf0 commit 4a9391c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ function backtickIfNeeded(e: string): string | undefined {
}
}

function backtickDbNameIfNeeded(e: string): string | undefined {
if (e == null || e == '') {
return undefined;
} else if (/[^\p{L}\p{N}_.]/u.test(e) || /[^\p{L}_]/u.test(e[0])) {
return `\`${e}\``;
} else {
return undefined;
}
}

const labelCompletions = (dbSchema: DbSchema) =>
dbSchema.labels?.map((labelName) => {
const result: CompletionItem = {
Expand Down Expand Up @@ -692,11 +702,7 @@ function completeAliasName({
if (
rulesCreatingNewDb.some((rule) => candidateRule.ruleList.includes(rule))
) {
return parameterSuggestions.map((completionItem) => ({
label: completionItem.label,
kind: completionItem.kind,
insertText: backtickIfNeeded(completionItem.label),
}));
return parameterSuggestions;
}

// For `CREATE ALIAS aliasName FOR DATABASE databaseName`
Expand All @@ -706,11 +712,7 @@ function completeAliasName({
candidateRule.ruleList.includes(CypherParser.RULE_createAlias) &&
candidateRule.ruleList.includes(CypherParser.RULE_aliasName)
) {
return parameterSuggestions.map((completionItem) => ({
label: completionItem.label,
kind: completionItem.kind,
insertText: backtickIfNeeded(completionItem.label),
}));
return parameterSuggestions;
}

const rulesThatOnlyAcceptAlias = [
Expand All @@ -724,15 +726,11 @@ function completeAliasName({
)
) {
return [
...parameterSuggestions.map((completionItem) => ({
label: completionItem.label,
kind: completionItem.kind,
insertText: backtickIfNeeded(completionItem.label), //TODO: necessary? it seems rn we cant create backticked param in cmd
})),
...parameterSuggestions,
...(dbSchema?.aliasNames ?? []).map((aliasName) => ({
label: aliasName,
kind: CompletionItemKind.Value,
insertText: backtickIfNeeded(aliasName),
insertText: backtickDbNameIfNeeded(aliasName),
})),
];
}
Expand All @@ -745,7 +743,7 @@ function completeAliasName({
.map((databaseName) => ({
label: databaseName,
kind: CompletionItemKind.Value,
insertText: backtickIfNeeded(databaseName),
insertText: backtickDbNameIfNeeded(databaseName),
})),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { testCompletions } from './completionAssertionHelpers';

describe('Can complete database names', () => {
const dbSchema: DbSchema = {
databaseNames: ['db1', 'db2', 'movies', 'financial reports, neo4j_server'],
databaseNames: [
'db1',
'db2',
'movies',
'financial reports',
'neo4j_server',
],
aliasNames: [
'myMovies',
'scoped.alias',
Expand All @@ -30,17 +36,17 @@ describe('Can complete database names', () => {
expected: [
{
label: 'financial reports',
kind: CompletionItemKind.Keyword,
kind: CompletionItemKind.Value,
insertText: '`financial reports`',
},
{
label: 'panama papers1',
kind: CompletionItemKind.Keyword,
kind: CompletionItemKind.Value,
insertText: '`panama papers1`',
},
{
label: 'office-db',
kind: CompletionItemKind.Keyword,
kind: CompletionItemKind.Value,
insertText: '`office-db`',
},
],
Expand All @@ -59,7 +65,7 @@ describe('Can complete database names', () => {
{ label: 'db1', kind: CompletionItemKind.Value },
{ label: 'db2', kind: CompletionItemKind.Value },
{ label: 'movies', kind: CompletionItemKind.Value },
{ label: 'neo4j_server', kind: CompletionItemKind.Variable },
{ label: 'neo4j_server', kind: CompletionItemKind.Value },
{ label: 'myMovies', kind: CompletionItemKind.Value },
{ label: 'scoped.alias', kind: CompletionItemKind.Value },
{ label: 'a.b.c.d', kind: CompletionItemKind.Value },
Expand Down Expand Up @@ -100,7 +106,7 @@ describe('Can complete database names', () => {
});
});

test("Doesn't suggest existing database names or aliases when createing database", () => {
test("Doesn't suggest existing database names or aliases when creating database", () => {
const query = 'CREATE DATABASE ';

testCompletions({
Expand Down

0 comments on commit 4a9391c

Please sign in to comment.