| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package fake |
| 6 |
|
| 7 |
import ( |
| 8 |
"golang.org/x/tools/gopls/internal/protocol" |
| 9 |
"golang.org/x/tools/internal/diff" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
func NewEdit(startLine, startColumn, endLine, endColumn uint32, text string) protocol.TextEdit { |
| 17 |
return protocol.TextEdit{ |
| 18 |
Range: protocol.Range{ |
| 19 |
Start: protocol.Position{Line: startLine, Character: startColumn}, |
| 20 |
End: protocol.Position{Line: endLine, Character: endColumn}, |
| 21 |
}, |
| 22 |
NewText: text, |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
func applyEdits(mapper *protocol.Mapper, edits []protocol.TextEdit, windowsLineEndings bool) ([]byte, error) { |
| 30 |
diffEdits, err := protocol.EditsToDiffEdits(mapper, edits) |
| 31 |
if err != nil { |
| 32 |
return nil, err |
| 33 |
} |
| 34 |
patched, err := diff.ApplyBytes(mapper.Content, diffEdits) |
| 35 |
if err != nil { |
| 36 |
return nil, err |
| 37 |
} |
| 38 |
if windowsLineEndings { |
| 39 |
patched = toWindowsLineEndings(patched) |
| 40 |
} |
| 41 |
return patched, nil |
| 42 |
} |