-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some issues with suggestions (#437)
I discovered a few bugs in the suggestions rendering logic, which I've fixed in this PR. I've also included a reproducer test. 1. There were cases where multiple edits in one suggestion could cause the renderer to index out of bounds. 2. There were cases where, in multiline mode, extra newline would appear, because newlines ended up at the start or end of a hunk boundary.
- Loading branch information
Showing
8 changed files
with
205 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2020-2025 Buf Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// package stringsx contains extensions to Go's package strings. | ||
package stringsx | ||
|
||
import ( | ||
"github.com/bufbuild/protocompile/internal/ext/iterx" | ||
"github.com/bufbuild/protocompile/internal/ext/unsafex" | ||
"github.com/bufbuild/protocompile/internal/iter" | ||
) | ||
|
||
// EveryFunc verifies that all runes in the string satisfy the given predicate. | ||
func EveryFunc(s string, p func(rune) bool) bool { | ||
return iterx.All(Runes(s), p) | ||
} | ||
|
||
// Runes returns an iterator over the runes in a string. | ||
// | ||
// Each non-UTF-8 byte in the string is yielded as a replacement character (U+FFFD). | ||
func Runes(s string) iter.Seq[rune] { | ||
return func(yield func(r rune) bool) { | ||
for _, r := range s { | ||
if !yield(r) { | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Bytes returns an iterator over the bytes in a string. | ||
func Bytes(s string) iter.Seq[byte] { | ||
return func(yield func(byte) bool) { | ||
for i := 0; i < len(s); i++ { | ||
// Avoid performing a bounds check each loop step. | ||
b := *unsafex.Add(unsafex.StringData(s), i) | ||
if !yield(b) { | ||
return | ||
} | ||
} | ||
} | ||
} |