Skip to content

Commit d4de50c

Browse files
authored
SAM run/debug: webview state fixes #2121
* Fix state issues for all fields
1 parent db3e265 commit d4de50c

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

src/lambda/vue/samInvokeBackend.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export function registerSamInvokeVueCommand(context: ExtContext): vscode.Disposa
6262
command: 'loadSamLaunchConfig',
6363
data: {
6464
launchConfig: launchConfig,
65+
initialCall: true,
6566
},
6667
},
6768
]
@@ -73,11 +74,6 @@ export function registerSamInvokeVueCommand(context: ExtContext): vscode.Disposa
7374
)
7475
}
7576

76-
export interface SamInvokeVueState {
77-
launchConfig: AwsSamDebuggerConfigurationLoose
78-
payload: { value: string; errorMsg: string }
79-
}
80-
8177
export interface AwsSamDebuggerConfigurationLoose extends AwsSamDebuggerConfiguration {
8278
invokeTarget: {
8379
target: 'template' | 'api' | 'code'
@@ -92,6 +88,7 @@ export interface LoadSamLaunchConfigResponse {
9288
command: 'loadSamLaunchConfig'
9389
data: {
9490
launchConfig: AwsSamDebuggerConfiguration
91+
initialCall?: boolean
9592
}
9693
}
9794

src/lambda/vue/samInvokeFrontend.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import { defineComponent } from 'vue'
77
import { WebviewApi } from 'vscode-webview'
88
import { AwsSamDebuggerConfiguration } from '../../shared/sam/debugger/awsSamDebugConfiguration'
9-
import { AwsSamDebuggerConfigurationLoose, SamInvokerResponse, SamInvokeVueState } from './samInvokeBackend'
9+
import { AwsSamDebuggerConfigurationLoose, SamInvokerResponse } from './samInvokeBackend'
1010
import settingsPanel from '../../webviews/components/settingsPanel.vue'
1111

12-
declare const vscode: WebviewApi<SamInvokeVueState>
12+
declare const vscode: WebviewApi<SamInvokeVueData>
1313

1414
interface VueDataLaunchPropertyObject {
1515
value: string
@@ -94,9 +94,12 @@ export default defineComponent({
9494
settingsPanel,
9595
},
9696
created() {
97-
const oldState: Partial<SamInvokeVueState> = vscode.getState() ?? {}
98-
this.launchConfig = oldState.launchConfig ?? this.launchConfig
99-
this.payload = oldState.payload ?? this.payload
97+
const oldState: Partial<SamInvokeVueData> = vscode.getState() ?? {}
98+
99+
const keys = Object.keys(oldState) as [keyof SamInvokeVueData]
100+
keys.forEach(k => {
101+
this.$data[k] = oldState[k] ?? this.$data[k]
102+
})
100103

101104
window.addEventListener('message', ev => {
102105
const event = ev.data as SamInvokerResponse
@@ -113,7 +116,7 @@ export default defineComponent({
113116
this.launchConfig.invokeTarget.templatePath = event.data.template
114117
break
115118
case 'loadSamLaunchConfig':
116-
if (oldState.launchConfig !== undefined) {
119+
if (oldState.launchConfig !== undefined && event.data.initialCall) {
117120
return
118121
}
119122

@@ -143,6 +146,19 @@ export default defineComponent({
143146
}
144147
})
145148

149+
Object.keys(this.$data).forEach(k => {
150+
this.$watch(
151+
k,
152+
(v: any) => {
153+
const old = vscode.getState()
154+
vscode.setState(
155+
Object.assign(old ?? {}, { [k]: JSON.parse(JSON.stringify(v)) }) as SamInvokeVueData
156+
)
157+
},
158+
{ deep: true }
159+
)
160+
})
161+
146162
// Send a message back to let the backend know we're ready for messages
147163
vscode.postMessage({ command: 'initialized' })
148164
},
@@ -167,28 +183,6 @@ export default defineComponent({
167183
stageVariables: { value: '', errorMsg: '' },
168184
}
169185
},
170-
watch: {
171-
launchConfig: {
172-
handler(newval: AwsSamDebuggerConfigurationLoose) {
173-
vscode.setState(
174-
Object.assign(vscode.getState() ?? {}, {
175-
launchConfig: JSON.parse(JSON.stringify(newval)),
176-
} as SamInvokeVueState)
177-
)
178-
},
179-
deep: true,
180-
},
181-
payload: {
182-
handler(newval: { value: string; errorMsg: string }) {
183-
vscode.setState(
184-
Object.assign(vscode.getState() ?? {}, {
185-
payload: JSON.parse(JSON.stringify(newval)),
186-
} as SamInvokeVueState)
187-
)
188-
},
189-
deep: true,
190-
},
191-
},
192186
methods: {
193187
resetJsonErrors() {
194188
this.payload.errorMsg = ''

0 commit comments

Comments
 (0)