GitXplorerGitXplorer
j

SnippetColorizer

public
7 stars
0 forks
1 issues

Commits

List of commits on branch master.
Verified
a8618684e485b30cacf65989bef1f77bc6ed221c

Merge pull request #3 from jcansdale/host-solution

jjcansdale committed 6 years ago
Unverified
f288ef0e2f73f95fc8a7531fbb9cf5adc3ba6b75

Base Workspace on host Solution

jjcansdale committed 6 years ago
Verified
539dabc85dbc7951afc49c7fd4e2fd6ea6dfa859

Update README.md

jjcansdale committed 6 years ago
Verified
f284a5f3d580fbfc719d70ca32a97bf709564efc

Create README.md

jjcansdale committed 6 years ago
Unverified
938397fa997c39589b56f9b5a64943e776c14703

Add project files.

jjcansdale committed 6 years ago
Unverified
37ffc3fd0f3f0af8c0f62104a6a38bb36baf5df2

Add .gitignore and .gitattributes.

jjcansdale committed 6 years ago

README

The README file for this repository.

What is this?

This is an experiment to find a clean way to turn a snippet of text into a WPF component.

See Twitter thread starting here: https://twitter.com/jcansdale/status/1059793737600110592

Unfortunately getting colorization to work isn't simply a case of creating a TextBuffer with a ContentType of CSharp and calling ITextEditorFactoryService.CreateTextView(textBuffer). We need to create a Microsoft.CodeAnalysis.Workspace and associate it with the TextBuffer.

This is the ceremony MiscellaneousFilesWorkspace performs on loose files that aren't associated with a project or Workspace. https://github.com/dotnet/roslyn/blob/2468ad7ccb5fa5982579279454341123b20846ed/src/VisualStudio/Core/Def/Implementation/ProjectSystem/MiscellaneousFilesWorkspace.cs#L338-L341

How to test

This project can be tested using TestDriven.Net's Test With > In-Proc (VS SDK) feature. This allows code to be executed inside the current Visual Studio process, MEF services to be prototyped and calls made to Visual Studio services. You can download this extension from the marketplace here.

image

The ColorizedTextFactoryAdHocTests class is marked with [Export] so it knows to register MEF services in the same assembly and the ShowTextViewHost method is marked with [STAThread] so that it knows to execute on the UI thread.

Any MEF service or Visual Studio service can be passed as a parameter to a "test" method (for Visual Studio services, the service type will be inferred form the interface type).

Here is what happens when I Test With > In-Proc (VS SDK) on the ColorizedTextFactoryAdHocTests.ShowTextViewHost method.

image

Questions

The ColorizedTextFactory.CreateProjectInfoForDocument uses reflection to call CreateProjectInfoForDocument on MiscellaneousFilesWorkspace. This is bad.

I didn't know enough about Roslyn to create a minimal ProjectInfo that is associated with a language, but ideally not a specific file on disk. Any help here would be appreciated.

Thanks everyone who helped on twitter and happy spelunking!