-
Notifications
You must be signed in to change notification settings - Fork 28.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose only the positions of those brackets colored by native bracket pair colorization #131062
Comments
Oh, thanks so much for posting this feature request. |
Syncing over all bracket positions might be headache. However, I can imagine an async API that you can ask to query bracket pairs in a given range. We don't know the globalStringIndex (only compute line/column for faster queries). /**
* Returns undefined if bracket pair information are not available (e.g. because the feature is disabled or the document is too large).
* Otherwise, returns a list of bracket pairs whose range intersects the given range.
*/
async function provideBracketPairs(model: TextModel, range: Range): Promise<BracketPairs | undefined>;
interface BracketPairs {
pairs: BracketPair[];
truncated: boolean; // Indicates whether there are more positions that are not included for performance reasons
/**
* Indicates if bracket pairs changed in the meantime.
*/
inaccurate: boolean;
}
interface BracketPair {
openRange: Range;
closeRange: Range;
} Would that be helpful? I don't know all the implications of this async API for your usecase. |
If that approach is significantly faster than the Bracket Pair Colorizer 2 approach (Which is also async, and it's implemented in Blockman), then I guess it's worth making. Just one note: Well, I guess most of real world code files does not have more than 3k brackets even if they have 10 thousand lines. One more note: Well, for this one, I guess there is simple solution. If we have an extreme edge case like a file with 20k brackets, then the bracket query should return nothing. It will not be a deal breaker, because most of developers don't work with such huge files. |
I don't think that is a good idea - you should try to not query the brackets for the entire file on every keystroke. That is slow by design and absolutely does not work for files such as
Hmm, do you really need all bracket pairs? Consider this:
Do you really need the brackets in "a lot of bracket pairs here" when providing the decorations for the current viewport? |
It's pretty cool approach for optimization. Well, yeah, if it is doable with not a huge pain, then |
Got a question about the statement:
It's from #128465 I see there are some feature updates about native bracket pair colorization. So, now, does the new version of VSCode guarantee correctness of bracket tokens? If no, then does Also, I would like to ask you, in what state is the feature idea of |
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? |
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 (debouncing) (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 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. |
Are there any related investments? |
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 #128465 (comment)
The text was updated successfully, but these errors were encountered: