Skip to content

Commit

Permalink
wip shit
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Nov 18, 2024
1 parent 6ca1fa5 commit ee6c7c9
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 23 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
12 changes: 6 additions & 6 deletions gopad/editor/file/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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()
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion gopad/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion gopad/key_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion gopad/quit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/bubbles/button/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/bubbles/filepicker/filepicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion internal/bubbles/groupedlist/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
1 change: 1 addition & 0 deletions internal/bubbles/help/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/charmbracelet/bubbletea/v2"
"github.com/charmbracelet/lipgloss/v2"

"go.gopad.dev/gopad/internal/bubbles/key"
)

Expand Down
10 changes: 5 additions & 5 deletions internal/xbytes/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand All @@ -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...)
}
Expand All @@ -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
}
Expand Down
11 changes: 7 additions & 4 deletions internal/xbytes/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit ee6c7c9

Please sign in to comment.