Skip to content

Commit

Permalink
Fixes bug with '(' showing for allShortestPath, ANY, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ncordon committed Oct 17, 2023
1 parent d86dd93 commit 8965010
Showing 1 changed file with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,43 @@ const namespacedCompletion = (
}
};

function getTokenCandidates(candidates: CandidatesCollection) {
function getTokenCandidates(
candidates: CandidatesCollection,
ignoredTokens: Set<number>,
) {
const tokenEntries = candidates.tokens.entries();

const tokenCandidates = Array.from(tokenEntries).flatMap((value) => {
const [tokenNumber, followUpList] = value;

const firstToken = tokenNames[tokenNumber];
const followUpString = followUpList.indexes
.map((i) => tokenNames[i])
.join(' ');
if (!ignoredTokens.has(tokenNumber)) {
const firstToken = tokenNames[tokenNumber];
const followUpIndexes = followUpList.indexes;
const firstIgnoredToken = followUpIndexes.findIndex((t) =>
ignoredTokens.has(t),
);

const followUpTokens = followUpIndexes.slice(
0,
firstIgnoredToken >= 0 ? firstIgnoredToken : followUpIndexes.length,
);

const followUpString = followUpTokens.map((i) => tokenNames[i]).join(' ');

if (firstToken === undefined) {
return [];
} else if (followUpString === '') {
return [firstToken];
} else {
const followUp = firstToken + ' ' + followUpString;
if (followUpList.optional) {
return [firstToken, followUp];
}

if (firstToken === undefined) {
return [];
} else if (followUpString === '') {
return [firstToken];
} else {
const followUp = firstToken + ' ' + followUpString;
if (followUpList.optional) {
return [firstToken, followUp];
return [followUp];
}

return [followUp];
} else {
return [];
}
});

Expand Down Expand Up @@ -292,7 +307,7 @@ export function completionCoreCompletion(
]);

// Keep only keywords as suggestions
codeCompletion.ignoredTokens = new Set<number>(
const ignoredTokens = new Set<number>(
Object.entries(lexerSymbols)
.filter(([, type]) => type !== CypherTokenType.keyword)
.map(([token]) => Number(token)),
Expand Down Expand Up @@ -408,7 +423,7 @@ export function completionCoreCompletion(
},
);

const tokenCandidates = getTokenCandidates(candidates);
const tokenCandidates = getTokenCandidates(candidates, ignoredTokens);
const tokenCompletions: CompletionItem[] = tokenCandidates.map((t) => ({
label: t,
kind: CompletionItemKind.Keyword,
Expand Down

0 comments on commit 8965010

Please sign in to comment.