golang.org/x/tools/gopls@v0.15.3/internal/settings/default.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package settings 6 7 import ( 8 "sync" 9 "time" 10 11 "golang.org/x/tools/gopls/internal/file" 12 "golang.org/x/tools/gopls/internal/protocol" 13 "golang.org/x/tools/gopls/internal/protocol/command" 14 ) 15 16 var ( 17 optionsOnce sync.Once 18 defaultOptions *Options 19 ) 20 21 // DefaultOptions is the options that are used for Gopls execution independent 22 // of any externally provided configuration (LSP initialization, command 23 // invocation, etc.). 24 func DefaultOptions(overrides ...func(*Options)) *Options { 25 optionsOnce.Do(func() { 26 var commands []string 27 for _, c := range command.Commands { 28 commands = append(commands, c.ID()) 29 } 30 defaultOptions = &Options{ 31 ClientOptions: ClientOptions{ 32 InsertTextFormat: protocol.PlainTextTextFormat, 33 PreferredContentFormat: protocol.Markdown, 34 ConfigurationSupported: true, 35 DynamicConfigurationSupported: true, 36 DynamicRegistrationSemanticTokensSupported: true, 37 DynamicWatchedFilesSupported: true, 38 LineFoldingOnly: false, 39 HierarchicalDocumentSymbolSupport: true, 40 }, 41 ServerOptions: ServerOptions{ 42 SupportedCodeActions: map[file.Kind]map[protocol.CodeActionKind]bool{ 43 file.Go: { 44 protocol.SourceFixAll: true, 45 protocol.SourceOrganizeImports: true, 46 protocol.QuickFix: true, 47 protocol.RefactorRewrite: true, 48 protocol.RefactorInline: true, 49 protocol.RefactorExtract: true, 50 }, 51 file.Mod: { 52 protocol.SourceOrganizeImports: true, 53 protocol.QuickFix: true, 54 }, 55 file.Work: {}, 56 file.Sum: {}, 57 file.Tmpl: {}, 58 }, 59 SupportedCommands: commands, 60 }, 61 UserOptions: UserOptions{ 62 BuildOptions: BuildOptions{ 63 ExpandWorkspaceToModule: true, 64 DirectoryFilters: []string{"-**/node_modules"}, 65 TemplateExtensions: []string{}, 66 StandaloneTags: []string{"ignore"}, 67 }, 68 UIOptions: UIOptions{ 69 DiagnosticOptions: DiagnosticOptions{ 70 Annotations: map[Annotation]bool{ 71 Bounds: true, 72 Escape: true, 73 Inline: true, 74 Nil: true, 75 }, 76 Vulncheck: ModeVulncheckOff, 77 DiagnosticsDelay: 1 * time.Second, 78 DiagnosticsTrigger: DiagnosticsOnEdit, 79 AnalysisProgressReporting: true, 80 }, 81 InlayHintOptions: InlayHintOptions{}, 82 DocumentationOptions: DocumentationOptions{ 83 HoverKind: FullDocumentation, 84 LinkTarget: "pkg.go.dev", 85 LinksInHover: true, 86 }, 87 NavigationOptions: NavigationOptions{ 88 ImportShortcut: BothShortcuts, 89 SymbolMatcher: SymbolFastFuzzy, 90 SymbolStyle: DynamicSymbols, 91 SymbolScope: AllSymbolScope, 92 }, 93 CompletionOptions: CompletionOptions{ 94 Matcher: Fuzzy, 95 CompletionBudget: 100 * time.Millisecond, 96 ExperimentalPostfixCompletions: true, 97 CompleteFunctionCalls: true, 98 }, 99 Codelenses: map[string]bool{ 100 string(command.Generate): true, 101 string(command.RegenerateCgo): true, 102 string(command.Tidy): true, 103 string(command.GCDetails): false, 104 string(command.UpgradeDependency): true, 105 string(command.Vendor): true, 106 // TODO(hyangah): enable command.RunGovulncheck. 107 }, 108 }, 109 }, 110 InternalOptions: InternalOptions{ 111 CompleteUnimported: true, 112 CompletionDocumentation: true, 113 DeepCompletion: true, 114 SubdirWatchPatterns: SubdirWatchPatternsAuto, 115 ReportAnalysisProgressAfter: 5 * time.Second, 116 TelemetryPrompt: false, 117 LinkifyShowMessage: false, 118 IncludeReplaceInWorkspace: false, 119 ZeroConfig: true, 120 }, 121 Hooks: Hooks{ 122 URLRegexp: urlRegexp(), 123 DefaultAnalyzers: analyzers(), 124 StaticcheckAnalyzers: map[string]*Analyzer{}, 125 }, 126 } 127 }) 128 options := defaultOptions.Clone() 129 for _, override := range overrides { 130 if override != nil { 131 override(options) 132 } 133 } 134 return options 135 }