static void CreateCSharpParsedDocument(RazorCSharpParserContext context) { if (context.Project == null) { return; } context.CSharpCode = CreateCodeFile(context); context.ParsedSyntaxTree = CSharpSyntaxTree.ParseText(Microsoft.CodeAnalysis.Text.SourceText.From(context.CSharpCode)); var originalProject = TypeSystemService.GetCodeAnalysisProject(context.Project); if (originalProject != null) { string fileName = context.FileName + ".g.cs"; var documentId = TypeSystemService.GetDocumentId(originalProject.Id, fileName); if (documentId == null) { context.AnalysisDocument = originalProject.AddDocument( fileName, context.ParsedSyntaxTree?.GetRoot()); } else { context.AnalysisDocument = TypeSystemService.GetCodeAnalysisDocument(documentId); } } }
internal static GuiBuilderWindow GetWindow(string file, Project project) { if (!IdeApp.Workspace.IsOpen) { return(null); } if (!GtkDesignInfo.HasDesignedObjects(project)) { return(null); } GtkDesignInfo info = GtkDesignInfo.FromProject(project); if (file.StartsWith(info.GtkGuiFolder)) { return(null); } var docId = TypeSystemService.GetDocumentId(project, file); if (docId == null) { return(null); } var doc = TypeSystemService.GetCodeAnalysisDocument(docId); if (doc == null) { return(null); } Microsoft.CodeAnalysis.SemanticModel semanticModel; try { semanticModel = doc.GetSemanticModelAsync().Result; } catch { return(null); } if (semanticModel == null) { return(null); } var root = semanticModel.SyntaxTree.GetRoot(); foreach (var classDeclaration in root.DescendantNodesAndSelf(child => !(child is BaseTypeDeclarationSyntax)).OfType <ClassDeclarationSyntax> ()) { var c = semanticModel.GetDeclaredSymbol(classDeclaration); GuiBuilderWindow win = info.GuiBuilderProject.GetWindowForClass(c.ToDisplayString(Microsoft.CodeAnalysis.SymbolDisplayFormat.CSharpErrorMessageFormat)); if (win != null) { return(win); } } return(null); }
Document GetDocument(CancellationToken token) { var doc = type.DocumentId; if (doc == null) { var docId = TypeSystemService.GetDocuments(type.FilePath).FirstOrDefault(); if (docId == null) { return(null); } return(TypeSystemService.GetCodeAnalysisDocument(docId, token)); } return(TypeSystemService.GetCodeAnalysisDocument(type.DocumentId, token)); }
void OnFileAdded(object sender, ProjectFileEventArgs e) { foreach (ProjectFileEventInfo args in e) { var docId = TypeSystemService.GetDocumentId(args.Project, args.ProjectFile.Name); if (docId == null) { continue; } var doc = TypeSystemService.GetCodeAnalysisDocument(docId); if (doc == null) { continue; } string dir = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "stetic"), "deleted-designs"); if (!Directory.Exists(dir) || Directory.GetFiles(dir).Length == 0) { continue; } var semanticModel = doc.GetSemanticModelAsync().Result; if (semanticModel == null) { continue; } foreach (var classDeclaration in semanticModel.SyntaxTree.GetRoot().DescendantNodesAndSelf(child => !(child is BaseTypeDeclarationSyntax)).OfType <ClassDeclarationSyntax> ()) { var c = semanticModel.GetDeclaredSymbol(classDeclaration); string path = Path.Combine(dir, c.ToDisplayString(Microsoft.CodeAnalysis.SymbolDisplayFormat.CSharpErrorMessageFormat) + ".xml"); if (!System.IO.File.Exists(path)) { continue; } XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(path); AddNewComponent(xmldoc.DocumentElement); System.IO.File.Delete(path); } } }
void OnFileRemoved(object sender, ProjectFileEventArgs e) { ArrayList toDelete = new ArrayList(); foreach (ProjectFileEventInfo args in e) { var docId = TypeSystemService.GetDocumentId(args.Project, args.ProjectFile.Name); if (docId == null) { continue; } var doc = TypeSystemService.GetCodeAnalysisDocument(docId); if (doc == null) { continue; } var semanticModel = doc.GetSemanticModelAsync().Result; if (semanticModel == null) { continue; } foreach (var classDeclaration in semanticModel.SyntaxTree.GetRoot().DescendantNodesAndSelf(child => !(child is BaseTypeDeclarationSyntax)).OfType <ClassDeclarationSyntax> ()) { var c = semanticModel.GetDeclaredSymbol(classDeclaration); GuiBuilderWindow win = GetWindowForClass(c.ToDisplayString(Microsoft.CodeAnalysis.SymbolDisplayFormat.MinimallyQualifiedFormat)); if (win != null) { toDelete.Add(win); } } } foreach (GuiBuilderWindow win in toDelete) { Remove(win); } }