vscode

package
v0.0.0-...-f07bf43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func BackupFile(path string) error

BackupFile creates a backup of a file by copying it to .bak extension

func ConvertToWorkspacePaths

func ConvertToWorkspacePaths(settings map[string]any, workspaceRoot string) map[string]any

ConvertToWorkspacePaths converts absolute paths to ${workspaceFolder}-relative paths This makes settings portable across machines and team members

func DetectIndentation

func DetectIndentation(content string) int

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

func EscapeJSONKey(key string) string

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

func FilterGoKeys(settings map[string]any) map[string]any

FilterGoKeys returns only the Go-related keys from a settings map

func FindSettingsFile

func FindSettingsFile(dir string) (string, error)

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

func GetUserSettingsPath() (string, error)

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

func HasVSCodeDirectory(dir string) bool

HasVSCodeDirectory checks if a .vscode directory exists in the specified directory

func IsGoRelatedKey

func IsGoRelatedKey(key string) bool

IsGoRelatedKey returns true if the key is a Go or gopls setting

func ReadExistingSettings

func ReadExistingSettings(path string) (map[string]any, error)

ReadExistingSettings reads and parses existing settings.json

func RestoreFromBackup

func RestoreFromBackup(path string) error

RestoreFromBackup restores a file from its .bak backup

func UpdateJSONKeys

func UpdateJSONKeys(path string, keysToUpdate map[string]any) error

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:

  1. No Go library supports true JSONC round-tripping
  2. VS Code itself strips comments/trailing commas when modifying settings via UI
  3. The key order and indentation preservation are more important for readability

func UpdateSettingsForVersion

func UpdateSettingsForVersion(workingDir string, goenvRoot string, version string) error

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

func ValidateSettingsKeys(keys map[string]any) (warnings []string, err error)

ValidateSettingsKeys checks if keys are safe to update and returns warnings for deprecated keys

func WriteJSONFile

func WriteJSONFile(path string, data any) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL