private static async Task <XAMLatorDocument> GetCodeDocumentAsync(VisualStudioWorkspace workspace, string path) { XAMLatorDocument result = null; if (workspace != null) { Solution solution = workspace.CurrentSolution; DocumentId documentId = solution.GetDocumentIdsWithFilePath(path).FirstOrDefault(); Document document = solution.GetDocument(documentId); if (document != null) { Task <SourceText> sourceTextTask = document.GetTextAsync(); result = new XAMLatorDocument { Path = path, Code = (await sourceTextTask)?.ToString() ?? string.Empty, SemanticModel = await document.GetSemanticModelAsync(), SyntaxTree = await document.GetSyntaxTreeAsync() }; } } return(result); }
private void OnDocumentChanged(object sender, XAMLatorDocument documentAnalysis) { if (documentAnalysis != null) { DocumentChangedEventArgs documentChangedEventArgs = new DocumentChangedEventArgs(documentAnalysis.Path, documentAnalysis.Code, documentAnalysis.SyntaxTree, documentAnalysis.SemanticModel); DocumentChanged?.Invoke(this, documentChangedEventArgs); } }
private async System.Threading.Tasks.Task OnFileSavedAsync(object sender, uint docCookie) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); (string document, IntPtr documentData) = GetDocumentInfo(docCookie); await TaskScheduler.Default; XAMLatorDocument analysis = await DocumentAnalysisHelper.GetDocumentAsync(_workspace, document, documentData); if (analysis != null) { OnDocumentChanged?.Invoke(this, analysis); } }