// CodeActions returns all enabled code actions (edits and other // commands) available for the selected range. // // Depending on how the request was triggered, fewer actions may be // offered, e.g. to avoid UI distractions after mere cursor motion. // // See ../protocol/codeactionkind.go for some code action theory. func CodeActions(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, rng protocol.Range, diagnostics []protocol.Diagnostic, enabled func(protocol.CodeActionKind) bool, trigger protocol.CodeActionTriggerKind) (actions []protocol.CodeAction, _ error) { … } type codeActionsRequest … // addApplyFixAction adds an ApplyFix command-based CodeAction to the result. func (req *codeActionsRequest) addApplyFixAction(title, fix string, loc protocol.Location) { … } // addCommandAction adds a CodeAction to the result based on the provided command. // // If allowResolveEdits (and the client supports codeAction/resolve) // then the command is embedded into the code action data field so // that the client can later ask the server to "resolve" a command // into an edit that they can preview and apply selectively. // Set allowResolveEdits only for actions that generate edits. // // Otherwise, the command is set as the code action operation. func (req *codeActionsRequest) addCommandAction(cmd *protocol.Command, allowResolveEdits bool) { … } // addCommandAction adds an edit-based CodeAction to the result. func (req *codeActionsRequest) addEditAction(title string, fixedDiagnostics []protocol.Diagnostic, changes ...protocol.DocumentChange) { … } // addAction adds a code action to the response. func (req *codeActionsRequest) addAction(act protocol.CodeAction) { … } // resolveEdits reports whether the client can resolve edits lazily. func (req *codeActionsRequest) resolveEdits() bool { … } // lazyInit[*T](ctx, req) returns a pointer to an instance of T, // calling new(T).init(ctx.req) on the first request. // // It is conceptually a (generic) method of req. func lazyInit[P interface { … } type codeActionProducer … var codeActionProducers … // sourceOrganizeImports produces "Organize Imports" code actions. func sourceOrganizeImports(ctx context.Context, req *codeActionsRequest) error { … } // quickFix produces code actions that fix errors, // for example by adding/deleting/renaming imports, // or declaring the missing methods of a type. func quickFix(ctx context.Context, req *codeActionsRequest) error { … } type allImportsFixesResult … func (res *allImportsFixesResult) init(ctx context.Context, req *codeActionsRequest) { … } func importFixTitle(fix *imports.ImportFix) string { … } // fixedByImportFix filters the provided slice of diagnostics to those that // would be fixed by the provided imports fix. func fixedByImportFix(fix *imports.ImportFix, diagnostics []protocol.Diagnostic) []protocol.Diagnostic { … } // goFreeSymbols produces "Browse free symbols" code actions. // See [server.commandHandler.FreeSymbols] for command implementation. func goFreeSymbols(ctx context.Context, req *codeActionsRequest) error { … } // goplsDocFeatures produces "Browse gopls feature documentation" code actions. // See [server.commandHandler.ClientOpenURL] for command implementation. func goplsDocFeatures(ctx context.Context, req *codeActionsRequest) error { … } // goDoc produces "Browse documentation for X" code actions. // See [server.commandHandler.Doc] for command implementation. func goDoc(ctx context.Context, req *codeActionsRequest) error { … } // refactorExtractFunction produces "Extract function" code actions. // See [extractFunction] for command implementation. func refactorExtractFunction(ctx context.Context, req *codeActionsRequest) error { … } // refactorExtractMethod produces "Extract method" code actions. // See [extractMethod] for command implementation. func refactorExtractMethod(ctx context.Context, req *codeActionsRequest) error { … } // refactorExtractVariable produces "Extract variable" code actions. // See [extractVariable] for command implementation. func refactorExtractVariable(ctx context.Context, req *codeActionsRequest) error { … } // refactorExtractToNewFile produces "Extract declarations to new file" code actions. // See [server.commandHandler.ExtractToNewFile] for command implementation. func refactorExtractToNewFile(ctx context.Context, req *codeActionsRequest) error { … } // refactorRewriteRemoveUnusedParam produces "Remove unused parameter" code actions. // See [server.commandHandler.ChangeSignature] for command implementation. func refactorRewriteRemoveUnusedParam(ctx context.Context, req *codeActionsRequest) error { … } // refactorRewriteChangeQuote produces "Convert to {raw,interpreted} string literal" code actions. func refactorRewriteChangeQuote(ctx context.Context, req *codeActionsRequest) error { … } // refactorRewriteChangeQuote produces "Invert 'if' condition" code actions. // See [invertIfCondition] for command implementation. func refactorRewriteInvertIf(ctx context.Context, req *codeActionsRequest) error { … } // refactorRewriteSplitLines produces "Split ITEMS into separate lines" code actions. // See [splitLines] for command implementation. func refactorRewriteSplitLines(ctx context.Context, req *codeActionsRequest) error { … } // refactorRewriteJoinLines produces "Join ITEMS into one line" code actions. // See [joinLines] for command implementation. func refactorRewriteJoinLines(ctx context.Context, req *codeActionsRequest) error { … } // refactorRewriteFillStruct produces "Fill STRUCT" code actions. // See [fillstruct.SuggestedFix] for command implementation. func refactorRewriteFillStruct(ctx context.Context, req *codeActionsRequest) error { … } // refactorRewriteFillSwitch produces "Add cases for TYPE/ENUM" code actions. func refactorRewriteFillSwitch(ctx context.Context, req *codeActionsRequest) error { … } // canRemoveParameter reports whether we can remove the function parameter // indicated by the given [start, end) range. // // This is true if: // - there are no parse or type errors, and // - [start, end) is contained within an unused field or parameter name // - ... of a non-method function declaration. // // (Note that the unusedparam analyzer also computes this property, but // much more precisely, allowing it to report its findings as diagnostics.) // // TODO(adonovan): inline into refactorRewriteRemoveUnusedParam. func canRemoveParameter(pkg *cache.Package, pgf *parsego.File, rng protocol.Range) bool { … } // refactorInlineCall produces "Inline call to FUNC" code actions. // See [inlineCall] for command implementation. func refactorInlineCall(ctx context.Context, req *codeActionsRequest) error { … } // goTest produces "Run tests and benchmarks" code actions. // See [server.commandHandler.runTests] for command implementation. func goTest(ctx context.Context, req *codeActionsRequest) error { … } // goAssembly produces "Browse ARCH assembly for FUNC" code actions. // See [server.commandHandler.Assembly] for command implementation. func goAssembly(ctx context.Context, req *codeActionsRequest) error { … }