protected override async Task GetTagsAsync(GetTagsState state, NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0) { return; } var snapshot = spans[0].Snapshot; if (!state.UserAsyncState.IsInitialized) { await Initialize(state.UserAsyncState, snapshot, state.CancellationToken).ConfigureAwait(false); } if (!state.UserAsyncState.IsValid) { return; } Debug.Assert(!(state.UserAsyncState.SyntaxRoot is null) && !(state.UserAsyncState.SemanticModel is null) && !(state.UserAsyncState.Workspace is null)); var classifier = new RoslynClassifier(state.UserAsyncState.SyntaxRoot, state.UserAsyncState.SemanticModel, state.UserAsyncState.Workspace, roslynClassificationTypes, defaultClassificationType, state.CancellationToken); state.UserAsyncState.TagsList.Clear(); foreach (var span in spans) { foreach (var info in classifier.GetColors(span.Span.ToTextSpan())) { state.UserAsyncState.TagsList.Add(new TagSpan <IClassificationTag>(new SnapshotSpan(snapshot, info.Span), new ClassificationTag((IClassificationType)info.Color))); } if (state.UserAsyncState.TagsList.Count != 0) { state.AddResult(new TagsResult(span, state.UserAsyncState.TagsList.ToArray())); state.UserAsyncState.TagsList.Clear(); } } }
public IEnumerable <ITagSpan <IClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans, CancellationToken cancellationToken) { if (spans.Count == 0) { yield break; } var snapshot = spans[0].Snapshot; var asyncState = new RoslynTaggerAsyncState(); Initialize(asyncState, snapshot, cancellationToken).Wait(cancellationToken); if (!asyncState.IsValid) { yield break; } Debug.Assert(!(asyncState.SyntaxRoot is null) && !(asyncState.SemanticModel is null) && !(asyncState.Workspace is null)); var classifier = new RoslynClassifier(asyncState.SyntaxRoot, asyncState.SemanticModel, asyncState.Workspace, roslynClassificationTypes, defaultClassificationType, cancellationToken); foreach (var span in spans) { foreach (var info in classifier.GetColors(span.Span.ToTextSpan())) { yield return(new TagSpan <IClassificationTag>(new SnapshotSpan(snapshot, info.Span), new ClassificationTag((IClassificationType)info.Color))); } } }
public Task OnCommandUpdatedAsync(IReplCommandInput command, CancellationToken cancellationToken) { if (isResetting) { return(Task.CompletedTask); } Debug.Assert(execState != null); if (execState == null) { throw new InvalidOperationException(); } string code = command.Input; const string assemblyName = "myasm"; var previousScriptCompilation = execState.ScriptState.Script.GetCompilation(); if (cancellationToken.IsCancellationRequested) { return(Task.CompletedTask); } var options = previousScriptCompilation.Options; if (cancellationToken.IsCancellationRequested) { return(Task.CompletedTask); } var syntaxTree = CreateSyntaxTree(code, cancellationToken); if (cancellationToken.IsCancellationRequested) { return(Task.CompletedTask); } var sc = CreateScriptCompilation(assemblyName, syntaxTree, null, options, previousScriptCompilation, execState.ScriptState.Script.ReturnType, execState.ScriptState.Script.GlobalsType); if (cancellationToken.IsCancellationRequested) { return(Task.CompletedTask); } var sem = sc.GetSemanticModel(syntaxTree); if (cancellationToken.IsCancellationRequested) { return(Task.CompletedTask); } using (var workspace = new AdhocWorkspace(RoslynMefHostServices.DefaultServices)) { var classifier = new RoslynClassifier(sem.SyntaxTree.GetRoot(), sem, workspace, roslynClassificationTypes, defaultClassificationType, cancellationToken); foreach (var info in classifier.GetClassifications(new TextSpan(0, command.Input.Length))) { command.AddClassification(info.Span.Start, info.Span.Length, info.Type); } } return(Task.CompletedTask); }