Documentation
¶
Overview ¶
Package refactor provides code refactoring operations for the language server.
Supported refactorings include:
- Rename: safely rename symbols across files
- Extract: extract expressions to variables or functions
Package refactor provides code refactoring operations for LSP.
Index ¶
- Variables
- func ValidateName(name string) error
- type ExtractInfo
- type ExtractProvider
- func (p *ExtractProvider) AnalyzeSelection(file string, span diag.Span) *ExtractInfo
- func (p *ExtractProvider) ExtractFunction(file string, span diag.Span, funcName, codeText string) (*edit.WorkspaceEdit, error)
- func (p *ExtractProvider) ExtractVariable(file string, span diag.Span, varName, exprText string) (*edit.WorkspaceEdit, error)
- type PrepareResult
- type RenameProvider
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptySelection = errors.New("refactor: empty selection") ErrInvalidSelection = errors.New("refactor: invalid selection for extraction") ErrNoSymbols = errors.New("refactor: no symbol index available") )
Extract refactoring errors.
var ( ErrNoSymbol = errors.New("refactor: no symbol at position") ErrNotRenameable = errors.New("refactor: symbol cannot be renamed") ErrInvalidName = errors.New("refactor: invalid identifier name") ErrNameConflict = errors.New("refactor: name conflicts with existing symbol") )
Common errors.
Functions ¶
func ValidateName ¶
ValidateName checks if a name is a valid Lua identifier.
Types ¶
type ExtractInfo ¶
type ExtractInfo struct {
CanExtractVariable bool
CanExtractFunction bool
CapturedVariables []string // variables referenced from outside the selection
DefinedVariables []string // variables defined within the selection
UsedAfter []string // variables defined in selection but used after
}
ExtractInfo describes what can be extracted from a selection.
type ExtractProvider ¶
type ExtractProvider struct {
// contains filtered or unexported fields
}
ExtractProvider handles extraction refactorings.
func NewExtractProvider ¶
func NewExtractProvider(symbols *index.SymbolIndex) *ExtractProvider
NewExtractProvider creates an extract provider.
func (*ExtractProvider) AnalyzeSelection ¶
func (p *ExtractProvider) AnalyzeSelection(file string, span diag.Span) *ExtractInfo
AnalyzeSelection analyzes a selection for extraction possibilities.
func (*ExtractProvider) ExtractFunction ¶
func (p *ExtractProvider) ExtractFunction(file string, span diag.Span, funcName, codeText string) (*edit.WorkspaceEdit, error)
ExtractFunction extracts a code block into a function. The codeText parameter should contain the text of the code being extracted.
func (*ExtractProvider) ExtractVariable ¶
func (p *ExtractProvider) ExtractVariable(file string, span diag.Span, varName, exprText string) (*edit.WorkspaceEdit, error)
ExtractVariable extracts an expression into a local variable. The exprText parameter should contain the text of the expression being extracted.
type PrepareResult ¶
type PrepareResult struct {
Span diag.Span
Placeholder string // current name
Kind index.SymbolKind
}
PrepareResult contains info about a symbol that can be renamed.
type RenameProvider ¶
type RenameProvider struct {
// contains filtered or unexported fields
}
RenameProvider handles rename operations.
func NewRenameProvider ¶
func NewRenameProvider(symbols *index.SymbolIndex) *RenameProvider
NewRenameProvider creates a rename provider.
func (*RenameProvider) PrepareRename ¶
func (p *RenameProvider) PrepareRename(file string, line, col int) (*PrepareResult, error)
PrepareRename checks if rename is valid at position. Returns the symbol's current name and span, or error if not renameable.
func (*RenameProvider) Rename ¶
func (p *RenameProvider) Rename(file string, line, col int, newName string) (*edit.WorkspaceEdit, error)
Rename creates a workspace edit to rename a symbol.