Skip to content

Commit

Permalink
fix(completion): Fix hang when detail text is large (#3533)
Browse files Browse the repository at this point in the history
__Issue:__ In some cases, the 'detail' text for completion is massive... and it hits a degenerate case in Revery's word-wrap / ellipsizing that causes a hang.

__Fix:__ For the completion UI, constrain the amount of detail text we show, to work around the bug and prevent a hang.
  • Loading branch information
bryphe authored May 12, 2021
1 parent 541245c commit 1956285
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
- #3525 - CLI: Fix crash when opening non-existent file in running instance
- #3530 - UX: Fix click inside context menu from closing context menu (fixes #3510)
- #3532 - OSX: Fix crash when opening folder with Unicode characters (fixes #3519)
- #3533 - Completion: Fix hang when detail text is large

### Performance

Expand Down
6 changes: 6 additions & 0 deletions src/Core/Utility/StringEx.re
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ let characterCount = (~startByte, ~endByte, str) => {
loop(0, startByte);
};

let clamp = (~characters, str) => {
let characterCount = characterCount(~startByte=0, ~endByte=characters, str);

Zed_utf8.sub(str, 0, characterCount);
};

let characterToByte = (~index: EditorCoreTypes.CharacterIndex.t, str) => {
let idx = CharacterIndex.toInt(index);
let len = String.length(str);
Expand Down
3 changes: 2 additions & 1 deletion src/Feature/LanguageSupport/Completion.re
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,7 @@ module View = {
let maybeDetail =
switch (detail) {
| Some(detail) when isFocused && remainingWidth > 0 =>
let detail = StringEx.clamp(~characters=128, detail);
<View
style=Style.[
position(`Absolute),
Expand All @@ -1371,7 +1372,7 @@ module View = {
text=detail
/>
</View>
</View>
</View>;
| _ => React.empty
};

Expand Down

0 comments on commit 1956285

Please sign in to comment.