Skip to content

Commit 4efe86f

Browse files
fix: support dots/dashes in environment variable autocomplete (hoppscotch#5630)
Co-authored-by: Anwarul Islam <[email protected]>
1 parent aed0323 commit 4efe86f

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

packages/hoppscotch-common/src/components/smart/EnvInput.vue

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,23 +441,41 @@ const envVars = computed(() => {
441441
})
442442
443443
function 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

Comments
 (0)