refactor

package
v1.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func ValidateName(name string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL