feat: support for predefined variables (#3886)

Co-authored-by: Anwarul Islam <anwaarulislaam@gmail.com>
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Kishan Jadav
2024-09-30 09:47:34 +01:00
committed by jamesgeorge007
parent db8cf229ac
commit e4d9f82a75
14 changed files with 608 additions and 17 deletions

View File

@@ -261,7 +261,7 @@ const clearIcon = refAutoReset<typeof IconTrash2 | typeof IconDone>(
1000
)
const globalVars = useReadonlyStream(globalEnv$, {} as GlobalEnvironment)
const globalEnv = useReadonlyStream(globalEnv$, {} as GlobalEnvironment)
type SelectedEnv = "variables" | "secret"
@@ -319,7 +319,7 @@ const liveEnvs = computed(() => {
}
return [
...vars.value.map((x) => ({ ...x.env, source: editingName.value! })),
...globalVars.value.variables.map((x) => ({ ...x, source: "Global" })),
...globalEnv.value.variables.map((x) => ({ ...x, source: "Global" })),
]
})

View File

@@ -343,6 +343,7 @@ useCodemirror(
linter,
completer: null,
environmentHighlights: true,
predefinedVariablesHighlights: true,
})
)

View File

@@ -161,6 +161,7 @@ useCodemirror(
linter,
completer: null,
environmentHighlights: true,
predefinedVariablesHighlights: true,
})
)

View File

@@ -160,6 +160,7 @@ useCodemirror(
linter: langLinter,
completer: null,
environmentHighlights: true,
predefinedVariablesHighlights: true,
})
)

View File

@@ -234,6 +234,7 @@ useCodemirror(
linter,
completer: null,
environmentHighlights: true,
predefinedVariablesHighlights: true,
})
)

View File

@@ -246,6 +246,7 @@ useCodemirror(
linter,
completer: null,
environmentHighlights: true,
predefinedVariablesHighlights: true,
})
)

View File

@@ -78,6 +78,7 @@ import { clone } from "lodash-es"
import { history, historyKeymap } from "@codemirror/commands"
import { inputTheme } from "~/helpers/editor/themes/baseTheme"
import { HoppReactiveEnvPlugin } from "~/helpers/editor/extensions/HoppEnvironment"
import { HoppPredefinedVariablesPlugin } from "~/helpers/editor/extensions/HoppPredefinedVariables"
import { useReadonlyStream } from "@composables/stream"
import { AggregateEnvironment, aggregateEnvs$ } from "~/newstore/environments"
import { platform } from "~/platform"
@@ -103,6 +104,7 @@ const props = withDefaults(
focus?: boolean
selectTextOnMount?: boolean
environmentHighlights?: boolean
predefinedVariablesHighlights?: boolean
readonly?: boolean
autoCompleteSource?: string[]
inspectionResults?: InspectorResult[] | undefined
@@ -118,6 +120,7 @@ const props = withDefaults(
focus: false,
readonly: false,
environmentHighlights: true,
predefinedVariablesHighlights: true,
autoCompleteSource: undefined,
inspectionResult: undefined,
inspectionResults: undefined,
@@ -396,20 +399,22 @@ function envAutoCompletion(context: CompletionContext) {
info: env?.value ?? "",
apply: env?.key ? `<<${env.key}>>` : "",
}))
.filter((x) => x)
.filter(Boolean)
const nodeBefore = syntaxTree(context.state).resolveInner(context.pos, -1)
const textBefore = context.state.sliceDoc(nodeBefore.from, context.pos)
const tagBefore = /<<\w*$/.exec(textBefore)
const tagBefore = /<<\$?\w*$/.exec(textBefore) // Update regex to match <<$ as well
if (!tagBefore && !context.explicit) return null
return {
from: tagBefore ? nodeBefore.from + tagBefore.index : context.pos,
options: options,
validFor: /^(<<\w*)?$/,
validFor: /^(<<\$?\w*)?$/,
}
}
const envTooltipPlugin = new HoppReactiveEnvPlugin(envVars, view)
const predefinedVariablePlugin = new HoppPredefinedVariablesPlugin()
function handleTextSelection() {
const selection = view.value?.state.selection.main
@@ -490,6 +495,7 @@ const getExtensions = (readonly: boolean): Extension => {
position: "absolute",
}),
props.environmentHighlights ? envTooltipPlugin : [],
props.predefinedVariablesHighlights ? predefinedVariablePlugin : [],
placeholderExt(props.placeholder),
EditorView.domEventHandlers({
paste(ev) {