fixer

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseFixing

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

BaseFixing implements Fixing.

func NewBaseFixing added in v0.40.0

func NewBaseFixing(protoFileName string) (*BaseFixing, error)

NewBaseFixing creates a BaseFixing.

func (*BaseFixing) Content added in v0.40.0

func (f *BaseFixing) Content() []byte

Content returns f.content.

func (*BaseFixing) Finally

func (f *BaseFixing) Finally() error

Finally writes the fixed content to the file.

func (*BaseFixing) LineEnding added in v0.40.0

func (f *BaseFixing) LineEnding() string

LineEnding is a detected line ending.

func (*BaseFixing) Lines added in v0.36.0

func (f *BaseFixing) Lines() []string

Lines returns the line format of f.content.

func (*BaseFixing) Replace added in v0.40.0

func (f *BaseFixing) Replace(t TextEdit)

Replace records a textedit to replace the old with the next later.

func (*BaseFixing) ReplaceAll added in v0.36.0

func (f *BaseFixing) ReplaceAll(proc func(lines []string) []string)

ReplaceAll replaces the lines.

func (*BaseFixing) ReplaceContent added in v0.37.0

func (f *BaseFixing) ReplaceContent(proc func(content []byte) []byte)

ReplaceContent replaces entire content.

func (*BaseFixing) ReplaceText

func (f *BaseFixing) ReplaceText(line int, old, new string)

ReplaceText replaces the text at the line.

func (*BaseFixing) SearchAndReplace added in v0.36.0

func (f *BaseFixing) SearchAndReplace(startPos meta.Position, lex func(lex *lexer.Lexer) TextEdit) error

SearchAndReplace locates text edits and replaces with them.

type Fixer

type Fixer interface {
	// NOTE: This method is insufficient to process unexpected multi-line contents.
	ReplaceText(line int, old, new string)
	ReplaceAll(proc func(lines []string) []string)

	SearchAndReplace(startPos meta.Position, lex func(lex *lexer.Lexer) TextEdit) error
	ReplaceContent(proc func(content []byte) []byte)

	Lines() []string
}

Fixer provides the ways to operate the proto content.

type Fixing

type Fixing interface {
	Fixer
	Finally() error
}

Fixing adds the way to modify the proto file to Fixer.

func NewFixing

func NewFixing(fixMode bool, proto *parser.Proto) (Fixing, error)

NewFixing creates a fixing, depending on fixMode.

type NopFixing

type NopFixing struct{}

NopFixing does nothing.

func (NopFixing) Finally

func (f NopFixing) Finally() error

Finally noop

func (NopFixing) Lines added in v0.36.0

func (f NopFixing) Lines() []string

Lines noop.

func (NopFixing) ReplaceAll added in v0.36.0

func (f NopFixing) ReplaceAll(proc func(lines []string) []string)

ReplaceAll noop

func (NopFixing) ReplaceContent added in v0.37.0

func (f NopFixing) ReplaceContent(proc func(content []byte) []byte)

ReplaceContent noop.

func (NopFixing) ReplaceText

func (f NopFixing) ReplaceText(line int, old, new string)

ReplaceText noop

func (NopFixing) SearchAndReplace added in v0.36.0

func (f NopFixing) SearchAndReplace(startPos meta.Position, lex func(lexer *lexer.Lexer) TextEdit) error

SearchAndReplace noop

type TextEdit added in v0.36.0

type TextEdit struct {
	Pos     int
	End     int // Inclusive. If the target is abc, pos and end are 1 and 3, respectively.
	NewText []byte
}

TextEdit represents the replacement of the code between Pos and End with the new text.

Jump to

Keyboard shortcuts

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