diff --git a/go.mod b/go.mod index ea970ae..32d483d 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +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 go.lsp.dev/protocol => github.com/gopad-dev/protocol v0.0.0-20240916085830-4815610e4100 ) diff --git a/go.sum b/go.sum index 87f1ddd..34a5736 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +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/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= @@ -86,8 +88,6 @@ 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/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb h1:A8425heRM8mylnv4H58FPUiH+aYivyitre0PzxrfmWs= github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb/go.mod h1:dOF6gtQiF9UwNh995T5OphYmtIypkjsp3ap7r9AN/iA= github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148 h1:AfFPZwtwGN01BW1jDdqBVqscTwetvMpydqYZz57RSlc= diff --git a/gopad/editor/file/highlight.go b/gopad/editor/file/highlight.go index c725736..bc2f7fb 100644 --- a/gopad/editor/file/highlight.go +++ b/gopad/editor/file/highlight.go @@ -346,7 +346,7 @@ main: for match.Match.PatternIndex < layer.Config.HighlightsPatternIndex { // If the node represents a local scope, push a new local scope onto // the scope stack. - if layer.Config.LocalScopeCaptureIndex != nil && uint(capture.Index) == *layer.Config.LocalScopeCaptureIndex { + if layer.Config.LocalScopeCaptureIndex != nil && capture.Index == *layer.Config.LocalScopeCaptureIndex { definitionHighlight = nil scope := LocalScope{ Inherits: true, @@ -359,7 +359,7 @@ main: } } layer.ScopeStack = append(layer.ScopeStack, scope) - } else if layer.Config.LocalDefCaptureIndex != nil && uint(capture.Index) == *layer.Config.LocalDefCaptureIndex { + } else if layer.Config.LocalDefCaptureIndex != nil && capture.Index == *layer.Config.LocalDefCaptureIndex { // If the node represents a definition, add a new definition to the // local scope at the top of the scope stack. referenceHighlight = nil @@ -368,7 +368,7 @@ main: var valueRange tree_sitter.Range for _, matchCapture := range match.Match.Captures { - if layer.Config.LocalDefValueCaptureIndex != nil && uint(matchCapture.Index) == *layer.Config.LocalDefValueCaptureIndex { + if layer.Config.LocalDefValueCaptureIndex != nil && matchCapture.Index == *layer.Config.LocalDefValueCaptureIndex { valueRange = matchCapture.Node.Range() } } @@ -383,7 +383,7 @@ main: }) definitionHighlight = scope.LocalDefs[len(scope.LocalDefs)-1].Highlight } - } else if layer.Config.LocalRefCaptureIndex != nil && uint(capture.Index) == *layer.Config.LocalRefCaptureIndex && definitionHighlight == nil { + } else if layer.Config.LocalRefCaptureIndex != nil && capture.Index == *layer.Config.LocalRefCaptureIndex && definitionHighlight == nil { // If the node represents a reference, then try to find the corresponding // definition in the scope stack. definitionHighlight = nil @@ -600,9 +600,9 @@ func (c HighlightConfiguration) injectionForMatch(query *tree_sitter.Query, matc for _, capture := range match.Captures { index := capture.Index - if uint(index) == languageCaptureIndex { + if index == languageCaptureIndex { languageName = capture.Node.Utf8Text(source) - } else if uint(index) == contentCaptureIndex { + } else if index == contentCaptureIndex { contentNode = &capture.Node } } diff --git a/gopad/help.go b/gopad/help.go index b52b36d..3f9b24c 100644 --- a/gopad/help.go +++ b/gopad/help.go @@ -3,10 +3,10 @@ package gopad import ( "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss/v2" - "go.gopad.dev/gopad/internal/bubbles/key" "go.gopad.dev/gopad/gopad/config" "go.gopad.dev/gopad/internal/bubbles/help" + "go.gopad.dev/gopad/internal/bubbles/key" "go.gopad.dev/gopad/internal/bubbles/overlay" ) diff --git a/gopad/key_mapper.go b/gopad/key_mapper.go index 3764074..e0774ac 100644 --- a/gopad/key_mapper.go +++ b/gopad/key_mapper.go @@ -5,9 +5,9 @@ import ( "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss/v2" - "go.gopad.dev/gopad/internal/bubbles/key" "go.gopad.dev/gopad/gopad/config" + "go.gopad.dev/gopad/internal/bubbles/key" "go.gopad.dev/gopad/internal/bubbles/overlay" ) diff --git a/gopad/quit.go b/gopad/quit.go index af8b69d..62f2cf6 100644 --- a/gopad/quit.go +++ b/gopad/quit.go @@ -3,10 +3,10 @@ package gopad import ( "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss/v2" - "go.gopad.dev/gopad/internal/bubbles/key" "go.gopad.dev/gopad/gopad/config" "go.gopad.dev/gopad/internal/bubbles/button" + "go.gopad.dev/gopad/internal/bubbles/key" "go.gopad.dev/gopad/internal/bubbles/overlay" ) diff --git a/internal/bubbles/button/button.go b/internal/bubbles/button/button.go index 20334e9..d33d819 100644 --- a/internal/bubbles/button/button.go +++ b/internal/bubbles/button/button.go @@ -75,7 +75,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { switch msg := msg.(type) { case tea.MouseReleaseMsg: switch { - case mouse.Matches((msg), m.zoneID(), tea.MouseLeft): + case mouse.Matches(msg, m.zoneID(), tea.MouseLeft): cmds = append(cmds, m.OnClick()) return m, tea.Batch(cmds...) } diff --git a/internal/bubbles/filepicker/filepicker.go b/internal/bubbles/filepicker/filepicker.go index 313819b..be9693e 100644 --- a/internal/bubbles/filepicker/filepicker.go +++ b/internal/bubbles/filepicker/filepicker.go @@ -10,9 +10,9 @@ import ( "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss/v2" "github.com/dustin/go-humanize" - "go.gopad.dev/gopad/internal/bubbles/key" "go.gopad.dev/gopad/internal/bubbles/help" + "go.gopad.dev/gopad/internal/bubbles/key" ) var ( diff --git a/internal/bubbles/groupedlist/list.go b/internal/bubbles/groupedlist/list.go index 1a11681..d0f4602 100644 --- a/internal/bubbles/groupedlist/list.go +++ b/internal/bubbles/groupedlist/list.go @@ -3,8 +3,8 @@ package groupedlist import ( "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss/v2" - "go.gopad.dev/gopad/internal/bubbles/key" + "go.gopad.dev/gopad/internal/bubbles/key" "go.gopad.dev/gopad/internal/bubbles/textinput" ) diff --git a/internal/bubbles/help/help.go b/internal/bubbles/help/help.go index 4e7e6a0..7c1af92 100644 --- a/internal/bubbles/help/help.go +++ b/internal/bubbles/help/help.go @@ -5,6 +5,7 @@ import ( "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss/v2" + "go.gopad.dev/gopad/internal/bubbles/key" ) diff --git a/internal/xbytes/bytes.go b/internal/xbytes/bytes.go index 8634260..300603e 100644 --- a/internal/xbytes/bytes.go +++ b/internal/xbytes/bytes.go @@ -179,7 +179,7 @@ func Insert(s []byte, i int, b ...byte) []byte { return append(b, s...) } - ri := RuneIndex(s, i) + ri := ByteIndex(s, i) if ri == -1 || ri == len(s) { return append(s, b...) } @@ -188,8 +188,8 @@ func Insert(s []byte, i int, b ...byte) []byte { } func Replace(s []byte, start int, end int, b ...byte) []byte { - startIndex := RuneIndex(s, start) - endIndex := RuneIndex(s, end) + startIndex := ByteIndex(s, start) + endIndex := ByteIndex(s, end) if startIndex == -1 || endIndex == -1 { return append(s, b...) } @@ -198,8 +198,8 @@ func Replace(s []byte, start int, end int, b ...byte) []byte { } func Delete(s []byte, start int, end int) []byte { - startIndex := RuneIndex(s, start) - endIndex := RuneIndex(s, end) + startIndex := ByteIndex(s, start) + endIndex := ByteIndex(s, end) if startIndex == -1 || endIndex == -1 { return s } diff --git a/internal/xbytes/bytes_test.go b/internal/xbytes/bytes_test.go index 9fd67ca..c3a6834 100644 --- a/internal/xbytes/bytes_test.go +++ b/internal/xbytes/bytes_test.go @@ -251,26 +251,29 @@ func TestInsert(t *testing.T) { func TestReplace(t *testing.T) { s := []struct { data []byte - i int + from int + to int data2 []byte expected []byte }{ { data: []byte("Hello, 世界"), - i: 7, + from: 7, + to: 7, data2: []byte("界"), expected: []byte("Hello, 界界"), }, { data: []byte("Hello, 世界"), - i: 8, + from: 8, + to: 8, data2: []byte("a"), expected: []byte("Hello, 世a"), }, } for _, d := range s { - actual := Replace(d.data, d.i, d.data2...) + actual := Replace(d.data, d.from, d.to, d.data2...) assert.Equal(t, d.expected, actual) } }