Open HeinzKessler opened 1 year ago
recognize the code generation attributes of the .Net Community Toolkit and offer syntax highlighting accordingly.
I am afraid this will slow down the syntax highlighter a bit.
When highlighting a field, Codist will first recognize that it is a IFieldSymbol
, then if this request is supported, it will iterate through all custom attributes and compare them each other and check if it is of type communitytoolkit.mvvm.componentmodel.ObservablePropertyAttribute
, by comparing the custom attribute name first, then each namespace part one by one and try to find out the corresponding property and make sure it is public
.
The current implementation only deal with properties exposed by IFieldSymbol
and the new implementation will have to take care for custom attributes. All instances of fields will be checked like that, which is a draw back to performance.
However, on Super Quick Info and the symbol tool tip for those annotated fields, you can read the [ObservableProperty]
annotation. If you are not sure about a field, you can just hover your mouse on it and get the information.
Thanks for this comprehensive explanation. I suppose, 99% of the fields won't have any custom attributes at all, so the performance overhead will mostly come down to the attribute check only. But OK, at least this will remain and will affect performance. Is there an existing way to format such fields "manually", e.g. by using certain prefixes or postfixes in the name, i.e. is there a way to format fields by some kind of regex pattern? Or some other trick to format them manually?
is there a way to format fields by some kind of regex pattern? Or some other trick to format them manually?
Yes. Theoretically it is not difficult to implement at all. However, the logic will affect ALL symbols being highlighted. The current workflow to highlight C# symbols:
If "regex pattern enabled" highlight is to be implemented, for instance, you may want only private instance fields with a prefix "_m_
" to be tagged with "My Style 1", but someone else will prefer that any private static fields start with "__
" to be highlighted with "His Style 1", and someone else will prefer that any method named with a suffix "Async" to be highlighted with "Her Style 1", but private method suffixed with "Async" should be "Her Style 2"...
The code logic will become complicated. The current implementation in the step 4 does not have associated concept for compound sematic aspects such as "private static", "sealed override", etc. It once met with a member or type which is "private", it yields a "C#: Private member" tag, and when it later finds that member or type is "static", it yields another "C#: Static member" tag. So, if _private instance fields with a prefix "m" to be tagged with "My Style 1"_ is to be implemented, we have to rewrite the logic of the tagger to compare with compound aspects.
If the "Regex pattern enabled" highlight does not cooperate with the aforementioned sematic aspects, the code logic will be much simpler. However, each token will be examined by the regular expressions, which may be a little slow, I am afraid.
Is there an existing way to format such fields "manually", e.g. by using certain prefixes or postfixes in the name, i.e. is there a way to format fields by some kind of regex pattern?
The next version will allow you to do this by specifying regular expressions with matched tags.
Hi,
I've just uploaded a new beta version which allows you define regular expressions to highlight your code.
The detail of the mechanism can be read in the Wiki page here: https://github.com/wmjordan/Codist/wiki/ClassificationTypes.json-and-Codist.ct.json
The new feature is not yet complete. For instance, the custom rules only apply to files in the same directory of the configuration file. Please take some time to read the Wiki and give the new version a try. Your feedback is also welcome.
Hi,
I’m keen to see and test the new function. However, maybe I’m a little stupid, but I don’t see how I can download the beta version from GitHub.
Kind regards, Heinz
Von: WMJ @.> Gesendet: Mittwoch, 25. September 2024 14:38 An: wmjordan/Codist @.> Cc: Heinz Kessler @.>; Author @.> Betreff: Re: [wmjordan/Codist] Support Community Toolkit MVVM Attributes (Issue #266)
The new feature is not yet complete. For instance, the custom rules only apply to files in the same directory of the configuration file. Please take some time to read the Wiki and give the new version a try. Your feedback is also welcome.
— Reply to this email directly, view it on GitHub https://github.com/wmjordan/Codist/issues/266#issuecomment-2373969627 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AF2XTUTWUGADT7VJTJEPHX3ZYKVDTAVCNFSM6AAAAABOKTCY42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZTHE3DSNRSG4 . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AF2XTUSGBCIYYHONBUPJKV3ZYKVDTA5CNFSM6AAAAABOKTCY42WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUNP7TNW.gif Message ID: @. @.> >
The new beta can be downloaded here. It is an issue that pinned on top of the Issues section.
Hi,
thanks a lot. I will try it now.
How do you prefer to get feedback?
Regards, Heinz
Von: WMJ @.> Gesendet: Donnerstag, 26. September 2024 09:47 An: wmjordan/Codist @.> Cc: Heinz Kessler @.>; Author @.> Betreff: Re: [wmjordan/Codist] Support Community Toolkit MVVM Attributes (Issue #266)
The new beta can be downloaded here https://github.com/wmjordan/Codist/issues/334 . It is an issue that pinned on top of the Issues section.
— Reply to this email directly, view it on GitHub https://github.com/wmjordan/Codist/issues/266#issuecomment-2376178002 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AF2XTUWZR3UBKXPH3BGYD4DZYO3XRAVCNFSM6AAAAABOKTCY42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZWGE3TQMBQGI . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AF2XTUXM5JQNIO5PAM4MZFDZYO3XRA5CNFSM6AAAAABOKTCY42WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUNUGMVE.gif Message ID: @. @.> >
Just leave a line here on GitHub will do. Thank you for taking time to test the feature.
The documentation says, a ClassificationTypes.json
file should be created in Codist's configuration folder, but I didn't find an information where this folder is.
Aas a proposal, in the Codist configuration window, under "Customized", maybe you want to make the words "config folder" a link to just this folder.
You are right.
Maybe it is appropriate to offer a link to create a template file in the config folder, and a button to open that config file with Visual Studio.
Can you tell me where I can find that folder?
Click the Tools/Options menu command, find Codist. In the middle of the interface, click the "Open Config Folder" button.
Thanks.
The documentation says that "Advanced Syntax Highlighting" shall be enabled in order to benefit from the regular expressions in Codist.ct.json
but I found no place to enable Advanced Syntax Highlighting.
I feel a little stupid now... :-)
Sorry to have you confused.
Please take a look at the above screenshot, the Advanced Syntax Highlight is the first checkbox under the "Feature Controllers".
Oh, thanks! Then maybe you should call it what it is: "Advanced Syntax Highlight"
Thanks for your valuable feedback. I recently modified the WiKi page.
The .Net Community Toolkit is sure to become popular very quickly. Its MVVM toolkit allows for automatic generation of boilerplate code needed for properties, relay commands etc. in WPF.
A WPF "observable property" will look like this:
[ObservableProperty]
private bool _myPropertyValue;
The actual property will be auto generated in a second .cs file, and the class has to be a partial class. See here. Therefore the lines above act like a public property.
The only drawback is that there's only a private field left, decorated with the [ObservableProperty] attribute, which will not be formatted as a public property by Codist. Therefore it would be nice if codist could recognize the code generation attributes of the .Net Community Toolkit and offer syntax highlighting accordingly.