Skip to content

Commit e696d45

Browse files
committed
add template functions autocomplation
1 parent a03a5c2 commit e696d45

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

console/atest-ui/package-lock.json

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console/atest-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"test": "vitest"
1717
},
1818
"dependencies": {
19+
"@codemirror/lang-json": "^6.0.2",
1920
"@codemirror/lang-sql": "github:codemirror/lang-sql",
2021
"@vueuse/core": "^10.11.0",
2122
"codemirror": "^5.65.17",

console/atest-ui/src/assets/base.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
--page-title-bottom-padding: 5px;
4545

4646
--sql-editor-height: 180px;
47+
--payload-editor-height: 180px;
4748
}
4849

4950
*,

console/atest-ui/src/assets/main.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#app {
44
margin: 0 auto;
5-
{{/* padding-top: 40px; */}}
65
height: 100vh;
76
font-weight: normal;
87
}

console/atest-ui/src/views/TestCase.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import { Codemirror } from 'vue-codemirror'
1919
import jsonlint from 'jsonlint-mod'
2020
2121
import CodeMirror from 'codemirror'
22+
import { json, jsonLanguage } from "@codemirror/lang-json"
23+
import { LanguageSupport } from "@codemirror/language"
24+
import { CompletionContext } from "@codemirror/autocomplete"
25+
import type { Completion } from "@codemirror/autocomplete"
2226
import 'codemirror/lib/codemirror.css'
2327
import 'codemirror/addon/merge/merge.js'
2428
import 'codemirror/addon/merge/merge.css'
@@ -30,6 +34,36 @@ window.DIFF_DELETE = -1;
3034
window.DIFF_INSERT = 1;
3135
window.DIFF_EQUAL = 0;
3236
37+
const templateFuncs = ref([] as Completion[])
38+
function myCompletions(context: CompletionContext) {
39+
if (templateFuncs.value.length == 0) {
40+
API.FunctionsQuery("", "template", (e) => {
41+
if (e.data) {
42+
e.data.forEach((item: any) => {
43+
templateFuncs.value.push({
44+
label: item.key,
45+
type: "text",
46+
} as Completion)
47+
})
48+
}
49+
})
50+
}
51+
52+
let word = context.matchBefore(/\w*/) || {
53+
from: "",
54+
to: ""
55+
}
56+
if (word.from == word.to && !context.explicit)
57+
return null
58+
return {
59+
from: word.from,
60+
options: templateFuncs.value
61+
}
62+
}
63+
const jsonComplete = new LanguageSupport(jsonLanguage, jsonLanguage.data.of(
64+
{autocomplete: myCompletions}
65+
))
66+
3367
const { t } = useI18n()
3468
3569
const props = defineProps({
@@ -1141,6 +1175,8 @@ Magic.AdvancedKeys([{
11411175
<Codemirror v-if="bodyType === 3 || bodyType === 5 || bodyType === 6"
11421176
@blur="jsonFormat(-1)"
11431177
v-model="testCaseWithSuite.data.request.body"
1178+
style="height: var(--payload-editor-height);"
1179+
:extensions="[json(), jsonComplete]"
11441180
:disabled="isHistoryTestCase"/>
11451181
<el-table :data="testCaseWithSuite.data.request.form" style="width: 100%" v-if="bodyType === 4">
11461182
<el-table-column label="Key" width="180">

0 commit comments

Comments
 (0)