Skip to content

Commit 0fe5ce7

Browse files
akoclaude
andcommitted
fix: improve VS Code extension detection on Windows and macOS
findCodeCLI() now checks common install locations when 'code' is not on PATH: - Windows: %LOCALAPPDATA%\Programs\Microsoft VS Code\bin\code.cmd and %ProgramFiles% variants (stable + Insiders) - macOS: /Applications/Visual Studio Code.app/.../bin/code The fallback message when auto-install fails is now a visible box with two install options: the CLI command and the VS Code UI method (Ctrl+Shift+X → Install from VSIX). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5b23aea commit 0fe5ce7

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

cmd/mxcli/init.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"os/exec"
1111
"path/filepath"
12+
"runtime"
1213
"slices"
1314
"strings"
1415

@@ -1163,8 +1164,18 @@ func installVSCodeExtension(projectDir string) {
11631164
// Try to find the VS Code CLI
11641165
codeCLI := findCodeCLI()
11651166
if codeCLI == "" {
1166-
fmt.Printf(" Extracted VS Code extension to .claude/vscode-mdl.vsix\n")
1167-
fmt.Printf(" Install manually: code --install-extension %s\n", vsixPath)
1167+
fmt.Println()
1168+
fmt.Println(" ┌─────────────────────────────────────────────────────────────┐")
1169+
fmt.Println(" │ VS Code MDL extension extracted but could not auto-install │")
1170+
fmt.Println(" │ ('code' command not found on PATH) │")
1171+
fmt.Println(" │ │")
1172+
fmt.Println(" │ To install, either: │")
1173+
fmt.Println(" │ 1. Run in terminal: │")
1174+
fmt.Printf(" │ code --install-extension %s\n", vsixPath)
1175+
fmt.Println(" │ 2. Or in VS Code: Ctrl+Shift+X → ··· → Install from VSIX │")
1176+
fmt.Printf(" │ Select: %s\n", vsixPath)
1177+
fmt.Println(" └─────────────────────────────────────────────────────────────┘")
1178+
fmt.Println()
11681179
return
11691180
}
11701181

@@ -1187,11 +1198,50 @@ func installVSCodeExtension(projectDir string) {
11871198

11881199
// findCodeCLI looks for the VS Code CLI executable.
11891200
func findCodeCLI() string {
1201+
// 1. Check PATH (works on all platforms when VS Code added to PATH)
11901202
for _, name := range []string{"code", "code-insiders"} {
11911203
if path, err := exec.LookPath(name); err == nil {
11921204
return path
11931205
}
11941206
}
1207+
1208+
// 2. Windows: check common install locations
1209+
if runtime.GOOS == "windows" {
1210+
localAppData := os.Getenv("LOCALAPPDATA")
1211+
programFiles := os.Getenv("ProgramFiles")
1212+
candidates := []string{}
1213+
if localAppData != "" {
1214+
candidates = append(candidates,
1215+
filepath.Join(localAppData, "Programs", "Microsoft VS Code", "bin", "code.cmd"),
1216+
filepath.Join(localAppData, "Programs", "Microsoft VS Code Insiders", "bin", "code-insiders.cmd"),
1217+
)
1218+
}
1219+
if programFiles != "" {
1220+
candidates = append(candidates,
1221+
filepath.Join(programFiles, "Microsoft VS Code", "bin", "code.cmd"),
1222+
filepath.Join(programFiles, "Microsoft VS Code Insiders", "bin", "code-insiders.cmd"),
1223+
)
1224+
}
1225+
for _, path := range candidates {
1226+
if _, err := os.Stat(path); err == nil {
1227+
return path
1228+
}
1229+
}
1230+
}
1231+
1232+
// 3. macOS: check standard application path
1233+
if runtime.GOOS == "darwin" {
1234+
candidates := []string{
1235+
"/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code",
1236+
"/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code-insiders",
1237+
}
1238+
for _, path := range candidates {
1239+
if _, err := os.Stat(path); err == nil {
1240+
return path
1241+
}
1242+
}
1243+
}
1244+
11951245
return ""
11961246
}
11971247

0 commit comments

Comments
 (0)