question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

expose only the positions of those brackets colored by native bracket pair colorization

See original GitHub issue

Question: I know exposing tokens to extensions is a headache, but is it now possible and non-headache to expose only the positions of those brackets colored by native bracket pair colorization? like this: {type: "{" | "}" | "(" | ")" | "[" | "]"; line: number; column: number; }[] or like this: {type: "{" | "}" | "(" | ")" | "[" | "]"; globalStringIndex: number; }[]

No tree structure needed, just a simple array of positions. It will be super huge speed upgrade for Blockman (already 19k installs).

_Originally posted by @leodevbro in https://github.com/microsoft/vscode/issues/128465#issuecomment-900604355_

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
leodevbrocommented, Feb 11, 2022

getBracketPairs is async. When the call returns, the text buffer could have already been modified and not agree with content anymore.

In case of Blockman extension, I guess currently it works basically that way, when typing text on keyboard Blockman cannot analyze updated content quickly enough to keep up the changes in real time, so it deals with timers (It’s like a refresh rate or frames per second in video games. If refresh rate is low, the game will have less CPU/GPU overload and will be more performant). On each text change event, Blockman starts re-analyzing the file after t seconds. If we set the t to be 0 seconds, the editor UI will most likely freeze during typing some text on the keyboard, so, that’s why the default time is 1.2 seconds. The freezing is still noticeable during typing, but it’s not a deal breaker for many coders because it feels rare and short.

Note: the timer is triggered only for the last change event and is not triggered on every event during the 1.2 seconds, so it will not get overloaded and bounced.

So, yeah, with Blockman, if text changes during the ongoing analyzing/rendering process, the blocks will be rendered for the old text, so it will look incorrect visually, but Blockman detects the change events and re-renders the blocks again with the new content. So the blocks finally are being rendered correctly. So, I guess the the blocks appear incorrect for about 1 second (average time) when working on a 5,000 line file, but if it will have access to the native tokens of brackets, I think this average time will go down to maybe 0.1 seconds, and so it will feel more comfy.

1reaction
hedietcommented, Nov 8, 2021

The problem is this:

const content = this.document.getText();
const bracketPairs = await vscode.languages.getBracketPairs(this.document.uri, this.getViewPortRange());
// use content and bracket pairs to create decorations

How can we prevent someone from doing this? The issue here is that getBracketPairs is async. When the call returns, the text buffer could have already been modified and not agree with content anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bracket pair colorization 10000x faster - Visual Studio Code
Bracket pair colorization is all about quickly determining all brackets and their (absolute) nesting level in the viewport. The viewport can be ...
Read more >
Native Bracket Pair Colourization in VS Code
Configure native bracket pair colourization​​ All colors are themeable and up to six colors can be configured. If playback doesn't begin shortly, ...
Read more >
Adding color to bracket pairs - Visual Studio Blog
We call it Rainbow Braces and the first iteration adds basic colorization to curly brackets, square brackets, and parentheses (see image above).
Read more >
VS Code — Native Bracket Pair Colorization - YouTube
In this video, we're gonna be looking at how to enable a newly added VS Code feature that allows us to color parentheses,...
Read more >
Making bracket pair colorization faster - Hacker News
The blog post does a great job of describing why bracket colorization isn't appropriate for the plug-in architecture anyway.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found