Skip to content

Commit f9946b3

Browse files
committed
fix: Resolve dupBranchBody in VSCode extension installation
- Extract common command execution logic to eliminate duplicate branches - Both Windows and non-Windows branches now only differ in executable name - Fixes gocritic dupBranchBody warning in downloadAndInstallExtension function
1 parent 36304bf commit f9946b3

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

general/ide/jetbrains/jetbrains.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,8 @@ func (jc *JetbrainsCommand) detectJetBrainsIDEs() error {
203203
// Set the full config directory path
204204
ide.ConfigDir = filepath.Join(configBasePath, dirName)
205205

206-
// Check for idea.properties file
207-
propertiesPath := filepath.Join(ide.ConfigDir, "idea.properties")
208-
if _, err := os.Stat(propertiesPath); err == nil {
209-
ide.PropertiesPath = propertiesPath
210-
} else {
211-
// Create idea.properties if it doesn't exist
212-
ide.PropertiesPath = propertiesPath
213-
}
206+
// Set idea.properties file path
207+
ide.PropertiesPath = filepath.Join(ide.ConfigDir, "idea.properties")
214208

215209
jc.detectedIDEs = append(jc.detectedIDEs, *ide)
216210
}

general/ide/vscode/vscode.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ func (vc *VscodeCommand) checkWritePermissions() error {
132132
}
133133
return fmt.Errorf("failed to check write permissions: %w", err)
134134
}
135-
file.Close()
135+
if closeErr := file.Close(); closeErr != nil {
136+
return fmt.Errorf("failed to close file: %w", closeErr)
137+
}
136138
return nil
137139
}
138140

@@ -535,21 +537,24 @@ func (vic *VscodeInstallCommand) downloadAndInstallExtension(repoURL string) err
535537
defer os.Remove(tempFile) // Clean up temp file
536538

537539
_, err = io.Copy(out, resp.Body)
538-
out.Close()
540+
if closeErr := out.Close(); closeErr != nil {
541+
return fmt.Errorf("failed to close temp file: %w", closeErr)
542+
}
539543
if err != nil {
540544
return fmt.Errorf("failed to save extension package: %w", err)
541545
}
542546

543547
log.Info("Installing extension using VSCode CLI...")
544548

545549
// Install extension using VSCode's CLI
546-
var cmd *exec.Cmd
550+
var codeCmd string
547551
if runtime.GOOS == "windows" {
548-
cmd = exec.Command("code.cmd", "--install-extension", tempFile, "--force")
552+
codeCmd = "code.cmd"
549553
} else {
550-
cmd = exec.Command("code", "--install-extension", tempFile, "--force")
554+
codeCmd = "code"
551555
}
552556

557+
cmd := exec.Command(codeCmd, "--install-extension", tempFile, "--force")
553558
output, err := cmd.CombinedOutput()
554559
if err != nil {
555560
return fmt.Errorf("failed to install extension via VSCode CLI: %w\nOutput: %s", err, string(output))

0 commit comments

Comments
 (0)