VsixCommunity / docs

MIT License
9 stars 7 forks source link

Walkthrough: Create Custom Language Editor issues. #50

Open grokys opened 2 months ago

grokys commented 2 months ago

This walkthrough has a number of issues, the most important being that the linked repostiory https://github.com/SFC-Sarge/LinqLanguageEditor2022 is now dead.

In addition to this, there are several problems:

I'd suggest that a guide the concentrates on adding support for a simple theoretical language, and explains why each step needs to be done would be more useful.

grokys commented 2 months ago

If anyone comes across this, I'm trying to work out how to create a "hello world" language server over at https://github.com/grokys/HelloWorldExtension and documenting my findings along the way.

grokys commented 2 months ago

Actually, this same seems to implement what I personally would think of as a custom language editor:

https://github.com/microsoft/VSSDK-Extensibility-Samples/tree/master/Ook_Language_Integration

So I'm a little confused as to where LanguageBase comes into this, as that doesn't seem to be present in this sample.

It would have been nice to watch the linked video but it seems like with many things VSSDK-related, it no longer exists.

grokys commented 2 months ago

But then I watch this video:

https://www.youtube.com/watch?v=VNhmk1oR3R4

And this uses IClassifierProvider to provide syntax highlighting whereas the above Ook language example uses ITaggerProvider. So I ask copilot chat what I should be doing which suggests that I use IVsColorizer and IVsTextScanner...

Now I'm really confused as to what I should be doing.

grokys commented 2 months ago

Ok, thank you GitHub copilot. This is the explanation (hopefully it's correct). It still doesn't explain why I might need LanguageBase but it's helpful.


Choosing between IVsColorizer, ITaggerProvider, and IClassifierProvider for implementing syntax highlighting in a Visual Studio extension depends on your specific requirements and the context of your extension. Here's a brief overview of each approach to help you decide:

IVsColorizer

• Use Case: This is an older approach primarily used in earlier versions of Visual Studio or for integrating with legacy systems. It directly interfaces with Visual Studio's text editor to provide syntax coloring. • Considerations: While it offers a high degree of control, it's generally more complex and less flexible than the newer MEF-based approaches. It might not be the best choice for new extensions targeting recent versions of Visual Studio.

ITaggerProvider

• Use Case: ITaggerProvider is part of the modern MEF (Managed Extensibility Framework) based extensibility model for Visual Studio. It's used to create taggers that can provide various kinds of tags, including those for syntax highlighting, outlining, and more. • Considerations: This approach is more modular and integrates well with the rest of the Visual Studio editor's extensibility points. It's a good choice if you're also implementing other tagging-related features like outlining or tooltips.

IClassifierProvider

• Use Case: IClassifierProvider is specifically designed for syntax highlighting and classification. It's also part of the MEF-based extensibility model and allows you to classify text into different categories, which can then be styled accordingly. • Considerations: This is the most straightforward and recommended approach for implementing syntax highlighting in modern Visual Studio extensions. It leverages the editor's built-in mechanisms for classification and styling, making it easier to implement and maintain.

Recommendation

For most scenarios involving syntax highlighting in modern Visual Studio extensions, IClassifierProvider is the recommended approach. It provides a clear and straightforward way to implement syntax highlighting, with support for the rich extensibility model provided by MEF. It allows your extension to cleanly integrate with Visual Studio's editor, benefiting from its styling and theming capabilities.

ITaggerProvider is a more general mechanism that can be used for a wider range of tagging scenarios beyond just syntax highlighting. If your extension needs to provide additional tagging features (like outlining or tooltips), you might use ITaggerProvider alongside IClassifierProvider. IVsColorizer is generally recommended only for specific legacy scenarios or when integrating with older systems that require direct use of this interface.

In summary, for new extensions focused on syntax highlighting, start with IClassifierProvider. Consider ITaggerProvider if you're implementing a broader range of text tagging features, and use IVsColorizer only if you have specific legacy requirements.


Apologies for the noise, but hopefully someone coming along later may find it useful.