From 0dbfaa16b0c83fc6c393fe4d7b4d2a0d671c7faa Mon Sep 17 00:00:00 2001 From: James Pogran Date: Wed, 6 Apr 2022 11:41:04 -0400 Subject: [PATCH 1/7] Single File Support --- internal/langserver/handlers/did_open.go | 4 + internal/langserver/handlers/initialize.go | 272 ++++++++++++--------- internal/langserver/handlers/service.go | 2 + 3 files changed, 163 insertions(+), 115 deletions(-) diff --git a/internal/langserver/handlers/did_open.go b/internal/langserver/handlers/did_open.go index 1ce91ac17..700809fa7 100644 --- a/internal/langserver/handlers/did_open.go +++ b/internal/langserver/handlers/did_open.go @@ -70,6 +70,10 @@ func (svc *service) TextDocumentDidOpen(ctx context.Context, params lsp.DidOpenT return err } + if svc.singleFileMode { + svc.stateStore.WalkerPaths.EnqueueDir(modHandle) + } + if !watcher.IsModuleWatched(mod.Path) { err := watcher.AddModule(mod.Path) if err != nil { diff --git a/internal/langserver/handlers/initialize.go b/internal/langserver/handlers/initialize.go index fd9860e5c..9f682b6e1 100644 --- a/internal/langserver/handlers/initialize.go +++ b/internal/langserver/handlers/initialize.go @@ -17,89 +17,27 @@ import ( ) func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) (lsp.InitializeResult, error) { - serverCaps := lsp.InitializeResult{ - Capabilities: lsp.ServerCapabilities{ - TextDocumentSync: lsp.TextDocumentSyncOptions{ - OpenClose: true, - Change: lsp.Incremental, - }, - CompletionProvider: lsp.CompletionOptions{ - ResolveProvider: false, - TriggerCharacters: []string{".", "["}, - }, - CodeActionProvider: lsp.CodeActionOptions{ - CodeActionKinds: ilsp.SupportedCodeActions.AsSlice(), - ResolveProvider: false, - }, - DeclarationProvider: lsp.DeclarationOptions{}, - DefinitionProvider: true, - CodeLensProvider: lsp.CodeLensOptions{}, - ReferencesProvider: true, - HoverProvider: true, - DocumentFormattingProvider: true, - DocumentSymbolProvider: true, - WorkspaceSymbolProvider: true, - Workspace: lsp.Workspace5Gn{ - WorkspaceFolders: lsp.WorkspaceFolders4Gn{ - Supported: true, - ChangeNotifications: "workspace/didChangeWorkspaceFolders", - }, - }, - }, - } + serverCaps := buildInitializeResult(ctx) - serverCaps.ServerInfo.Name = "terraform-ls" - version, ok := lsctx.LanguageServerVersion(ctx) - if ok { - serverCaps.ServerInfo.Version = version + out, err := settings.DecodeOptions(params.InitializationOptions) + if err != nil { + return serverCaps, err } - clientCaps := params.Capabilities - - properties := map[string]interface{}{ - "experimentalCapabilities.referenceCountCodeLens": false, - "options.rootModulePaths": false, - "options.excludeModulePaths": false, - "options.commandPrefix": false, - "options.ignoreDirectoryNames": false, - "options.experimentalFeatures.validateOnSave": false, - "options.terraformExecPath": false, - "options.terraformExecTimeout": "", - "options.terraformLogFilePath": false, - "root_uri": "dir", - "lsVersion": serverCaps.ServerInfo.Version, + err = out.Options.Validate() + if err != nil { + return serverCaps, err } + properties := getProperties(out) + properties["lsVersion"] = serverCaps.ServerInfo.Version + + clientCaps := params.Capabilities expClientCaps := lsp.ExperimentalClientCapabilities(clientCaps.Experimental) svc.server = jrpc2.ServerFromContext(ctx) - if tv, ok := expClientCaps.TelemetryVersion(); ok { - svc.logger.Printf("enabling telemetry (version: %d)", tv) - err := svc.setupTelemetry(tv, svc.server) - if err != nil { - svc.logger.Printf("failed to setup telemetry: %s", err) - } - svc.logger.Printf("telemetry enabled (version: %d)", tv) - } - defer svc.telemetry.SendEvent(ctx, "initialize", properties) - - if params.RootURI == "" { - properties["root_uri"] = "file" - return serverCaps, fmt.Errorf("Editing a single file is not yet supported." + - " Please open a directory.") - } - if !uri.IsURIValid(string(params.RootURI)) { - properties["root_uri"] = "invalid" - return serverCaps, fmt.Errorf("URI %q is not valid", params.RootURI) - } - - root := document.DirHandleFromURI(string(params.RootURI)) - - err := lsctx.SetRootDirectory(ctx, root.Path()) - if err != nil { - return serverCaps, err - } + setupTelemetry(expClientCaps, svc, ctx, properties) if params.ClientInfo.Name != "" { err = ilsp.SetClientName(ctx, params.ClientInfo.Name) @@ -108,7 +46,7 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) } } - if _, ok = expClientCaps.ShowReferencesCommandId(); ok { + if _, ok := expClientCaps.ShowReferencesCommandId(); ok { serverCaps.Capabilities.Experimental = lsp.ExperimentalServerCapabilities{ ReferenceCountCodeLens: true, } @@ -120,26 +58,6 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) return serverCaps, err } - out, err := settings.DecodeOptions(params.InitializationOptions) - if err != nil { - return serverCaps, err - } - - properties["options.rootModulePaths"] = len(out.Options.ModulePaths) > 0 - properties["options.excludeModulePaths"] = len(out.Options.ExcludeModulePaths) > 0 - properties["options.commandPrefix"] = len(out.Options.CommandPrefix) > 0 - properties["options.ignoreDirectoryNames"] = len(out.Options.IgnoreDirectoryNames) > 0 - properties["options.experimentalFeatures.prefillRequiredFields"] = out.Options.ExperimentalFeatures.PrefillRequiredFields - properties["options.experimentalFeatures.validateOnSave"] = out.Options.ExperimentalFeatures.ValidateOnSave - properties["options.terraformExecPath"] = len(out.Options.TerraformExecPath) > 0 - properties["options.terraformExecTimeout"] = out.Options.TerraformExecTimeout - properties["options.terraformLogFilePath"] = len(out.Options.TerraformLogFilePath) > 0 - - err = out.Options.Validate() - if err != nil { - return serverCaps, err - } - err = svc.configureSessionDependencies(ctx, out.Options) if err != nil { return serverCaps, err @@ -188,8 +106,132 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) }) } + if params.RootURI == "" { + svc.singleFileMode = true + properties["root_uri"] = "file" + jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{ + Type: lsp.Warning, + Message: "Some capabilities may be reduced when editing a single file, but you can still open text files and edit them. We recommend opening a directory for full functionality.", + }) + } else { + if !uri.IsURIValid(string(params.RootURI)) { + properties["root_uri"] = "invalid" + return serverCaps, fmt.Errorf("URI %q is not valid", params.RootURI) + } + + err := svc.setWalker(ctx, params, cfgOpts) + if err != nil { + return serverCaps, err + } + } + + // Walkers run asynchronously so we're intentionally *not* + // passing the request context here + // Static user-provided paths take precedence over dynamic discovery + walkerCtx := context.Background() + err = svc.closedDirWalker.StartWalking(walkerCtx) + if err != nil { + return serverCaps, fmt.Errorf("failed to start closedDirWalker: %w", err) + } + err = svc.openDirWalker.StartWalking(walkerCtx) + if err != nil { + return serverCaps, fmt.Errorf("failed to start openDirWalker: %w", err) + } + + return serverCaps, err +} + +func setupTelemetry(expClientCaps lsp.ExpClientCapabilities, svc *service, ctx context.Context, properties map[string]interface{}) { + if tv, ok := expClientCaps.TelemetryVersion(); ok { + svc.logger.Printf("enabling telemetry (version: %d)", tv) + err := svc.setupTelemetry(tv, svc.server) + if err != nil { + svc.logger.Printf("failed to setup telemetry: %s", err) + } + svc.logger.Printf("telemetry enabled (version: %d)", tv) + } + defer svc.telemetry.SendEvent(ctx, "initialize", properties) +} + +func getProperties(out *settings.DecodedOptions) map[string]interface{} { + properties := map[string]interface{}{ + "experimentalCapabilities.referenceCountCodeLens": false, + "options.rootModulePaths": false, + "options.excludeModulePaths": false, + "options.commandPrefix": false, + "options.ignoreDirectoryNames": false, + "options.experimentalFeatures.validateOnSave": false, + "options.terraformExecPath": false, + "options.terraformExecTimeout": "", + "options.terraformLogFilePath": false, + "root_uri": "dir", + "lsVersion": "", + } + + properties["options.rootModulePaths"] = len(out.Options.ModulePaths) > 0 + properties["options.excludeModulePaths"] = len(out.Options.ExcludeModulePaths) > 0 + properties["options.commandPrefix"] = len(out.Options.CommandPrefix) > 0 + properties["options.ignoreDirectoryNames"] = len(out.Options.IgnoreDirectoryNames) > 0 + properties["options.experimentalFeatures.prefillRequiredFields"] = out.Options.ExperimentalFeatures.PrefillRequiredFields + properties["options.experimentalFeatures.validateOnSave"] = out.Options.ExperimentalFeatures.ValidateOnSave + properties["options.terraformExecPath"] = len(out.Options.TerraformExecPath) > 0 + properties["options.terraformExecTimeout"] = out.Options.TerraformExecTimeout + properties["options.terraformLogFilePath"] = len(out.Options.TerraformLogFilePath) > 0 + + return properties +} + +func buildInitializeResult(ctx context.Context) lsp.InitializeResult { + serverCaps := lsp.InitializeResult{ + Capabilities: lsp.ServerCapabilities{ + TextDocumentSync: lsp.TextDocumentSyncOptions{ + OpenClose: true, + Change: lsp.Incremental, + }, + CompletionProvider: lsp.CompletionOptions{ + ResolveProvider: false, + TriggerCharacters: []string{".", "["}, + }, + CodeActionProvider: lsp.CodeActionOptions{ + CodeActionKinds: ilsp.SupportedCodeActions.AsSlice(), + ResolveProvider: false, + }, + DeclarationProvider: lsp.DeclarationOptions{}, + DefinitionProvider: true, + CodeLensProvider: lsp.CodeLensOptions{}, + ReferencesProvider: true, + HoverProvider: true, + DocumentFormattingProvider: true, + DocumentSymbolProvider: true, + WorkspaceSymbolProvider: true, + Workspace: lsp.Workspace5Gn{ + WorkspaceFolders: lsp.WorkspaceFolders4Gn{ + Supported: true, + ChangeNotifications: "workspace/didChangeWorkspaceFolders", + }, + }, + }, + } + + serverCaps.ServerInfo.Name = "terraform-ls" + version, ok := lsctx.LanguageServerVersion(ctx) + if ok { + serverCaps.ServerInfo.Version = version + } + + return serverCaps +} + +func (svc *service) setWalker(ctx context.Context, params lsp.InitializeParams, options *settings.Options) error { + root := document.DirHandleFromURI(string(params.RootURI)) + + err := lsctx.SetRootDirectory(ctx, root.Path()) + if err != nil { + return err + } + var excludeModulePaths []string - for _, rawPath := range cfgOpts.ExcludeModulePaths { + for _, rawPath := range options.ExcludeModulePaths { modPath, err := resolvePath(root.Path(), rawPath) if err != nil { svc.logger.Printf("Ignoring excluded module path %s: %s", rawPath, err) @@ -200,7 +242,7 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) err = svc.stateStore.WalkerPaths.EnqueueDir(root) if err != nil { - return serverCaps, err + return err } if len(params.WorkspaceFolders) > 0 { @@ -219,27 +261,27 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) } } - svc.closedDirWalker.SetIgnoreDirectoryNames(cfgOpts.IgnoreDirectoryNames) + svc.closedDirWalker.SetIgnoreDirectoryNames(options.IgnoreDirectoryNames) svc.closedDirWalker.SetExcludeModulePaths(excludeModulePaths) - svc.openDirWalker.SetIgnoreDirectoryNames(cfgOpts.IgnoreDirectoryNames) + svc.openDirWalker.SetIgnoreDirectoryNames(options.IgnoreDirectoryNames) svc.openDirWalker.SetExcludeModulePaths(excludeModulePaths) // Walkers run asynchronously so we're intentionally *not* // passing the request context here - walkerCtx := context.Background() - err = svc.closedDirWalker.StartWalking(walkerCtx) - if err != nil { - return serverCaps, fmt.Errorf("failed to start closedDirWalker: %w", err) - } - err = svc.openDirWalker.StartWalking(walkerCtx) - if err != nil { - return serverCaps, fmt.Errorf("failed to start openDirWalker: %w", err) - } - // Static user-provided paths take precedence over dynamic discovery - if len(cfgOpts.ModulePaths) > 0 { - svc.logger.Printf("Attempting to add %d static module paths", len(cfgOpts.ModulePaths)) - for _, rawPath := range cfgOpts.ModulePaths { + // walkerCtx := context.Background() + // err = svc.closedDirWalker.StartWalking(walkerCtx) + // if err != nil { + // return fmt.Errorf("failed to start closedDirWalker: %w", err) + // } + // err = svc.openDirWalker.StartWalking(walkerCtx) + // if err != nil { + // return fmt.Errorf("failed to start openDirWalker: %w", err) + // } + + if len(options.ModulePaths) > 0 { + svc.logger.Printf("Attempting to add %d static module paths", len(options.ModulePaths)) + for _, rawPath := range options.ModulePaths { modPath, err := resolvePath(root.Path(), rawPath) if err != nil { jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{ @@ -251,14 +293,14 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) err = svc.watcher.AddModule(modPath) if err != nil { - return serverCaps, err + return err } } - return serverCaps, nil + return nil } - return serverCaps, nil + return nil } func resolvePath(rootDir, rawPath string) (string, error) { diff --git a/internal/langserver/handlers/service.go b/internal/langserver/handlers/service.go index 45e939f38..d7d620552 100644 --- a/internal/langserver/handlers/service.go +++ b/internal/langserver/handlers/service.go @@ -61,6 +61,8 @@ type service struct { walkerCollector *module.WalkerCollector additionalHandlers map[string]rpch.Func + + singleFileMode bool } var discardLogs = log.New(ioutil.Discard, "", 0) From 28e1377203c54182411462a81f4914c206a22621 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Wed, 6 Apr 2022 13:35:29 -0400 Subject: [PATCH 2/7] rename methods. add ignore warning setting --- internal/langserver/handlers/initialize.go | 25 +++++++++++++--------- internal/settings/settings.go | 2 ++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/internal/langserver/handlers/initialize.go b/internal/langserver/handlers/initialize.go index 9f682b6e1..b840b47b4 100644 --- a/internal/langserver/handlers/initialize.go +++ b/internal/langserver/handlers/initialize.go @@ -17,7 +17,7 @@ import ( ) func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) (lsp.InitializeResult, error) { - serverCaps := buildInitializeResult(ctx) + serverCaps := initializeResult(ctx) out, err := settings.DecodeOptions(params.InitializationOptions) if err != nil { @@ -29,7 +29,7 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) return serverCaps, err } - properties := getProperties(out) + properties := mapProperties(out) properties["lsVersion"] = serverCaps.ServerInfo.Version clientCaps := params.Capabilities @@ -109,17 +109,19 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) if params.RootURI == "" { svc.singleFileMode = true properties["root_uri"] = "file" - jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{ - Type: lsp.Warning, - Message: "Some capabilities may be reduced when editing a single file, but you can still open text files and edit them. We recommend opening a directory for full functionality.", - }) + if properties["options.ignoreSingleFileWarning"] == false { + jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{ + Type: lsp.Warning, + Message: "Some capabilities may be reduced when editing a single file, but you can still open text files and edit them. We recommend opening a directory for full functionality.", + }) + } } else { if !uri.IsURIValid(string(params.RootURI)) { properties["root_uri"] = "invalid" return serverCaps, fmt.Errorf("URI %q is not valid", params.RootURI) } - err := svc.setWalker(ctx, params, cfgOpts) + err := svc.setupWalker(ctx, params, cfgOpts) if err != nil { return serverCaps, err } @@ -153,9 +155,10 @@ func setupTelemetry(expClientCaps lsp.ExpClientCapabilities, svc *service, ctx c defer svc.telemetry.SendEvent(ctx, "initialize", properties) } -func getProperties(out *settings.DecodedOptions) map[string]interface{} { +func mapProperties(out *settings.DecodedOptions) map[string]interface{} { properties := map[string]interface{}{ "experimentalCapabilities.referenceCountCodeLens": false, + "options.ignoreSingleFileWarning": false, "options.rootModulePaths": false, "options.excludeModulePaths": false, "options.commandPrefix": false, @@ -168,12 +171,14 @@ func getProperties(out *settings.DecodedOptions) map[string]interface{} { "lsVersion": "", } + properties["options.rootModulePaths"] = len(out.Options.ModulePaths) > 0 properties["options.rootModulePaths"] = len(out.Options.ModulePaths) > 0 properties["options.excludeModulePaths"] = len(out.Options.ExcludeModulePaths) > 0 properties["options.commandPrefix"] = len(out.Options.CommandPrefix) > 0 properties["options.ignoreDirectoryNames"] = len(out.Options.IgnoreDirectoryNames) > 0 properties["options.experimentalFeatures.prefillRequiredFields"] = out.Options.ExperimentalFeatures.PrefillRequiredFields properties["options.experimentalFeatures.validateOnSave"] = out.Options.ExperimentalFeatures.ValidateOnSave + properties["options.ignoreSingleFileWarning"] = out.Options.IgnoreSingleFileWarning properties["options.terraformExecPath"] = len(out.Options.TerraformExecPath) > 0 properties["options.terraformExecTimeout"] = out.Options.TerraformExecTimeout properties["options.terraformLogFilePath"] = len(out.Options.TerraformLogFilePath) > 0 @@ -181,7 +186,7 @@ func getProperties(out *settings.DecodedOptions) map[string]interface{} { return properties } -func buildInitializeResult(ctx context.Context) lsp.InitializeResult { +func initializeResult(ctx context.Context) lsp.InitializeResult { serverCaps := lsp.InitializeResult{ Capabilities: lsp.ServerCapabilities{ TextDocumentSync: lsp.TextDocumentSyncOptions{ @@ -222,7 +227,7 @@ func buildInitializeResult(ctx context.Context) lsp.InitializeResult { return serverCaps } -func (svc *service) setWalker(ctx context.Context, params lsp.InitializeParams, options *settings.Options) error { +func (svc *service) setupWalker(ctx context.Context, params lsp.InitializeParams, options *settings.Options) error { root := document.DirHandleFromURI(string(params.RootURI)) err := lsctx.SetRootDirectory(ctx, root.Path()) diff --git a/internal/settings/settings.go b/internal/settings/settings.go index 9829ee89e..bc9002d75 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -25,6 +25,8 @@ type Options struct { // ExperimentalFeatures encapsulates experimental features users can opt into. ExperimentalFeatures ExperimentalFeatures `mapstructure:"experimentalFeatures"` + IgnoreSingleFileWarning bool `mapstructure:"ignoreSingleFileWarning"` + TerraformExecPath string `mapstructure:"terraformExecPath"` TerraformExecTimeout string `mapstructure:"terraformExecTimeout"` TerraformLogFilePath string `mapstructure:"terraformLogFilePath"` From 7508ad19c60e8a82ac388543859530b13d0770d3 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Wed, 6 Apr 2022 15:10:45 -0400 Subject: [PATCH 3/7] docs --- docs/SETTINGS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/SETTINGS.md b/docs/SETTINGS.md index f3c20a6c9..8d89f67e2 100644 --- a/docs/SETTINGS.md +++ b/docs/SETTINGS.md @@ -80,6 +80,10 @@ The following list of directories will always be ignored: - `terraform.tfstate.d` - `.terragrunt-cache` +## `ignoreSingleFileWarning` (`bool`) + +This setting controls whether terraform-ls sends a warning about opening up a single Terraform file instead of a Terraform folder. Setting this to `true` will prevent the message being sent. The default value is `false`. + ## `experimentalFeatures` (object) This object contains inner settings used to opt into experimental features not yet ready to be on by default. From bb06f286abaff89815877c7788af0c7589ff2f22 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Thu, 7 Apr 2022 11:51:10 -0400 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: Radek Simko --- internal/langserver/handlers/did_open.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/langserver/handlers/did_open.go b/internal/langserver/handlers/did_open.go index 700809fa7..2e544c3d7 100644 --- a/internal/langserver/handlers/did_open.go +++ b/internal/langserver/handlers/did_open.go @@ -71,7 +71,10 @@ func (svc *service) TextDocumentDidOpen(ctx context.Context, params lsp.DidOpenT } if svc.singleFileMode { - svc.stateStore.WalkerPaths.EnqueueDir(modHandle) + err = svc.stateStore.WalkerPaths.EnqueueDir(modHandle) + if err != nil { + return err + } } if !watcher.IsModuleWatched(mod.Path) { From 2ab87008364d3e8cf438ea97fc69a2ec289e3a80 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Thu, 7 Apr 2022 11:51:40 -0400 Subject: [PATCH 5/7] feedback --- internal/langserver/handlers/initialize.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/internal/langserver/handlers/initialize.go b/internal/langserver/handlers/initialize.go index b840b47b4..b48b30d94 100644 --- a/internal/langserver/handlers/initialize.go +++ b/internal/langserver/handlers/initialize.go @@ -271,19 +271,6 @@ func (svc *service) setupWalker(ctx context.Context, params lsp.InitializeParams svc.openDirWalker.SetIgnoreDirectoryNames(options.IgnoreDirectoryNames) svc.openDirWalker.SetExcludeModulePaths(excludeModulePaths) - // Walkers run asynchronously so we're intentionally *not* - // passing the request context here - // Static user-provided paths take precedence over dynamic discovery - // walkerCtx := context.Background() - // err = svc.closedDirWalker.StartWalking(walkerCtx) - // if err != nil { - // return fmt.Errorf("failed to start closedDirWalker: %w", err) - // } - // err = svc.openDirWalker.StartWalking(walkerCtx) - // if err != nil { - // return fmt.Errorf("failed to start openDirWalker: %w", err) - // } - if len(options.ModulePaths) > 0 { svc.logger.Printf("Attempting to add %d static module paths", len(options.ModulePaths)) for _, rawPath := range options.ModulePaths { From 586af7bcb4f2326d005dc92cbb5b7629654cec1c Mon Sep 17 00:00:00 2001 From: James Pogran Date: Thu, 7 Apr 2022 11:52:29 -0400 Subject: [PATCH 6/7] feedback --- internal/langserver/handlers/initialize.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/langserver/handlers/initialize.go b/internal/langserver/handlers/initialize.go index b48b30d94..3ea7fc930 100644 --- a/internal/langserver/handlers/initialize.go +++ b/internal/langserver/handlers/initialize.go @@ -29,7 +29,7 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) return serverCaps, err } - properties := mapProperties(out) + properties := getTelemetryProperties(out) properties["lsVersion"] = serverCaps.ServerInfo.Version clientCaps := params.Capabilities @@ -155,7 +155,7 @@ func setupTelemetry(expClientCaps lsp.ExpClientCapabilities, svc *service, ctx c defer svc.telemetry.SendEvent(ctx, "initialize", properties) } -func mapProperties(out *settings.DecodedOptions) map[string]interface{} { +func getTelemetryProperties(out *settings.DecodedOptions) map[string]interface{} { properties := map[string]interface{}{ "experimentalCapabilities.referenceCountCodeLens": false, "options.ignoreSingleFileWarning": false, From 8ea29ed58aedf2dcd8a4cac04fc249c69d0d7994 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Thu, 7 Apr 2022 12:26:10 -0400 Subject: [PATCH 7/7] Update internal/langserver/handlers/initialize.go Co-authored-by: Radek Simko --- internal/langserver/handlers/initialize.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/langserver/handlers/initialize.go b/internal/langserver/handlers/initialize.go index 3ea7fc930..e53bd09b0 100644 --- a/internal/langserver/handlers/initialize.go +++ b/internal/langserver/handlers/initialize.go @@ -112,7 +112,7 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams) if properties["options.ignoreSingleFileWarning"] == false { jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{ Type: lsp.Warning, - Message: "Some capabilities may be reduced when editing a single file, but you can still open text files and edit them. We recommend opening a directory for full functionality.", + Message: "Some capabilities may be reduced when editing a single file. We recommend opening a directory for full functionality. Use 'ignoreSingleFileWarning' to suppress this warning.", }) } } else {