Compare commits

...

3 Commits

Author SHA1 Message Date
ahrefabhi
4120b53c27 fix: remove unused function call in getCurrentQueryPair 2025-07-10 22:26:47 +05:30
ahrefabhi
a7cbfe4587 fix: enhance context detection after closing parenthesis in query 2025-07-10 22:25:33 +05:30
ahrefabhi
74d480e113 fix: fixed context for query in parenthesis 2025-07-10 21:18:54 +05:30

View File

@@ -718,7 +718,6 @@ export function getQueryContextAtCursor(
isInValueBoundary ||
isInConjunctionBoundary ||
isInBracketListBoundary ||
isInParenthesisBoundary ||
isAfterClosingBracketList
) {
// Extract information from the current pair (if available)
@@ -968,6 +967,30 @@ export function getQueryContextAtCursor(
currentPair: currentPair,
};
}
if (
lastTokenContext.isInParenthesis &&
lastTokenBeforeCursor.type === FilterQueryLexer.RPAREN
) {
// If we are after a parenthesis we should enter the conjunction context.
return {
tokenType: lastTokenBeforeCursor.type,
text: lastTokenBeforeCursor.text,
start: adjustedCursorIndex,
stop: adjustedCursorIndex,
currentToken: lastTokenBeforeCursor.text,
isInKey: false,
isInNegation: false,
isInOperator: false,
isInValue: false,
isInFunction: false,
isInConjunction: true, // After RPARAN + space, should be conjunction context
isInParenthesis: false,
isInBracketList: false,
queryPairs: queryPairs,
currentPair: currentPair,
};
}
}
// FIXED: Consider the case where the cursor is at the end of a token
@@ -1454,6 +1477,19 @@ export function extractQueryPairs(query: string): IQueryPair[] {
}
}
function getIndexTillSpace(pair: IQueryPair, query: string): number {
const { position } = pair;
let pairEnd = position.valueEnd || position.operatorEnd || position.keyEnd;
// Start from the next index after pairEnd
pairEnd += 1;
while (pairEnd < query.length && query.charAt(pairEnd) === ' ') {
pairEnd += 1;
}
return pairEnd;
}
/**
* Gets the current query pair at the cursor position
* This is useful for getting suggestions based on the current context
@@ -1483,12 +1519,14 @@ export function getCurrentQueryPair(
position.valueEnd || position.operatorEnd || position.keyEnd;
const pairStart =
position.keyStart || position.operatorStart || position.valueStart || 0;
position.keyStart ?? (position.operatorStart || position.valueStart || 0);
// If this pair ends at or before the cursor, and it's further right than our previous best match
if (
pairEnd >= cursorIndex &&
pairStart <= cursorIndex &&
((pairEnd >= cursorIndex && pairStart <= cursorIndex) ||
(!pair.isComplete &&
pairStart <= cursorIndex &&
getIndexTillSpace(pair, query) >= cursorIndex)) &&
(!bestMatch ||
pairEnd >
(bestMatch.position.valueEnd ||