Documentation
¶
Index ¶
- Variables
- func BackupFile(path string) error
- func ConvertToWorkspacePaths(settings map[string]any, workspaceRoot string) map[string]any
- func DetectIndentation(content string) int
- func EscapeJSONKey(key string) string
- func FilterGoKeys(settings map[string]any) map[string]any
- func FindSettingsFile(dir string) (string, error)
- func FixGoExtensionSettings() error
- func GetUserSettingsPath() (string, error)
- func HasVSCodeDirectory(dir string) bool
- func IsGoRelatedKey(key string) bool
- func ReadExistingSettings(path string) (map[string]any, error)
- func RestoreFromBackup(path string) error
- func UpdateJSONKeys(path string, keysToUpdate map[string]any) error
- func UpdateSettingsForVersion(workingDir string, goenvRoot string, version string) error
- func ValidateSettingsKeys(keys map[string]any) (warnings []string, err error)
- func WriteJSONFile(path string, data any) error
- type CheckResult
- type Extensions
- type GoExtensionIssue
Constants ¶
This section is empty.
Variables ¶
var DeprecatedKeys = map[string]string{
"go.useLanguageServer": "Removed in Go extension v0.30.0+. gopls is now the default and only supported language server.",
"go.languageServerExperimentalFeatures": "Deprecated. Individual gopls features are now stable and enabled by default.",
"go.useCodeSnippetsOnFunctionSuggest": "Deprecated. Use gopls.ui.completion.usePlaceholders instead.",
}
DeprecatedKeys lists keys that should trigger warnings
Functions ¶
func BackupFile ¶
BackupFile creates a backup of a file by copying it to .bak extension
func ConvertToWorkspacePaths ¶
ConvertToWorkspacePaths converts absolute paths to ${workspaceFolder}-relative paths This makes settings portable across machines and team members
func DetectIndentation ¶
DetectIndentation detects the indentation width from a JSON file Returns the number of spaces used for indentation (defaults to 2 if can't detect)
func EscapeJSONKey ¶
EscapeJSONKey escapes dots in a key name for sjson sjson treats dots as path separators, so "go.goroot" becomes nested We need to escape dots with backslashes: "go\.goroot"
func FilterGoKeys ¶
FilterGoKeys returns only the Go-related keys from a settings map
func FindSettingsFile ¶
FindSettingsFile returns the path to VS Code settings.json in the current or specified directory
func FixGoExtensionSettings ¶
func FixGoExtensionSettings() error
FixGoExtensionSettings configures VS Code Go extension to work with goenv This prevents the extension from injecting stale Go paths into terminal PATH
func GetUserSettingsPath ¶
GetUserSettingsPath returns the path to VS Code user settings.json This varies by platform and is where global VS Code settings are stored
func HasVSCodeDirectory ¶
HasVSCodeDirectory checks if a .vscode directory exists in the specified directory
func IsGoRelatedKey ¶
IsGoRelatedKey returns true if the key is a Go or gopls setting
func ReadExistingSettings ¶
ReadExistingSettings reads and parses existing settings.json
func RestoreFromBackup ¶
RestoreFromBackup restores a file from its .bak backup
func UpdateJSONKeys ¶
UpdateJSONKeys updates specific keys in a JSON file while preserving key order
Behavior:
- Preserves the order of existing keys
- Updates only the specified keys
- Adds new keys at the end if they don't exist
- Detects and preserves original indentation (2 or 4 spaces)
- Strips JSONC features (comments, trailing commas)
- May reformat arrays to single line if short
Note: Some formatting changes occur because:
- No Go library supports true JSONC round-tripping
- VS Code itself strips comments/trailing commas when modifying settings via UI
- The key order and indentation preservation are more important for readability
func UpdateSettingsForVersion ¶
UpdateSettingsForVersion updates VS Code settings for a specific Go version This function is designed to be called from workflows and automation without cobra dependencies Returns nil if successful, error otherwise
func ValidateSettingsKeys ¶
ValidateSettingsKeys checks if keys are safe to update and returns warnings for deprecated keys
func WriteJSONFile ¶
WriteJSONFile writes a JSON file with proper formatting Detects and preserves existing indentation and trailing newlines if file exists Defaults to 2 spaces and single trailing newline for new files
Types ¶
type CheckResult ¶
type CheckResult struct {
// HasSettings indicates if any go.* settings exist
HasSettings bool
// UsesEnvVars indicates if settings use ${env:GOROOT} pattern
UsesEnvVars bool
// ConfiguredVersion is the version detected from absolute paths (empty if using env vars)
ConfiguredVersion string
// Mismatch indicates if the configured version doesn't match expected
Mismatch bool
// ExpectedVersion is the version that should be configured
ExpectedVersion string
// SettingsPath is the path to the settings.json file
SettingsPath string
}
CheckResult contains the result of a VS Code settings check
func CheckSettings ¶
func CheckSettings(settingsPath string, expectedVersion string) CheckResult
CheckSettings examines VS Code settings.json and validates Go configuration Returns a CheckResult with detailed information about the VS Code integration status
type Extensions ¶
type Extensions struct {
Recommendations []string `json:"recommendations"`
}
Extensions represents the VS Code extensions.json structure
func ReadExistingExtensions ¶
func ReadExistingExtensions(path string) (*Extensions, error)
ReadExistingExtensions reads and parses existing extensions.json
type GoExtensionIssue ¶
type GoExtensionIssue struct {
// Found indicates if the Go extension settings were detected
Found bool
// HasPathInjection indicates if go.goroot or go.gopath are set to specific paths
// This causes PATH injection that bypasses goenv
HasPathInjection bool
// HasAlternateTools indicates if go.alternateTools.go is configured
HasAlternateTools bool
// AlternateToolValue is the value of go.alternateTools.go (e.g., "goenv exec go")
AlternateToolValue string
// SettingsPath is the path to the user settings file
SettingsPath string
}
GoExtensionIssue represents a problem with Go extension configuration
func CheckGoExtensionSettings ¶
func CheckGoExtensionSettings() (GoExtensionIssue, error)
CheckGoExtensionSettings checks if VS Code Go extension is properly configured Returns information about potential PATH injection issues