Autoformatting

This commit is contained in:
Zachary Yedidia
2020-08-12 16:03:14 -04:00
parent 08f772b7d0
commit c1621086a2
7 changed files with 96 additions and 10 deletions

View File

@@ -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)

View File

@@ -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),
}
}