private async Task SetupCodeControlAsync() { var w = new AdhocWorkspace(Host); #if false foreach (var fieldInfo in w.GetType().GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.NonPublic)) { var v = fieldInfo.GetValue(w); Debug.WriteLine($"{fieldInfo.Name}: {v}"); } var langSvc = w.Services.GetLanguageServices(LanguageNames.CSharp); var method = langSvc.GetType().GetMethod("GetService", BindingFlags.Instance | BindingFlags.Public); List <object> services = new List <object>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { try { foreach (var type in assembly.GetTypes()) { if (typeof(ILanguageService).IsAssignableFrom(type)) { try { if (!type.ContainsGenericParameters) { var m = method.MakeGenericMethod(new[] { type }); var result = m.Invoke(langSvc, new object[] { }); if (result != null) { Debug.WriteLine(result); services.Add(result); } } } catch { } if (type.IsPublic) { Debug.WriteLine(String.Format("{0:G5}", type.IsPublic.ToString()) + " " + type.FullName); } } } } catch { } } foreach (object service in services) { foreach (var methodInfo in service.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { Debug.WriteLine((methodInfo.ReturnType?.FullName ?? "") + " " + service.GetType().FullName + "." + methodInfo.Name + "( " + string.Join(", ", methodInfo.GetParameters().Select(p => (p.IsOptional ? " optional " : "") + p.ParameterType + " " + p.Name)) + ")"); } if (service.GetType().Name == "CSharpCodeCleanupService") { } } // w.Services.FindLanguageServices<IFormattingService>(metadata => // { // foreach (var (key, value) in metadata) // { // Debug.WriteLine($"{key} = {value}"); // } // Debug.WriteLine(""); // return false; // }); #endif w.AddSolution(SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create())); var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "Code Project", "code", LanguageNames.CSharp); var w2 = w.CurrentSolution.AddProject(projectInfo); w.TryApplyChanges(w2); DocumentInfo documentInfo; var filename = Filename; if (filename != null) { documentInfo = DocumentInfo.Create(DocumentId.CreateNewId(projectInfo.Id), "Default", null, SourceCodeKind.Regular, new FileTextLoader(filename, Encoding.UTF8), filename); } else { documentInfo = DocumentInfo.Create(DocumentId.CreateNewId(projectInfo.Id), "Default", null, SourceCodeKind.Regular); } w2 = w.CurrentSolution.AddDocument(documentInfo); w.TryApplyChanges(w2); Project1 = w.CurrentSolution.GetProject(projectInfo.Id); Document1 = w.CurrentSolution.GetDocument(documentInfo.Id); var qui = w.Services.GetLanguageServices(LanguageNames.CSharp).GetService <QuickInfoService>(); var textAsync = await Document1.GetTextAsync(); if (false) { for (var i = 0; i < textAsync.Length; i++) { var re = await qui.GetQuickInfoAsync(Document1, i); if (re != null) { Debug.WriteLine(re.Span.ToString()); Debug.WriteLine("tags = " + string.Join(";", re.Tags)); foreach (var reRelatedSpan in re.RelatedSpans) { Debug.WriteLine("relatedspan " + reRelatedSpan.ToString()); } foreach (var quickInfoSection in re.Sections) { Debug.WriteLine("" + i + " Text(" + quickInfoSection.Text + ") Kind(" + quickInfoSection.Kind + ") TaggedParts(" + String.Join(", ", quickInfoSection.TaggedParts) + ")"); } } } } CodeControl.DebugLevel = 2; CodeControl.JTF2 = JTF2; CodeControl.Document = Document1; var tree = await Document1.GetSyntaxTreeAsync(); CodeControl.SyntaxTree = tree; var model = await Document1.GetSemanticModelAsync(); CodeControl.SemanticModel = model; CodeControl.Compilation = model.Compilation; // CodeControl.AddHandler(RoslynCodeControl.ContentChangedEvent, new RoslynCodeControl.ContentChangedRoutedEventHandler(CodeControlContentChanged)); CodeControl.AddHandler(RoslynCodeBase.RenderStartEvent, new RoutedEventHandler((sender, args) => { // StartTime = DateTime.Now; Debug.WriteLine("render start"); })); CodeControl.AddHandler(RoslynCodeBase.RenderCompleteEvent, new RoutedEventHandler((sender, args) => { // var span = DateTime.Now - StartTime; Debug.WriteLine("render complete "); })); await CodeControl.UpdateFormattedTextAsync(); }