code_rename

package
v0.50.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedServers = []LanguageServer{
	{Language: "go", Command: "gopls", Args: []string{"serve"}},
	{Language: "typescript", Command: "typescript-language-server", Args: []string{"--stdio"}},
	{Language: "javascript", Command: "typescript-language-server", Args: []string{"--stdio"}},
	{Language: "python", Command: "pyright-langserver", Args: []string{"--stdio"}},
	{Language: "rust", Command: "rust-analyzer", Args: []string{}},
	{Language: "bash", Command: "bash-language-server", Args: []string{"start"}},
	{Language: "sh", Command: "bash-language-server", Args: []string{"start"}},
	{Language: "html", Command: "vscode-html-language-server", Args: []string{"--stdio"}},
	{Language: "css", Command: "vscode-css-language-server", Args: []string{"--stdio"}},
	{Language: "scss", Command: "vscode-css-language-server", Args: []string{"--stdio"}},
	{Language: "less", Command: "vscode-css-language-server", Args: []string{"--stdio"}},
	{Language: "json", Command: "vscode-json-language-server", Args: []string{"--stdio"}},
	{Language: "yaml", Command: "yaml-language-server", Args: []string{"--stdio"}},
	{Language: "c", Command: "clangd", Args: []string{}},
	{Language: "cpp", Command: "clangd", Args: []string{}},
	{Language: "java", Command: "jdtls", Args: []string{}},
	{Language: "swift", Command: "sourcekit-lsp", Args: []string{}},
}

SupportedServers defines LSP servers with rename capability

Functions

func DetectLanguage

func DetectLanguage(filePath string) string

DetectLanguage determines the language from a file path

func GetAvailableLanguages

func GetAvailableLanguages(ctx context.Context, logger *logrus.Logger) []string

GetAvailableLanguages returns a list of languages with available LSP servers

func StopCleanupRoutine

func StopCleanupRoutine(cache *sync.Map, logger *logrus.Logger)

StopCleanupRoutine stops the background cleanup routine and closes all cached LSP clients Should be called during server shutdown to prevent goroutine leaks

Types

type ChangeSnippet

type ChangeSnippet struct {
	FilePath string `json:"file_path"`
	Line     int    `json:"line"`
	Before   string `json:"before"`
	After    string `json:"after"`
}

ChangeSnippet shows a single change in preview mode

type CodeRenameTool

type CodeRenameTool struct{}

CodeRenameTool implements symbol renaming via LSP

func (*CodeRenameTool) Definition

func (t *CodeRenameTool) Definition() mcp.Tool

Definition returns the tool's definition for MCP registration

func (*CodeRenameTool) Execute

func (t *CodeRenameTool) Execute(ctx context.Context, logger *logrus.Logger, cache *sync.Map, args map[string]any) (*mcp.CallToolResult, error)

Execute executes the tool's logic

func (*CodeRenameTool) ProvideExtendedInfo

func (t *CodeRenameTool) ProvideExtendedInfo() *tools.ExtendedHelp

ProvideExtendedInfo implements the ExtendedHelpProvider interface

type LSPClient

type LSPClient struct {
	// contains filtered or unexported fields
}

LSPClient wraps an LSP server connection

func NewLSPClient

func NewLSPClient(ctx context.Context, logger *logrus.Logger, server *LanguageServer, filePath string) (*LSPClient, error)

NewLSPClient creates and initialises a new LSP client

func (*LSPClient) Close

func (c *LSPClient) Close() (err error)

Close shuts down the LSP client and server with panic recovery

func (*LSPClient) PrepareRename

func (c *LSPClient) PrepareRename(ctx context.Context, filePath string, line, column int) (string, error)

PrepareRename calls textDocument/prepareRename to get the current symbol

func (*LSPClient) Rename

func (c *LSPClient) Rename(ctx context.Context, filePath string, line, column int, newName string) (*protocol.WorkspaceEdit, error)

Rename performs the actual rename operation

func (*LSPClient) SyncDocument

func (c *LSPClient) SyncDocument(ctx context.Context, filePath string) error

SyncDocument sends textDocument/didChange to update the LSP server's view of a file This should be called after modifying files to keep the LSP server in sync

type LanguageServer

type LanguageServer struct {
	Language string   // Language name (e.g., "go", "python", "typescript")
	Command  string   // Command to execute (e.g., "gopls", "pyright-langserver")
	Args     []string // Arguments to pass to the command
}

LanguageServer represents configuration for a language server

func FindServerForLanguage

func FindServerForLanguage(ctx context.Context, logger *logrus.Logger, language string) (*LanguageServer, error)

FindServerForLanguage finds an available LSP server for the given language

type ProcessTracker

type ProcessTracker struct {
	// contains filtered or unexported fields
}

ProcessTracker tracks LSP server processes for cleanup

func GetProcessTracker

func GetProcessTracker(logger *logrus.Logger) *ProcessTracker

GetProcessTracker returns the global process tracker instance

func (*ProcessTracker) CleanupOrphaned

func (pt *ProcessTracker) CleanupOrphaned()

CleanupOrphaned kills any orphaned LSP server processes

func (*ProcessTracker) CleanupStale

func (pt *ProcessTracker) CleanupStale(maxAge time.Duration)

CleanupStale kills processes that have been running too long (>5 minutes)

func (*ProcessTracker) Deregister

func (pt *ProcessTracker) Deregister(pid int)

Deregister removes a process from tracking

func (*ProcessTracker) Register

func (pt *ProcessTracker) Register(pid int, command string, process *os.Process)

Register registers a process for tracking

type RenameRequest

type RenameRequest struct {
	FilePath string `json:"file_path"`
	Line     int    `json:"line"`
	Column   int    `json:"column"`
	NewName  string `json:"new_name"`
	Preview  bool   `json:"preview"`
}

RenameRequest represents a rename operation request

type RenameResult

type RenameResult struct {
	FilesModified      int             `json:"files_modified,omitempty"`
	TotalReplacements  int             `json:"total_replacements,omitempty"`
	AffectedFiles      []string        `json:"affected_files,omitempty"`      // List of file paths with change counts
	Applied            bool            `json:"applied,omitempty"`             // Only present when true
	Error              string          `json:"error,omitempty"`               // Only present on failure
	RolledBack         bool            `json:"rolled_back,omitempty"`         // True if rollback was performed
	RollbackSuccessful bool            `json:"rollback_successful,omitempty"` // True if rollback succeeded
	BackupLocation     string          `json:"backup_location,omitempty"`     // Path to backup directory (on failure)
	FilesReverted      []string        `json:"files_reverted,omitempty"`      // Files restored during rollback
	ChangePreview      []ChangeSnippet `json:"change_preview,omitempty"`      // Preview of changes (preview mode only)
}

RenameResult represents the result of a rename operation Only returns actionable information - no echo of input parameters

type RenameTransaction

type RenameTransaction struct {
	// contains filtered or unexported fields
}

RenameTransaction manages atomic rename operations with rollback support

func NewRenameTransaction

func NewRenameTransaction() (*RenameTransaction, error)

NewRenameTransaction creates a new transaction for atomic rename operations

func (*RenameTransaction) ApplyWithTracking

func (tx *RenameTransaction) ApplyWithTracking(filePath string, edits []protocol.TextEdit) error

ApplyWithTracking applies edits to a file and tracks the modification

func (*RenameTransaction) BackupFile

func (tx *RenameTransaction) BackupFile(filePath string) error

BackupFile creates a backup of a file before modification

func (*RenameTransaction) Cleanup

func (tx *RenameTransaction) Cleanup() error

Cleanup removes the backup directory on successful completion

func (*RenameTransaction) KeepBackups

func (tx *RenameTransaction) KeepBackups() string

KeepBackups preserves the backup directory for debugging

func (*RenameTransaction) PreflightCheck

func (tx *RenameTransaction) PreflightCheck(edit *protocol.WorkspaceEdit) error

PreflightCheck validates all files can be modified before starting transaction

func (*RenameTransaction) Rollback

func (tx *RenameTransaction) Rollback() ([]string, error)

Rollback restores all modified files from backups

type ServerCache

type ServerCache struct {
	// contains filtered or unexported fields
}

ServerCache caches LSP server availability

func GetServerCache

func GetServerCache() *ServerCache

GetServerCache returns the global server cache instance

func NewServerCache

func NewServerCache() *ServerCache

NewServerCache creates a new server cache with 5-minute expiry

func (*ServerCache) IsAvailable

func (sc *ServerCache) IsAvailable(command string) (bool, bool)

IsAvailable checks if a language server is available (cached)

func (*ServerCache) SetAvailable

func (sc *ServerCache) SetAvailable(command string, available bool)

SetAvailable sets the availability of a language server

Jump to

Keyboard shortcuts

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