Skip to content

Commit

Permalink
Make it so it doesn't add comma when completing an arg from a snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Aug 30, 2024
1 parent cfa7363 commit abcaab4
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ export async function suggest(
astContext,
getFieldsByType,
getFieldsMap,
getPolicyMetadata
getPolicyMetadata,
fullText,
offset
);
}
if (astContext.type === 'list') {
Expand Down Expand Up @@ -1258,7 +1260,9 @@ async function getFunctionArgsSuggestions(
},
getFieldsByType: GetFieldsByTypeFn,
getFieldsMap: GetFieldsMapFn,
getPolicyMetadata: GetPolicyMetadataFn
getPolicyMetadata: GetPolicyMetadataFn,
fullText: string,
offset: number
): Promise<SuggestionRawDefinition[]> {
const fnDefinition = getFunctionDefinition(node.name);
// early exit on no hit
Expand Down Expand Up @@ -1314,9 +1318,11 @@ async function getFunctionArgsSuggestions(
// no need to suggest comma
.some((p) => p === null || p?.optional === true);

// Wehther to prepend comma to suggestion string
// Whether to prepend comma to suggestion string
// E.g. if true, "fieldName" -> "fieldName, "
const shouldAddComma = hasMoreMandatoryArgs && fnDefinition.type !== 'builtin';
const alreadyHasComma = fullText ? fullText[offset] === ',' : false;
const shouldAddComma =
hasMoreMandatoryArgs && fnDefinition.type !== 'builtin' && !alreadyHasComma;

const suggestedConstants = uniq(
typesToSuggestNext
Expand Down Expand Up @@ -1777,11 +1783,8 @@ async function getOptionArgsSuggestions(
defaultMessage: 'Add date histogram using bucket()',
}
),
documentation: {
value: '',
},
sortText: '1A',
});
} as SuggestionRawDefinition);
}

suggestions.push(
Expand Down

0 comments on commit abcaab4

Please sign in to comment.