On Sat, 14 Jan 2023 at 05:54, Asif Aaron Amin via Devel <devel@lists.geany.org> wrote:
Lex/All, 

I presume you mean VS code using differing colours for each nesting level of braces.  I also happen to use VS, but you can't expect that contributors to one project will be aware of the features of others apps, you need to describe the feature you want.

You are correct and thanks for the heads up. 

Without seeing your code, can't tell, you point to the VScode plugin, but not yours ;-)

That was because my code at the time was too embarrassing to release publicly 😅 I currently have my code hosted here: https://github.com/asifamin13/bracket-colors . Admittedly it's very minimal and currently bare on documentation and builds with a simple cmake setup. I plan to add the autotools build and docs later this week

Over the U.S. holiday break I decided to take a crack at writing the plugin. I used your idea of using timers to handle massive files, I think it performs pretty well. I didn't even have to use "a recursive descent parser to build an abstract syntax tree" like what VSCode does. The scintilla SCI_BRACEMATCH  was enough and is also language agnostic. My plugin also handles coloring parentheses, braces, and angle brackets on dark and light backgrounds. I'd like to make the colors user configurable at some point

Well, Vscode likely _RE_uses a recursive descent parser in the language server ..... its used for lots of other stuff as well.

SCI_BRACEMATCH actually isn't language agnostic either, it uses the styling set by the lexer and only looks at braces that are in the same style.  See https://github.com/geany/geany/blob/607fcec1fa5aff005090fbda17280976dcee68c8/scintilla/src/Document.cxx#L2755.  So for example, assuming the lexer styles comments and strings so they are different to code, it can ignore braces in comments and strings.  The example the Vscode article uses "{ /* } */ char str[] = "}"; }" matches the outer pair correctly in C in Geany. 

Configurability via the theme would be good, then themes with weird colour sets can choose colours that stand out in their collection.  That will also remove the need for you to handle dark/light and 50 shades of grey.

 I didn't even have to use "a recursive descent parser to build an abstract syntax tree" like what VSCode does.selects matching braces correct in Geany.
A few questions
  • I use 3 indicators to render colored text. From the scintilla documentation, there are only 43 indicators available to use. Currently I use INDICATOR_IME - 3 as my start index, the rationale being I don't know what INDICATOR_IME is used for and it doesn't seem to affect anything. Is there a better way to choose my start indicator? 
Geany itself uses three at the low end of the range, so probably no better way, there is no recognised way of sharing resources like indicators between plugins, but IIRC others use indicators from low up, so starting at the top is probably ok.

IME is a set of ways (they are plugins IIUC) of entering characters not on your keyboard, think typing Chinese Japanese Korean on a US international keyboard, so yeah don't use those indicators.
 
  • The tricky part when writing this was determining when a bracket was inside a string, docstring, etc. The way I solved it was to check the style of the text and see if it matched up with known styles I got from trial and error: static const std::set<int> sIgnoreStyles { 1, 2, 3, 4, 6, 7, 9 } There must a better way to do this, does there exist a notion of "geany comment styles" I can leverage? 
As I said above, SCI_BRACEMATCH already does that, so you probably don't need to.

And keeping a list of styles up to date is unlikely, I notice that https://github.com/geany/geany/blob/607fcec1fa5aff005090fbda17280976dcee68c8/src/editor.c#L3431 doesn't mention Julia, but IIRC it has block comments (issue raised).  Having a list in a plugin updated is even less likely to happen.

Cheers
Lex

Thanks, 
Asif Amin 
...