fix: Fix "Mark decorations may not be empty" issue (#325)

This commit is contained in:
Brendan Kellam 2025-06-02 11:22:52 -07:00 committed by GitHub
parent 3b36ffa17e
commit 8a9cdfda77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 8 deletions

View file

@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Fixed ### Fixed
- Fixed issue where new oauth providers weren't being display in the login page - Fixed issue where new oauth providers weren't being display in the login page. [commit](https://github.com/sourcebot-dev/sourcebot/commit/a2e06266dbe5e5ad4c2c3f730c73d64edecedcf7)
- Fixed client side "mark decorations may not be empty" error when viewing certain files. [#325](https://github.com/sourcebot-dev/sourcebot/pull/325)
- Fixed issue where the symbol hover popover would not appear for large source files. [#325](https://github.com/sourcebot-dev/sourcebot/pull/325)
## [4.0.1] - 2025-05-28 ## [4.0.1] - 2025-05-28

View file

@ -20,9 +20,12 @@ export const rangeHighlightingExtension = (range: BrowseHighlightRange) => State
const from = state.doc.line(start.lineNumber).from + start.column - 1; const from = state.doc.line(start.lineNumber).from + start.column - 1;
const to = state.doc.line(end.lineNumber).from + end.column - 1; const to = state.doc.line(end.lineNumber).from + end.column - 1;
return Decoration.set([ const decorations: Range<Decoration>[] = [];
markDecoration.range(from, to), if (from < to) {
]); decorations.push(markDecoration.range(from, to));
}
return Decoration.set(decorations);
} else { } else {
const decorations: Range<Decoration>[] = []; const decorations: Range<Decoration>[] = [];
for (let line = start.lineNumber; line <= end.lineNumber; line++) { for (let line = start.lineNumber; line <= end.lineNumber; line++) {

View file

@ -52,7 +52,7 @@ export const symbolHoverTargetsExtension = StateField.define<DecorationSet>({
// @note: we need to use `ensureSyntaxTree` here (as opposed to `syntaxTree`) // @note: we need to use `ensureSyntaxTree` here (as opposed to `syntaxTree`)
// because we want to parse the entire document, not just the text visible in // because we want to parse the entire document, not just the text visible in
// the current viewport. // the current viewport.
const { data: tree } = measureSync(() => ensureSyntaxTree(state, state.doc.length), "ensureSyntaxTree"); const { data: tree } = measureSync(() => ensureSyntaxTree(state, state.doc.length, Infinity), "ensureSyntaxTree");
const decorations: Range<Decoration>[] = []; const decorations: Range<Decoration>[] = [];
// @note: useful for debugging // @note: useful for debugging
@ -64,7 +64,7 @@ export const symbolHoverTargetsExtension = StateField.define<DecorationSet>({
tree?.iterate({ tree?.iterate({
enter: (node) => { enter: (node) => {
// console.log(node.type.name, getTextAt(node.from, node.to)); // console.log(node.type.name, getTextAt(node.from, node.to));
if (NODE_TYPES.includes(node.type.name)) { if (NODE_TYPES.includes(node.type.name) && node.from < node.to) {
decorations.push(decoration.range(node.from, node.to)); decorations.push(decoration.range(node.from, node.to));
} }
}, },

View file

@ -33,8 +33,13 @@ const matchHighlighter = StateField.define<DecorationSet>({
.map((range, index) => { .map((range, index) => {
const { from, to } = convertToCodeMirrorRange(range, transaction.newDoc); const { from, to } = convertToCodeMirrorRange(range, transaction.newDoc);
const mark = index === selectedMatchIndex ? selectedMatchMark : matchMark; const mark = index === selectedMatchIndex ? selectedMatchMark : matchMark;
if (from < to) {
return mark.range(from, to); return mark.range(from, to);
}); }
return undefined;
})
.filter((decoration) => decoration !== undefined);
highlights = Decoration.set(decorations) highlights = Decoration.set(decorations)
} }