@@ -441,23 +441,41 @@ const envVars = computed(() => {
441441})
442442
443443function envAutoCompletion(context : CompletionContext ) {
444- const options = (props .autoCompleteEnvSource ?? envVars .value ?? [])
445- .map ((env ) => ({
446- label: env ?.key ? ` <<${env .key }>> ` : " " ,
447- info: env ?.currentValue ?? " " ,
448- apply: env ?.key ? ` <<${env .key }>> ` : " " ,
449- }))
450- .filter (Boolean )
451-
452444 const nodeBefore = syntaxTree (context .state ).resolveInner (context .pos , - 1 )
453445 const textBefore = context .state .sliceDoc (nodeBefore .from , context .pos )
454- const tagBefore = / <<\$ ? \w * $ / .exec (textBefore ) // Update regex to match <<$ as well
446+ const tagBefore = / <<\$ ? [ A-Za-z0-9 _ . -] * $ / .exec (textBefore ) // Update regex to match <<$ as well
455447
456448 if (! tagBefore && ! context .explicit ) return null
449+
450+ // Check if there's already a closing ">>" after the cursor
451+ const textAfter = context .state .sliceDoc (context .pos , context .pos + 2 )
452+ const hasClosingBrackets = textAfter === " >>"
453+
454+ const options = (props .autoCompleteEnvSource ?? envVars .value ?? [])
455+ .map ((env ) => {
456+ const envKey = env ?.key
457+ if (! envKey ) return null
458+
459+ // If closing brackets already exist, don't include them in the completion
460+ const completionText = hasClosingBrackets
461+ ? ` <<${envKey } `
462+ : ` <<${envKey }>> `
463+
464+ return {
465+ label: ` <<${envKey }>> ` ,
466+ info: env ?.currentValue ?? " " ,
467+ apply: completionText ,
468+ }
469+ })
470+ .filter (
471+ (option ): option is { label: string ; info : string ; apply : string } =>
472+ option !== null
473+ )
474+
457475 return {
458476 from: tagBefore ? nodeBefore .from + tagBefore .index : context .pos ,
459477 options: options ,
460- validFor: / ^ (<<\$ ? \w * )? $ / ,
478+ validFor: / ^ (<<\$ ? [ A-Za-z0-9 _ . -] * )? $ / ,
461479 }
462480}
463481
0 commit comments