Skip to content

Commit 335c2b8

Browse files
committed
support spx-property-name input type in InputHelper
1 parent 844d161 commit 335c2b8

File tree

6 files changed

+119
-18
lines changed

6 files changed

+119
-18
lines changed

spx-gui/src/components/editor/code-editor/spx-code-editor/common.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ export enum SpxInputType {
203203
SpxSpecialObj = 'spx-special-obj',
204204
/** `RotationStyle` in spx */
205205
SpxRotationStyle = 'spx-rotation-style',
206+
/** Property name values in spx */
207+
SpxPropertyName = 'spx-property-name',
206208
/** Unknown type */
207209
Unknown = XGoBuiltInInputType.Unknown
208210
}
@@ -240,6 +242,11 @@ export type SpxInputTypedValue =
240242
/** Name of `RotationStyle` in spx, e.g., `Normal` */
241243
value: string
242244
}
245+
| {
246+
type: SpxInputType.SpxPropertyName
247+
/** Property name of spx stage/sprite */
248+
value: string
249+
}
243250

244251
export type InputValueForSpxType<T> = (SpxInputTypedValue & { type: T })['value']
245252

spx-gui/src/components/editor/code-editor/spx-code-editor/input-helper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import SpxKeyInput, * as spxKeyInput from './ui/input-helper/SpxKeyInput.vue'
3737
import SpxPlayActionInput, * as spxPlayActionInput from './ui/input-helper/SpxPlayActionInput.vue'
3838
import SpxSpecialObjInput, * as spxSpecialObjInput from './ui/input-helper/SpxSpecialObjInput.vue'
3939
import SpxRotationStyleInput, * as spxRotationStyleInput from './ui/input-helper/SpxRotationStyleInput.vue'
40+
import SpxPropertyNameInput, * as spxPropertyNameInput from './ui/input-helper/SpxPropertyNameInput.vue'
4041

