3

As R# is not supporting the Roslyn Early Preview C# 6.0 features, the code looks very dull...

I would like to colorize the code using a classifier VSIX. Is it possible to get the semantic model from the Roslyn Language Service for the current document?

1 Answer 1

8

You need to add a reference to Microsoft.CodeAnalysis.EditorFeatures.Text.dll, then use the following code.

var doc = point.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
var model = await doc.GetSemanticModelAsync();

This requires the Microsoft.CodeAnalysis.EditorFeatures.Text NuGet package (.NET 4.6 required)

Sign up to request clarification or add additional context in comments.

6 Comments

Unfortunately, point.Snapshot.GetOpenDocumentInCurrentContextWithChanges() returns always null
@Liviu: What kind of document is it? What's the ContentType of the TextBuffer? Is the Roslyn preview installed in the VS hive you're running in? (with matching version)
I've eventually figured out that debug session was running in Exp hive.
GetOpenDocumentInCurrentContextWithChanges is giving me some weird accessibility issues.
@MickeyPerlstein install the Microsoft.CodeAnalysis.EditorFeatures.Text package, which changes the accessibility of this method by adding an extension method with that name
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.