| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
func DefaultOptions(overrides ...func(*Options)) *Options { |
| 27 |
optionsOnce.Do(func() { |
| 28 |
var commands []string |
| 29 |
for _, c := range command.Commands { |
| 30 |
commands = append(commands, c.String()) |
| 31 |
} |
| 32 |
defaultOptions = &Options{ |
| 33 |
ClientOptions: ClientOptions{ |
| 34 |
InsertTextFormat: protocol.PlainTextTextFormat, |
| 35 |
PreferredContentFormat: protocol.Markdown, |
| 36 |
ConfigurationSupported: true, |
| 37 |
DynamicConfigurationSupported: true, |
| 38 |
DynamicRegistrationSemanticTokensSupported: true, |
| 39 |
DynamicWatchedFilesSupported: true, |
| 40 |
LineFoldingOnly: false, |
| 41 |
HierarchicalDocumentSymbolSupport: true, |
| 42 |
ImportsSource: ImportsSourceGopls, |
| 43 |
}, |
| 44 |
ServerOptions: ServerOptions{ |
| 45 |
SupportedCodeActions: map[file.Kind]map[protocol.CodeActionKind]bool{ |
| 46 |
file.Go: { |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
protocol.SourceFixAll: true, |
| 51 |
protocol.SourceOrganizeImports: true, |
| 52 |
protocol.QuickFix: true, |
| 53 |
GoAssembly: true, |
| 54 |
GoDoc: true, |
| 55 |
GoFreeSymbols: true, |
| 56 |
GoSplitPackage: true, |
| 57 |
GoplsDocFeatures: true, |
| 58 |
RefactorRewriteChangeQuote: true, |
| 59 |
RefactorRewriteFillStruct: true, |
| 60 |
RefactorRewriteFillSwitch: true, |
| 61 |
RefactorRewriteImplementInterface: true, |
| 62 |
RefactorRewriteInvertIf: true, |
| 63 |
RefactorRewriteJoinLines: true, |
| 64 |
RefactorRewriteRemoveUnusedParam: true, |
| 65 |
RefactorRewriteSplitLines: true, |
| 66 |
RefactorInlineCall: true, |
| 67 |
RefactorInlineVariable: true, |
| 68 |
RefactorExtractConstant: true, |
| 69 |
RefactorExtractConstantAll: true, |
| 70 |
RefactorExtractFunction: true, |
| 71 |
RefactorExtractMethod: true, |
| 72 |
RefactorExtractVariable: true, |
| 73 |
RefactorExtractVariableAll: true, |
| 74 |
RefactorExtractToNewFile: true, |
| 75 |
RefactorMoveType: true, |
| 76 |
|
| 77 |
}, |
| 78 |
file.Mod: { |
| 79 |
protocol.SourceOrganizeImports: true, |
| 80 |
protocol.QuickFix: true, |
| 81 |
}, |
| 82 |
file.Work: {}, |
| 83 |
file.Sum: {}, |
| 84 |
file.Tmpl: {}, |
| 85 |
}, |
| 86 |
SupportedCommands: commands, |
| 87 |
}, |
| 88 |
UserOptions: UserOptions{ |
| 89 |
BuildOptions: BuildOptions{ |
| 90 |
ExpandWorkspaceToModule: true, |
| 91 |
DirectoryFilters: []string{"-**/node_modules"}, |
| 92 |
TemplateExtensions: []string{}, |
| 93 |
StandaloneTags: []string{"ignore"}, |
| 94 |
WorkspaceFiles: []string{}, |
| 95 |
}, |
| 96 |
UIOptions: UIOptions{ |
| 97 |
DiagnosticOptions: DiagnosticOptions{ |
| 98 |
Annotations: map[Annotation]bool{ |
| 99 |
Bounds: true, |
| 100 |
Escape: true, |
| 101 |
Inline: true, |
| 102 |
Nil: true, |
| 103 |
}, |
| 104 |
Vulncheck: ModeVulncheckPrompt, |
| 105 |
DiagnosticsDelay: 1 * time.Second, |
| 106 |
DiagnosticsTrigger: DiagnosticsOnEdit, |
| 107 |
AnalysisProgressReporting: true, |
| 108 |
}, |
| 109 |
InlayHintOptions: InlayHintOptions{ |
| 110 |
Hints: map[InlayHint]bool{}, |
| 111 |
}, |
| 112 |
DocumentationOptions: DocumentationOptions{ |
| 113 |
HoverKind: FullDocumentation, |
| 114 |
LinkTarget: "pkg.go.dev", |
| 115 |
LinksInHover: LinksInHover_LinkTarget, |
| 116 |
}, |
| 117 |
NavigationOptions: NavigationOptions{ |
| 118 |
ImportShortcut: BothShortcuts, |
| 119 |
SymbolMatcher: SymbolFastFuzzy, |
| 120 |
SymbolStyle: DynamicSymbols, |
| 121 |
SymbolScope: AllSymbolScope, |
| 122 |
}, |
| 123 |
CompletionOptions: CompletionOptions{ |
| 124 |
Matcher: Fuzzy, |
| 125 |
CompletionBudget: 100 * time.Millisecond, |
| 126 |
ExperimentalPostfixCompletions: true, |
| 127 |
CompleteFunctionCalls: true, |
| 128 |
}, |
| 129 |
Codelenses: map[CodeLensSource]bool{ |
| 130 |
CodeLensGenerate: true, |
| 131 |
CodeLensRegenerateCgo: true, |
| 132 |
CodeLensTidy: true, |
| 133 |
CodeLensUpgradeDependency: true, |
| 134 |
CodeLensVendor: true, |
| 135 |
CodeLensRunGovulncheck: true, |
| 136 |
}, |
| 137 |
NewGoFileHeader: true, |
| 138 |
RenameMovesSubpackages: false, |
| 139 |
}, |
| 140 |
FileWatcher: FileWatcherOff, |
| 141 |
}, |
| 142 |
InternalOptions: InternalOptions{ |
| 143 |
CompleteUnimported: true, |
| 144 |
CompletionDocumentation: true, |
| 145 |
DeepCompletion: true, |
| 146 |
SubdirWatchPatterns: SubdirWatchPatternsAuto, |
| 147 |
ReportAnalysisProgressAfter: 5 * time.Second, |
| 148 |
TelemetryPrompt: false, |
| 149 |
LinkifyShowMessage: false, |
| 150 |
IncludeReplaceInWorkspace: false, |
| 151 |
ZeroConfig: true, |
| 152 |
}, |
| 153 |
} |
| 154 |
}) |
| 155 |
options := defaultOptions.Clone() |
| 156 |
for _, override := range overrides { |
| 157 |
if override != nil { |
| 158 |
override(options) |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
return options |
| 163 |
} |