Skip to content

Commit

Permalink
update to working go-tree-sitter & fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Nov 21, 2024
1 parent 2b63626 commit 45bcab7
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 49 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23
replace (
github.com/charmbracelet/lipgloss/v2 => github.com/gopad-dev/lipgloss/v2 v2.0.0-20241116225007-513a66c72a0b
github.com/lrstanley/bubblezone => github.com/gopad-dev/bubblezone v0.0.0-20240919125415-44caa82cfbd5
github.com/tree-sitter/go-tree-sitter => github.com/gopad-dev/go-tree-sitter-new v0.0.0-20241111011602-a1b6e90961a1
github.com/tree-sitter/go-tree-sitter => github.com/gopad-dev/go-tree-sitter-new v0.0.0-20241121002053-3e4ecb5d8c7b
go.lsp.dev/protocol => github.com/gopad-dev/protocol v0.0.0-20240916085830-4815610e4100
)

Expand Down Expand Up @@ -33,7 +33,7 @@ require (
github.com/charmbracelet/lipgloss v1.0.0 // indirect
github.com/charmbracelet/x/cellbuf v0.0.5 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/charmbracelet/x/wcwidth v0.0.0-20241119170951-e919f77bf23b // indirect
github.com/charmbracelet/x/wcwidth v0.0.0-20241120212915-1c56a76fb03b // indirect
github.com/charmbracelet/x/windows v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/charmbracelet/x/cellbuf v0.0.5 h1:LYmOqjZqoLeL4bgafJu+HZesy5zIdjgSYFk
github.com/charmbracelet/x/cellbuf v0.0.5/go.mod h1:FaDNlvrPSNCEnih536+xi5f8iqxRQfDA20TVTs30CPU=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/charmbracelet/x/wcwidth v0.0.0-20241119170951-e919f77bf23b h1:TF0bhQRbHgu+zGe5Ix6tFam8A5hp3S3QAkw/5TxXHu8=
github.com/charmbracelet/x/wcwidth v0.0.0-20241119170951-e919f77bf23b/go.mod h1:hyua5CY63kyl7IfyIxv1SjVEqoKze/XmDkEglItuVjA=
github.com/charmbracelet/x/wcwidth v0.0.0-20241120212915-1c56a76fb03b h1:4P86lAmBq7Omib4i3JdeWs/J0tKQaWwhMHp8J02GSdw=
github.com/charmbracelet/x/wcwidth v0.0.0-20241120212915-1c56a76fb03b/go.mod h1:hyua5CY63kyl7IfyIxv1SjVEqoKze/XmDkEglItuVjA=
github.com/charmbracelet/x/windows v0.2.0 h1:ilXA1GJjTNkgOm94CLPeSz7rar54jtFatdmoiONPuEw=
github.com/charmbracelet/x/windows v0.2.0/go.mod h1:ZibNFR49ZFqCXgP76sYanisxRyC+EYrBE7TTknD8s1s=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand All @@ -33,8 +33,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gopad-dev/bubblezone v0.0.0-20240919125415-44caa82cfbd5 h1:SPW30KtFPjJq33djuewVitKLRpMpDl3DsI6OpX/g/mc=
github.com/gopad-dev/bubblezone v0.0.0-20240919125415-44caa82cfbd5/go.mod h1:+iJ0NDEFCan/So8PIMgkqSPiPqZwpJkDp3bYfvkurWg=
github.com/gopad-dev/go-tree-sitter-new v0.0.0-20241111011602-a1b6e90961a1 h1:ehTeX0012TnGKq5s3hd0fjy5rqkkWMtQYvbsiT6RMwI=
github.com/gopad-dev/go-tree-sitter-new v0.0.0-20241111011602-a1b6e90961a1/go.mod h1:EvIVhMvvPNvhu9x+ddSPxSnUEU5AnsSwi1LMqXIVE3A=
github.com/gopad-dev/go-tree-sitter-new v0.0.0-20241121002053-3e4ecb5d8c7b h1:noci54Nl638f8+Johwzvvtr4yO762NsvXYObKr7Mrgw=
github.com/gopad-dev/go-tree-sitter-new v0.0.0-20241121002053-3e4ecb5d8c7b/go.mod h1:x681iFVoLMEwOSIHA1chaLkXlroXEN7WY+VHGFaoDbk=
github.com/gopad-dev/lipgloss/v2 v2.0.0-20241116225007-513a66c72a0b h1:YlNZhzHgqqQZOR6DI6EshVDD3NM8BIvaXZz879trUqo=
github.com/gopad-dev/lipgloss/v2 v2.0.0-20241116225007-513a66c72a0b/go.mod h1:72/7KVsLdRldv/CeBjZx6igXIZ9CFtBzQUmDEbhXZ3w=
github.com/gopad-dev/protocol v0.0.0-20240916085830-4815610e4100 h1:l7dkmmJhrMLS9JhvwUtj5MxUwEVqrXakv0b3uNFD03A=
Expand Down
28 changes: 21 additions & 7 deletions gopad/editor/doc/syntax.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package doc

import (
"bytes"
"context"
"encoding/binary"
"fmt"
Expand Down Expand Up @@ -250,8 +251,8 @@ func (s *SyntaxLayers) Update(ctx context.Context, currentRev uint64, newRev uin
if cursor == nil {
cursor = tree_sitter.NewQueryCursor()
}
// cursor.SetByteRange(0, ^uint(0))
// cursor.SetMatchLimit(TreeSitterMatchLimit)
cursor.SetByteRange(0, ^uint(0))
cursor.SetMatchLimit(TreeSitterMatchLimit)

touched := map[slotmap.LayerID]struct{}{}

Expand Down Expand Up @@ -412,8 +413,8 @@ func (s *SyntaxLayers) HighlightIter(ctx context.Context, source []byte, r *Byte
}
}

// cursor.SetByteRange(r.StartByte, r.EndByte)
// cursor.SetMatchLimit(TreeSitterMatchLimit)
cursor.SetByteRange(r.StartByte, r.EndByte)
cursor.SetMatchLimit(TreeSitterMatchLimit)

captures := make([]queryCapture, 0)
queryCaptures := cursor.Captures(layer.Config.Query, layer.Tree.RootNode(), source)
Expand Down Expand Up @@ -509,9 +510,22 @@ type LanguageLayer struct {
}

func (l *LanguageLayer) Hash(h *hash.Hasher) {
_ = binary.Write(h, binary.LittleEndian, l.Depth)
_ = binary.Write(h, binary.LittleEndian, l.Config.LanguageName)
_ = binary.Write(h, binary.LittleEndian, l.Ranges)
_ = binary.Write(h, binary.LittleEndian, uint8(l.Depth))
_ = binary.Write(h, binary.LittleEndian, []byte(l.Config.LanguageName))
_ = binary.Write(h, binary.LittleEndian, rangesToBytes(l.Ranges))
}

func rangesToBytes(ranges []tree_sitter.Range) []byte {
b := bytes.Buffer{}
for _, r := range ranges {
_ = binary.Write(&b, binary.LittleEndian, uint64(r.StartByte))
_ = binary.Write(&b, binary.LittleEndian, uint64(r.EndByte))
_ = binary.Write(&b, binary.LittleEndian, uint64(r.StartPoint.Row))
_ = binary.Write(&b, binary.LittleEndian, uint64(r.StartPoint.Column))
_ = binary.Write(&b, binary.LittleEndian, uint64(r.EndPoint.Row))
_ = binary.Write(&b, binary.LittleEndian, uint64(r.EndPoint.Column))
}
return b.Bytes()
}

func (l *LanguageLayer) parse(ctx context.Context, parser *tree_sitter.Parser, source []byte, hasEdits bool) error {
Expand Down
55 changes: 28 additions & 27 deletions gopad/editor/doc_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (v *DocumentView) Focus() tea.Cmd {

func (v *DocumentView) Blur() tea.Cmd {
v.focused = false
//return tea.HideCursor
// return tea.HideCursor
return nil
}

Expand Down Expand Up @@ -215,7 +215,7 @@ func (v DocumentView) Update(msg tea.Msg) (DocumentView, tea.Cmd) {
if msg.Name != v.Doc.Name {
return v, tea.Batch(cmds...)
}
//v.file.Autocomplete.SetCompletions(msg.Completions)
// v.file.Autocomplete.SetCompletions(msg.Completions)
return v, tea.Batch(cmds...)
case ls.UpdateInlayHintMsg:
if msg.Name != v.Doc.Name {
Expand Down Expand Up @@ -396,7 +396,7 @@ func (v DocumentView) Update(msg tea.Msg) (DocumentView, tea.Cmd) {
if s := v.Doc.Selection(); s == nil || s.IsEmpty() {
v.Doc.ResetMark()
}
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
return v, tea.Batch(cmds...)
case mouse.MatchesZone(msg, z, tea.MouseRight):
// TODO: open context menu?
Expand All @@ -420,7 +420,7 @@ func (v DocumentView) Update(msg tea.Msg) (DocumentView, tea.Cmd) {
if s := v.Doc.Selection(); s == nil || s.IsEmpty() {
v.Doc.ResetMark()
}
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
return v, tea.Batch(cmds...)
}
}
Expand Down Expand Up @@ -448,19 +448,19 @@ func (v DocumentView) Update(msg tea.Msg) (DocumentView, tea.Cmd) {
switch {
case mouse.MatchesZone(msg, z, tea.MouseWheelLeft), mouse.MatchesZone(msg, z, tea.MouseWheelDown, tea.ModShift):
v.Doc.MoveCursorLeft(1)
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
return v, tea.Batch(cmds...)
case mouse.MatchesZone(msg, z, tea.MouseWheelRight), mouse.MatchesZone(msg, z, tea.MouseWheelUp, tea.ModShift):
v.Doc.MoveCursorRight(1)
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
return v, tea.Batch(cmds...)
case mouse.MatchesZone(msg, z, tea.MouseWheelUp):
v.Doc.MoveCursorUp(1)
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
return v, tea.Batch(cmds...)
case mouse.MatchesZone(msg, z, tea.MouseWheelDown):
v.Doc.MoveCursorDown(1)
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
return v, tea.Batch(cmds...)
}
}
Expand All @@ -474,13 +474,13 @@ func (v DocumentView) Update(msg tea.Msg) (DocumentView, tea.Cmd) {
p := v.Doc.Cursor()
cmds = append(cmds, ls.GetAutocompletion(v.Doc.Name, p))
return v, tea.Batch(cmds...)
//case key.Matches(msg, config.Keys.Cancel) && v.file.Autocomplete.Visible():
// case key.Matches(msg, config.Keys.Cancel) && v.file.Autocomplete.Visible():
// v.file.Autocomplete.ClearCompletions()
//case key.Matches(msg, config.Keys.Editor.Autocomplete.Next) && v.file.Autocomplete.Visible():
// case key.Matches(msg, config.Keys.Editor.Autocomplete.Next) && v.file.Autocomplete.Visible():
// v.file.Autocomplete.Next()
//case key.Matches(msg, config.Keys.Editor.Autocomplete.Prev) && v.file.Autocomplete.Visible():
// case key.Matches(msg, config.Keys.Editor.Autocomplete.Prev) && v.file.Autocomplete.Visible():
// v.file.Autocomplete.Previous()
//case key.Matches(msg, config.Keys.Editor.Autocomplete.Apply) && v.file.Autocomplete.Visible():
// case key.Matches(msg, config.Keys.Editor.Autocomplete.Apply) && v.file.Autocomplete.Visible():
// completion := v.file.Autocomplete.Selected()
// if completion != nil {
// if completion.Text != "" {
Expand Down Expand Up @@ -566,19 +566,19 @@ func (v DocumentView) Update(msg tea.Msg) (DocumentView, tea.Cmd) {
Row: -1,
Col: v.Doc.Buffer.LineLen(c.Row),
})
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
case key.Matches(msg, config.Keys.Editor.Navigation.FileStart):
v.Doc.SetCursor(buffer.Point{
Row: 0,
Col: 0,
})
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
case key.Matches(msg, config.Keys.Editor.Navigation.FileEnd):
v.Doc.SetCursor(buffer.Point{
Row: v.Doc.Buffer.LinesLen() - 1,
Col: v.Doc.Buffer.LineLen(v.Doc.Buffer.LinesLen() - 1),
})
//cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
// cmds = append(cmds, v.file.Autocomplete.Update(v.Cursor()))
case key.Matches(msg, config.Keys.Editor.Navigation.GoTo):
cmds = append(cmds, overlay.Open(NewGoToOverlay(v.Doc.Cursor())))
return v, tea.Batch(cmds...)
Expand Down Expand Up @@ -635,32 +635,32 @@ func (v DocumentView) Update(msg tea.Msg) (DocumentView, tea.Cmd) {
if s != nil {
cmds = append(cmds, v.Doc.Insert(v.Doc.Cursor(), v.Doc.SelectionBytes()))
v.Doc.ResetMark()
} else {
// cmds = append(cmds, v.file.DuplicateLine(v.Cursor().Row))
// } else {
// cmds = append(cmds, v.file.DuplicateLine(v.Cursor().Row))
}
case key.Matches(msg, config.Keys.Editor.Edit.DeleteWordLeft):
s := v.Doc.Selection()
if s != nil {
// cmds = append(cmds, v.file.DeleteRange(*s))
cmds = append(cmds, v.Doc.DeleteRange(*s))
v.Doc.ResetMark()
} else {
// cmds = append(cmds, v.file.DeleteWordLeft(v.Cursor()))
// } else {
// cmds = append(cmds, v.file.DeleteWordLeft(v.Cursor()))
}
case key.Matches(msg, config.Keys.Editor.Edit.DeleteWordRight):
s := v.Doc.Selection()
if s != nil {
// cmds = append(cmds, v.file.DeleteRange(*s))
cmds = append(cmds, v.Doc.DeleteRange(*s))
v.Doc.ResetMark()
} else {
// cmds = append(cmds, v.file.DeleteWordRight(v.Cursor()))
// } else {
// cmds = append(cmds, v.file.DeleteWordRight(v.Cursor()))
}
case key.Matches(msg, config.Keys.Editor.Edit.DeleteLine):
s := v.Doc.Selection()
if s != nil {
// cmds = append(cmds, v.file.DeleteRange(*s))
cmds = append(cmds, v.Doc.DeleteRange(*s))
v.Doc.ResetMark()
} else {
// cmds = append(cmds, v.file.DeleteLine(v.Cursor().Row))
// } else {
// cmds = append(cmds, v.file.DeleteLine(v.Cursor().Row))
}
case key.Matches(msg, config.Keys.Editor.Edit.ToggleComment):
// TODO: implement
Expand Down Expand Up @@ -758,7 +758,7 @@ func (v *DocumentView) View(width int, height int, border bool, debug bool, offs

nextStyle, stop := iter.Pull(v.Doc.HighlightIter(nil))
defer stop()
charStyle, ok := nextStyle()
charStyle, _ := nextStyle()

var (
editorCode string
Expand Down Expand Up @@ -789,6 +789,7 @@ func (v *DocumentView) View(width int, height int, border bool, debug bool, offs

if char.Index >= charStyle.End {
for {
var ok bool
charStyle, ok = nextStyle()
if !ok {
break
Expand Down
1 change: 0 additions & 1 deletion gopad/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ func (e Editor) Update(msg tea.Msg) (Editor, tea.Cmd) {
return e, overlay.Open(NewCloseOverlay([]string{v.Doc.Name}))
}
cmds = append(cmds, CloseFile(v.Doc.Name))

}
return e, tea.Batch(cmds...)
case GoToActionMsg:
Expand Down
4 changes: 3 additions & 1 deletion gopad/gopad.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ func (g Gopad) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func (g Gopad) View() string {
now := time.Now()
defer log.Printf("Render time: %s\n", time.Since(now))
defer func() {
log.Printf("Render time: %s\n", time.Since(now))
}()

height := g.height

Expand Down
4 changes: 2 additions & 2 deletions internal/bubbles/cursor/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
if m.realRow != realRow || m.realCol != realCol {
m.realRow = realRow
m.realCol = realCol
//cmd = tea.SetCursorPosition(realRow, realCol)
// cmd = tea.SetCursorPosition(realRow, realCol)
}
}

Expand Down Expand Up @@ -308,7 +308,7 @@ func (m *Model) SetPosition(row, col int) {
}

// SetOffset sets the offset the cursor is displayed at.
func (m Model) SetOffset(x, y int) {
func (m *Model) SetOffset(x, y int) {
m.offsetX = x
m.offsetY = y
}
Expand Down
7 changes: 2 additions & 5 deletions internal/bubbles/textinput/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

"go.gopad.dev/gopad/internal/bubbles/cursor"
"go.gopad.dev/gopad/internal/bubbles/key"
"go.gopad.dev/gopad/internal/bubbles/notifications"
"go.gopad.dev/gopad/internal/bubbles/runeutil"
)

// Internal messages for clipboard operations.
type pasteMsg string
type pasteErrMsg struct{ error }

// EchoMode sets the input behavior of the text input field.
type EchoMode int
Expand Down Expand Up @@ -496,9 +496,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {

case pasteMsg:
m.insertRunesFromUserInput([]rune(msg))

case pasteErrMsg:
m.Err = msg
}

var cmds []tea.Cmd
Expand Down Expand Up @@ -603,7 +600,7 @@ func Blink() tea.Msg {
func Paste() tea.Msg {
str, err := clipboard.ReadAll()
if err != nil {
return pasteErrMsg{err}
return notifications.Addf("Error pasting from clipboard: %v", err)
}
return pasteMsg(str)
}
Expand Down

0 comments on commit 45bcab7

Please sign in to comment.