@@ -5,7 +5,9 @@ export function getDefaultValue() {
55 </script >
66
77<script setup lang="ts">
8- import { computed , ref , watch } from ' vue'
8+ import { computed , ref , watchEffect } from ' vue'
9+ import { capture } from ' @/utils/exception'
10+ import { getCleanupSignal } from ' @/utils/disposable'
911import { UISelect , UISelectOption } from ' @/components/ui'
1012import { stageCodeFilePaths } from ' @/models/spx/stage'
1113import {
@@ -15,7 +17,6 @@ import {
1517 type Property ,
1618 type TextDocument
1719} from ' ../../../xgo-code-editor'
18- import { capture } from ' @/utils/exception'
1920
2021const props = defineProps <{
2122 value: string
@@ -40,34 +41,33 @@ const codeEditor = useCodeEditor()
4041
4142const properties = ref <Property []>([])
4243
43- async function getProperties(textDocument : TextDocument ) {
44+ async function getProperties(textDocument : TextDocument , signal ? : AbortSignal ) {
4445 const codeFilePath = getCodeFilePath (textDocument .id .uri )
4546 const isStage = stageCodeFilePaths .includes (codeFilePath )
46- const stageProperties = await codeEditor .getProperties (' ' )
47+ const stageProperties = await codeEditor .getProperties (' ' , signal )
4748 if (isStage ) {
4849 return stageProperties
4950 }
5051 const spriteName = codeFilePath .replace (/ \. spx$ / , ' ' )
51- const spriteProperties = await codeEditor .getProperties (spriteName )
52+ const spriteProperties = await codeEditor .getProperties (spriteName , signal )
5253 const spritePropertyNames = new Set (spriteProperties .map ((p ) => p .name ))
5354 return [... spriteProperties , ... stageProperties .filter ((p ) => ! spritePropertyNames .has (p .name ))]
5455}
5556
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- )
57+ watchEffect (async (onCleanup ) => {
58+ const textDocument = ui .activeTextDocument
59+ if (textDocument == null ) {
60+ properties .value = []
61+ return
62+ }
63+ const signal = getCleanupSignal (onCleanup )
64+ try {
65+ properties .value = await getProperties (textDocument , signal )
66+ } catch (e ) {
67+ properties .value = []
68+ capture (e , ' Failed to get properties in SpxPropertyNameInput' )
69+ }
70+ })
7171 </script >
7272
7373<template >
0 commit comments