mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-19 07:17:11 +09:00
Autoformatting
This commit is contained in:
@@ -419,7 +419,8 @@ func (b *Buffer) lspInit() {
|
||||
var err error
|
||||
b.Server, err = lsp.StartServer(l)
|
||||
if err == nil {
|
||||
b.Server.Initialize(gopath.Dir(b.AbsPath))
|
||||
d, _ := os.Getwd()
|
||||
b.Server.Initialize(d)
|
||||
}
|
||||
}
|
||||
if b.HasLSP() {
|
||||
@@ -505,6 +506,17 @@ func (b *Buffer) Remove(start, end Loc) {
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyEdit performs a LSP text edit on the buffer
|
||||
func (b *Buffer) ApplyEdit(e lspt.TextEdit) {
|
||||
if len(e.NewText) == 0 {
|
||||
// deletion
|
||||
b.Remove(toLoc(e.Range.Start), toLoc(e.Range.End))
|
||||
} else {
|
||||
// insertion
|
||||
b.Insert(toLoc(e.Range.Start), e.NewText)
|
||||
}
|
||||
}
|
||||
|
||||
// FileType returns the buffer's filetype
|
||||
func (b *Buffer) FileType() string {
|
||||
return b.Settings["filetype"].(string)
|
||||
|
||||
@@ -2,6 +2,7 @@ package buffer
|
||||
|
||||
import (
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"go.lsp.dev/protocol"
|
||||
)
|
||||
|
||||
// Loc stores a location
|
||||
@@ -146,3 +147,10 @@ func clamp(pos Loc, la *LineArray) Loc {
|
||||
}
|
||||
return pos
|
||||
}
|
||||
|
||||
func toLoc(r protocol.Position) Loc {
|
||||
return Loc{
|
||||
X: int(r.Character),
|
||||
Y: int(r.Line),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user