Skip to content

Commit 897a11a

Browse files
committed
fix: resolve MCP server connection race condition in getTheme.ts
- Create local copy of vscode.extensions.all to avoid read-only property conflicts - Add defensive null checking for extension and packageJSON - Resolves race condition between MCP initialization and theme loading - Reapplies fix from automatically closed PR #5592 Fixes #5591
1 parent a6e16e8 commit 897a11a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/integrations/theme/getTheme.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ export async function getTheme() {
3737
const colorTheme = vscode.workspace.getConfiguration("workbench").get<string>("colorTheme") || "Default Dark Modern"
3838

3939
try {
40-
for (let i = vscode.extensions.all.length - 1; i >= 0; i--) {
40+
// Create a local copy of the extensions array to avoid potential conflicts with the read-only property
41+
const extensions = [...vscode.extensions.all]
42+
43+
for (let i = extensions.length - 1; i >= 0; i--) {
4144
if (currentTheme) {
4245
break
4346
}
44-
const extension = vscode.extensions.all[i]
45-
if (extension.packageJSON?.contributes?.themes?.length > 0) {
47+
const extension = extensions[i]
48+
// Add null check for extension and packageJSON
49+
if (extension?.packageJSON?.contributes?.themes?.length > 0) {
4650
for (const theme of extension.packageJSON.contributes.themes) {
4751
if (theme.label === colorTheme) {
4852
const themePath = path.join(extension.extensionPath, theme.path)

0 commit comments

Comments
 (0)