Skip to content

Commit

Permalink
wip cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Nov 8, 2024
1 parent b749543 commit 27ce7dd
Show file tree
Hide file tree
Showing 11 changed files with 1,164 additions and 1,032 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
go.gopad.dev/fuzzysearch v0.0.0-20240526153819-c12185e04fe2
go.gopad.dev/go-tree-sitter v0.0.0-20240620185356-89c6dfd0fb37
go.lsp.dev/jsonrpc2 v0.10.0
go.lsp.dev/protocol v0.12.1-0.20240203004437-3c0d4339e51f
golang.org/x/text v0.19.0
Expand All @@ -38,6 +37,7 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
Expand All @@ -47,6 +47,7 @@ require (
github.com/segmentio/asm v1.2.0 // indirect
github.com/segmentio/encoding v0.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tree-sitter/go-tree-sitter v0.24.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2 // indirect
go.lsp.dev/uri v0.3.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand Down Expand Up @@ -78,6 +80,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tree-sitter/go-tree-sitter v0.24.0 h1:kRZb6aBNfcI/u0Qh8XEt3zjNVnmxTisDBN+kXK0xRYQ=
github.com/tree-sitter/go-tree-sitter v0.24.0/go.mod h1:x681iFVoLMEwOSIHA1chaLkXlroXEN7WY+VHGFaoDbk=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
go.gopad.dev/fuzzysearch v0.0.0-20240526153819-c12185e04fe2 h1:TJfF4DCI0kn8rOfKkp8r11YRW4I+fr1iMdof9EJ1oaI=
Expand Down
30 changes: 4 additions & 26 deletions gopad/editor/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/charmbracelet/bubbletea/v2"
"go.gopad.dev/go-tree-sitter"
"github.com/tree-sitter/go-tree-sitter/highlight"

Check failure on line 12 in gopad/editor/file/file.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/tree-sitter/go-tree-sitter/highlight; to add it:

Check failure on line 12 in gopad/editor/file/file.go

View workflow job for this annotation

GitHub Actions / test

no required module provides package github.com/tree-sitter/go-tree-sitter/highlight; to add it:

"go.gopad.dev/gopad/gopad/ls"
"go.gopad.dev/gopad/internal/buffer"
Expand Down Expand Up @@ -77,7 +77,7 @@ type File struct {
Buffer buffer.Buffer
Mode Mode
Language *Language
Tree *Tree
Highlighter *highlight.Highlighter
Autocomplete *Autocompleter

diagnosticVersions map[ls.DiagnosticType]int32
Expand All @@ -86,9 +86,6 @@ type File struct {
inlayHintsVersion int32
InlayHints []ls.InlayHint

matchesVersion int32
Matches [][]*Match

Declarations []ls.FileLocation
Definitions []ls.FileLocation
TypeDefinitions []ls.FileLocation
Expand Down Expand Up @@ -116,8 +113,7 @@ func (f *File) SetLanguage(name string) {
f.Language = language

// reset tree and matches when changing language
f.Tree = nil
f.Matches = nil
f.Highlighter = nil
}

func (f *File) Range() buffer.Range {
Expand All @@ -133,17 +129,9 @@ func (f *File) recordChange(change Change) tea.Cmd {
log.Println("record change time: ", time.Since(now))
}()

var cmds []tea.Cmd
if cmd := f.UpdateTree(sitter.EditInput{
StartIndex: change.StartIndex,
OldEndIndex: change.OldEndIndex,
NewEndIndex: change.NewEndIndex,
}); cmd != nil {
cmds = append(cmds, cmd)
}

f.Changes = append(f.Changes, change)

var cmds []tea.Cmd
cmds = append(cmds, tea.Sequence(
ls.FileChanged(f.Buffer.Name(), f.Buffer.Version(), change.Text),
ls.GetInlayHint(f.Buffer.Name(), f.Buffer.Version(), f.Range()),
Expand All @@ -156,16 +144,6 @@ func (f *File) InsertNewLine(p buffer.Point) tea.Cmd {
startIndex := f.Buffer.ByteIndex(p)
f.Buffer.InsertNewLine(p)

if len(f.Matches) > p.Row {
for _, lineMatches := range f.Matches[p.Row:] {
for _, match := range lineMatches {
match.Range.Start.Row++
match.Range.End.Row++
}
}
f.Matches = slices.Insert(f.Matches, p.Row, make([]*Match, 0))
}

return f.recordChange(Change{
StartIndex: uint32(startIndex),
OldEndIndex: uint32(startIndex + 1),
Expand Down
Loading

0 comments on commit 27ce7dd

Please sign in to comment.