Skip to content
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

Walkthrough: Create Custom Language Editor issues. #50

Open
grokys opened this issue Jul 12, 2024 · 4 comments
Open

Walkthrough: Create Custom Language Editor issues. #50

grokys opened this issue Jul 12, 2024 · 4 comments

Comments

@grokys
Copy link

grokys commented Jul 12, 2024

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:

  • The walkthrough explains what to add to a package to achieve its aims, but does not explain why
  • Many of the steps are out of order, e.g. "Your completed LinqLanguageEditor2022Package.cs file should look like this now:" has the ProvideEditorLogicalView attribute at line 1429, but you're not told to add it until line 1530
  • It seems to spend more time on adding an options page and implementing the related tool windows than concentrating on creating the language editor
  • It mentions features such as "Intellisense Support" but then doesn't explain how to implement it.

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
Copy link
Author

grokys commented Jul 12, 2024

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
Copy link
Author

grokys commented Jul 12, 2024

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
Copy link
Author

grokys commented Jul 12, 2024

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
Copy link
Author

grokys commented Jul 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant