@@ -85,7 +85,7 @@ export interface LanguageServerConfig {
8585 modtime ?: Date ;
8686 enabled : boolean ;
8787 flags : string [ ] ;
88- env : any ;
88+ env : NodeJS . ProcessEnv ;
8989 features : {
9090 // A custom formatter can be configured to run instead of gopls.
9191 // This is enabled when the user has configured a specific format
@@ -95,6 +95,12 @@ export interface LanguageServerConfig {
9595 checkForUpdates : string ;
9696}
9797
98+ /**
99+ * Represents a configuration object for gopls or Go settings.
100+ * This is a flexible object that can contain any configuration key-value pairs.
101+ */
102+ export type ConfigurationObject = { [ key : string ] : unknown } ;
103+
98104export interface ServerInfo {
99105 Name : string ;
100106 Version ?: string ;
@@ -382,8 +388,27 @@ type VulncheckEvent = {
382388 message ?: string ;
383389} ;
384390
385- // buildLanguageClient returns a language client built using the given language server config.
386- // The returned language client need to be started before use.
391+ /**
392+ * Builds a VS Code Language Server Protocol (LSP) client for gopls.
393+ * The returned client is configured but not started - caller must call .start() on it.
394+ *
395+ * This function sets up:
396+ * - Output channels for server logs and traces
397+ * - Language server executable options (path, flags, environment)
398+ * - Client options (document selectors, middleware, synchronization)
399+ * - Progress handlers for gopls operations
400+ * - Command execution middleware
401+ * - Configuration synchronization with gopls
402+ *
403+ * @param goCtx - Go extension context containing output channels and state
404+ * @param cfg - Language server configuration with path, flags, and features
405+ * @returns Configured GoLanguageClient instance ready to be started
406+ *
407+ * @example
408+ * const cfg = await buildLanguageServerConfig(getGoConfig());
409+ * const client = await buildLanguageClient(goCtx, cfg);
410+ * await client.start(); // Start the language server
411+ */
387412export async function buildLanguageClient (
388413 goCtx : GoExtensionContext ,
389414 cfg : LanguageServerConfig
@@ -408,7 +433,7 @@ export async function buildLanguageClient(
408433
409434 // TODO(hxjiang): deprecate special handling for async call gopls.run_govulncheck.
410435 let govulncheckTerminal : IProgressTerminal | undefined ;
411- const pendingVulncheckProgressToken = new Map < ProgressToken , any > ( ) ;
436+ const pendingVulncheckProgressToken = new Map < ProgressToken , { URI : string } > ( ) ;
412437 const onDidChangeVulncheckResultEmitter = new vscode . EventEmitter < VulncheckEvent > ( ) ;
413438
414439 // VSCode-Go prepares the information needed to start the language server.
@@ -850,12 +875,12 @@ export async function buildLanguageClient(
850875// and selects only those the user explicitly specifies in their settings.
851876// This returns a new object created based on the filtered properties of workspaceConfig.
852877// Exported for testing.
853- export function filterGoplsDefaultConfigValues ( workspaceConfig : any , resource ?: vscode . Uri ) : any {
878+ export function filterGoplsDefaultConfigValues ( workspaceConfig : ConfigurationObject , resource ?: vscode . Uri ) : ConfigurationObject {
854879 if ( ! workspaceConfig ) {
855880 workspaceConfig = { } ;
856881 }
857882 const cfg = getGoplsConfig ( resource ) ;
858- const filtered = { } as { [ key : string ] : any } ;
883+ const filtered : ConfigurationObject = { } ;
859884 for ( const [ key , value ] of Object . entries ( workspaceConfig ) ) {
860885 if ( typeof value === 'function' ) {
861886 continue ;
@@ -888,7 +913,7 @@ export function filterGoplsDefaultConfigValues(workspaceConfig: any, resource?:
888913// - go.buildTags and go.buildFlags are passed as gopls.build.buildFlags
889914// if goplsWorkspaceConfig doesn't explicitly set it yet.
890915// Exported for testing.
891- export function passGoConfigToGoplsConfigValues ( goplsWorkspaceConfig : any , goWorkspaceConfig : any ) : any {
916+ export function passGoConfigToGoplsConfigValues ( goplsWorkspaceConfig : ConfigurationObject , goWorkspaceConfig : ConfigurationObject ) : ConfigurationObject {
892917 if ( ! goplsWorkspaceConfig ) {
893918 goplsWorkspaceConfig = { } ;
894919 }
@@ -913,10 +938,10 @@ export function passGoConfigToGoplsConfigValues(goplsWorkspaceConfig: any, goWor
913938// If this is for the nightly extension, we also request to activate features under experiments.
914939async function adjustGoplsWorkspaceConfiguration (
915940 cfg : LanguageServerConfig ,
916- workspaceConfig : any ,
941+ workspaceConfig : ConfigurationObject ,
917942 section ?: string ,
918943 resource ?: vscode . Uri
919- ) : Promise < any > {
944+ ) : Promise < ConfigurationObject > {
920945 // We process only gopls config
921946 if ( section !== 'gopls' ) {
922947 return workspaceConfig ;
@@ -940,7 +965,7 @@ async function adjustGoplsWorkspaceConfiguration(
940965 return workspaceConfig ;
941966}
942967
943- async function passInlayHintConfigToGopls ( cfg : LanguageServerConfig , goplsConfig : any , goConfig : any ) {
968+ async function passInlayHintConfigToGopls ( cfg : LanguageServerConfig , goplsConfig : ConfigurationObject , goConfig : vscode . WorkspaceConfiguration ) : Promise < ConfigurationObject > {
944969 const goplsVersion = await getLocalGoplsVersion ( cfg ) ;
945970 if ( ! goplsVersion ) return goplsConfig ?? { } ;
946971 const version = semver . parse ( goplsVersion . version ) ;
@@ -953,7 +978,7 @@ async function passInlayHintConfigToGopls(cfg: LanguageServerConfig, goplsConfig
953978 return goplsConfig ;
954979}
955980
956- async function passVulncheckConfigToGopls ( cfg : LanguageServerConfig , goplsConfig : any , goConfig : any ) {
981+ async function passVulncheckConfigToGopls ( cfg : LanguageServerConfig , goplsConfig : ConfigurationObject , goConfig : vscode . WorkspaceConfiguration ) : Promise < ConfigurationObject > {
957982 const goplsVersion = await getLocalGoplsVersion ( cfg ) ;
958983 if ( ! goplsVersion ) return goplsConfig ?? { } ;
959984 const version = semver . parse ( goplsVersion . version ) ;
@@ -966,7 +991,7 @@ async function passVulncheckConfigToGopls(cfg: LanguageServerConfig, goplsConfig
966991 return goplsConfig ;
967992}
968993
969- async function passLinkifyShowMessageToGopls ( cfg : LanguageServerConfig , goplsConfig : any ) {
994+ async function passLinkifyShowMessageToGopls ( cfg : LanguageServerConfig , goplsConfig : ConfigurationObject ) : Promise < ConfigurationObject > {
970995 goplsConfig = goplsConfig ?? { } ;
971996
972997 const goplsVersion = await getLocalGoplsVersion ( cfg ) ;
@@ -1025,6 +1050,29 @@ function createBenchmarkCodeLens(lens: vscode.CodeLens): vscode.CodeLens[] {
10251050 ] ;
10261051}
10271052
1053+ /**
1054+ * Builds the configuration object for the Go language server (gopls).
1055+ * This function locates gopls, validates it exists, and constructs the config needed to start it.
1056+ *
1057+ * Configuration includes:
1058+ * - Server executable path (from go.languageServerPath setting or auto-detected)
1059+ * - Server command-line flags (from go.languageServerFlags)
1060+ * - Environment variables for gopls process
1061+ * - Custom formatter (if go.formatTool is set to override gopls formatting)
1062+ * - Update check preferences (from go.toolsManagement.checkForUpdates)
1063+ * - Server version and modification time (for tracking updates)
1064+ *
1065+ * @param goConfig - VS Code workspace configuration for the Go extension
1066+ * @returns LanguageServerConfig object, with `enabled: false` if gopls is disabled or not found
1067+ *
1068+ * @example
1069+ * const goConfig = getGoConfig();
1070+ * const cfg = await buildLanguageServerConfig(goConfig);
1071+ * if (cfg.enabled) {
1072+ * console.log(`Found gopls at: ${cfg.path}`);
1073+ * const client = await buildLanguageClient(goCtx, cfg);
1074+ * }
1075+ */
10281076export async function buildLanguageServerConfig (
10291077 goConfig : vscode . WorkspaceConfiguration
10301078) : Promise < LanguageServerConfig > {
0 commit comments