4142
export class SpxInputHelperProvider extends InputHelperProvider {
4243
constructor(lspClient: SpxLSPClient, resourceProvider: IResourceProvider) {
@@ -135,6 +136,16 @@ export class SpxInputHelperProvider extends InputHelperProvider {
135136
return input.value as InputValueForSpxType<SpxInputType.SpxRotationStyle>
136137
}
137138
} satisfies InputTypeHandler<string>
139+
case SpxInputType.SpxPropertyName:
140+
return {
141+
component: SpxPropertyNameInput,
142+
getTitle: () => ({ en: 'Select a property', zh: '选择属性' }),
143+
getDefaultValue: spxPropertyNameInput.getDefaultValue,
144+
exprForInput: (input: InPlaceInput) => {
145+
if (input.type !== SpxInputType.SpxPropertyName) return null
146+
return JSON.stringify(input.value as InputValueForSpxType<SpxInputType.SpxPropertyName>)
147+
}
148+
} satisfies InputTypeHandler<string>
138149
default:
139150
return super.provideInputTypeHandler(type)
140151
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<script lang="ts">
2+
export function getDefaultValue() {
3+
return ''
4+
}
5+
</script>
6+
7+
<script setup lang="ts">
8+
import { computed, ref, watch } from 'vue'
9+
import { UISelect, UISelectOption } from '@/components/ui'
10+
import { stageCodeFilePaths } from '@/models/spx/stage'
11+
import {
12+
useCodeEditor,
13+
useCodeEditorUICtx,
14+
getCodeFilePath,
15+
type Property,
16+
type TextDocument
17+
} from '../../../xgo-code-editor'
18+
import { capture } from '@/utils/exception'
19+
20+
const props = defineProps<{
21+
value: string
22+
}>()
23+
24+
const emit = defineEmits<{
25+
'update:value': [string]
26+
submit: []
27+
}>()
28+
29+
const modelValue = computed({
30+
get() {
31+
return props.value
32+
},
33+
set(name) {
34+
emit('update:value', name)
35+
}
36+
})
37+
38+
const { ui } = useCodeEditorUICtx()
39+
const codeEditor = useCodeEditor()
40+
41+
const properties = ref<Property[]>([])
42+
43+
async function getProperties(textDocument: TextDocument) {
44+
const codeFilePath = getCodeFilePath(textDocument.id.uri)
45+
const isStage = stageCodeFilePaths.includes(codeFilePath)
46+
const stageProperties = await codeEditor.getProperties('')
47+
if (isStage) {
48+
return stageProperties
49+
}
50+
const spriteName = codeFilePath.replace(/\.spx$/, '')
51+
const spriteProperties = await codeEditor.getProperties(spriteName)
52+
const spritePropertyNames = new Set(spriteProperties.map((p) => p.name))
53+
return [...spriteProperties, ...stageProperties.filter((p) => !spritePropertyNames.has(p.name))]
54+
}
55+
56+
watch(
57+
() => ui.activeTextDocument,
58+
async (textDocument) => {
59+
if (textDocument == null) {
60+
properties.value = []
61+
return
62+
}
63+
try {
64+
properties.value = await getProperties(textDocument)
65+
} catch (e) {
66+
capture(e, 'Failed to get properties in SpxPropertyNameInput')
67+
}
68+
},
69+
{ immediate: true }
70+
)
71+
</script>
72+
73+
<template>
74+
<UISelect v-model:value="modelValue" :style="{ alignSelf: 'stretch' }">
75+
<UISelectOption v-for="property in properties" :key="property.name" :value="property.name">
76+
{{ property.name }}
77+
</UISelectOption>
78+
</UISelect>
79+
</template>

spx-gui/src/components/editor/code-editor/xgo-code-editor/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export * from './resource'
2323
export * from './snippet-variables'
2424

2525
// Vue components
26-
export { default as CodeEditorUI } from './ui/CodeEditorUI.vue'
26+
export { default as CodeEditorUI, useCodeEditorUICtx } from './ui/CodeEditorUI.vue'
2727
export { default as CodeEditorCard } from './ui/CodeEditorCard.vue'
2828
export { default as ResourceInput } from './ui/input-helper/ResourceInput.vue'
2929

tools/spxls/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ tool github.com/goplus/xgolsw/cmd/pkgdatagen
66

77
require (
88
github.com/goplus/builder/tools/ai v0.0.0
9-
github.com/goplus/xgolsw v0.16.2
9+
github.com/goplus/xgolsw v0.16.3-0.20260319085954-624ae868cdf5
1010
)
1111

1212
require (
1313
github.com/goplus/gogen v1.21.2 // indirect
14-
github.com/goplus/mod v0.19.5 // indirect
14+
github.com/goplus/mod v0.19.6 // indirect
1515
github.com/goplus/spbase v0.1.0 // indirect
16-
github.com/goplus/spx/v2 v2.0.0-pre.47 // indirect
16+
github.com/goplus/spx/v2 v2.0.0-pre.47.0.20260317084052-07546096faba // indirect
1717
github.com/goplus/xgo v1.6.6 // indirect
1818
github.com/petermattis/goid v0.0.0-20250721140440-ea1c0173183e // indirect
19-
github.com/qiniu/x v1.16.3 // indirect
19+
github.com/qiniu/x v1.16.5 // indirect
2020
golang.org/x/image v0.23.0 // indirect
2121
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd // indirect
22-
golang.org/x/mod v0.33.0 // indirect
22+
golang.org/x/mod v0.34.0 // indirect
2323
golang.org/x/sync v0.20.0 // indirect
24-
golang.org/x/text v0.34.0 // indirect
25-
golang.org/x/tools v0.42.0 // indirect
24+
golang.org/x/text v0.35.0 // indirect
25+
golang.org/x/tools v0.43.0 // indirect
2626
)
2727

2828
replace github.com/goplus/builder/tools/ai => ../ai

tools/spxls/go.sum

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
55
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
66
github.com/goplus/gogen v1.21.2 h1:xbXPgZOZiQx/WBM0nZxVSxFbtdCMZCRB+lguDnh8pfs=
77
github.com/goplus/gogen v1.21.2/go.mod h1:Y7ulYW3wonQ3d9er00b0uGFEV/IUZa6okWJZh892ACQ=
8-
github.com/goplus/mod v0.19.5 h1:36sbRxKie2Or9aSfWT06X6WV37sBwARXYfKfGfHzEQs=
9-
github.com/goplus/mod v0.19.5/go.mod h1:T6Ta3xPXx8NQaRb8h632P5iBgIB77zXfh9vLNRFqMqk=
8+
github.com/goplus/mod v0.19.6 h1:o00M6mN/rQ06cGDdH8xSHdL3xiZJXom6AUmwpOTBZ84=
9+
github.com/goplus/mod v0.19.6/go.mod h1:UnoI3xX5LbUu5TFwOhVRpwOBHSH//s7yqWNIbXpzpRA=
1010
github.com/goplus/spbase v0.1.0 h1:JNZ0D/65DerYyv9/9IfrXHZZbd0WNK0jHiVvgCtZhwY=
1111
github.com/goplus/spbase v0.1.0/go.mod h1:brnD3OJnHtipqob2IsJ3/QzGBf+eOnqXNnHGKpv1irQ=
1212
github.com/goplus/spx/v2 v2.0.0-pre.47 h1:VzGuN++kfLrNUbn6lxmNKI8Mn1UgBEsOfFfV1PrP7eQ=
1313
github.com/goplus/spx/v2 v2.0.0-pre.47/go.mod h1:oP0YVzWNrczCyyO8qjYyni5sV4wJ3sqVkjCmc+P6jBo=
14+
github.com/goplus/spx/v2 v2.0.0-pre.47.0.20260317084052-07546096faba h1:zMrw0i0jSaoLmvaFQT/DMGRSB32Q+yBYsGt99gqwkVU=
15+
github.com/goplus/spx/v2 v2.0.0-pre.47.0.20260317084052-07546096faba/go.mod h1:oP0YVzWNrczCyyO8qjYyni5sV4wJ3sqVkjCmc+P6jBo=
1416
github.com/goplus/xgo v1.6.6 h1:gfFoGYnyGfImt1aFEkK55TQTzNUDZQYDlWq9mRr3ors=
1517
github.com/goplus/xgo v1.6.6/go.mod h1:7ViCaG6azWTPIxxvXPtkod7J13IO06qKWHJSaQ2nqvY=
1618
github.com/goplus/xgolsw v0.16.2 h1:WlSFVH1jYwYQT/CglXMkwJ1PnUKtrSO9Nc+E7jZIoVk=
1719
github.com/goplus/xgolsw v0.16.2/go.mod h1:qWCUhCwSUDo3MamTySd4TQ1MqrQuie9qgySIC4r5roM=
20+
github.com/goplus/xgolsw v0.16.3-0.20260319085954-624ae868cdf5 h1:3sLaUb/w4SUsjtdHOo2eX9Z8JVfxYIL4gMuUkiv3Ocg=
21+
github.com/goplus/xgolsw v0.16.3-0.20260319085954-624ae868cdf5/go.mod h1:R61Je+Ps3trGmRV1pambjv0o0PUfHD5MRnNL6G+GC88=
1822
github.com/petermattis/goid v0.0.0-20250721140440-ea1c0173183e h1:D0bJD+4O3G4izvrQUmzCL80zazlN7EwJ0PPDhpJWC/I=
1923
github.com/petermattis/goid v0.0.0-20250721140440-ea1c0173183e/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
2024
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2125
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
22-
github.com/qiniu/x v1.16.3 h1:UftZPVh4n4M5qqdqTg2TlnhDATVn5rGsp9v7FxHwN4g=
23-
github.com/qiniu/x v1.16.3/go.mod h1:AiovSOCaRijaf3fj+0CBOpR1457pn24b0Vdb1JpwhII=
26+
github.com/qiniu/x v1.16.5 h1:+/cSm9m8F8sx6zJ4ylmsuhux8xVpxMHP/pzL8xv1Y9w=
27+
github.com/qiniu/x v1.16.5/go.mod h1:AiovSOCaRijaf3fj+0CBOpR1457pn24b0Vdb1JpwhII=
2428
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
2529
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
2630
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
@@ -37,8 +41,8 @@ golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd h1:x1GptNaTtxPAlTVIAJk61f
3741
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
3842
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
3943
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
40-
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
41-
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
44+
golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI=
45+
golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY=
4246
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
4347
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
4448
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -55,14 +59,14 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc
5559
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
5660
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
5761
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
58-
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
59-
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
62+
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
63+
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
6064
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
6165
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
6266
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
6367
golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
64-
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
65-
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
68+
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s=
69+
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
6670
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6771
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6872
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

0 commit comments

Comments
 (0)