public ProjectedDocumentContext (TextEditor projectedEditor, DocumentContext originalContext) { if (projectedEditor == null) throw new ArgumentNullException ("projectedEditor"); if (originalContext == null) throw new ArgumentNullException ("originalContext"); this.projectedEditor = projectedEditor; this.originalContext = originalContext; if (originalContext.Project != null) { var originalProjectId = TypeSystemService.GetProjectId (originalContext.Project); if (originalProjectId != null) { var originalProject = TypeSystemService.Workspace.CurrentSolution.GetProject (originalProjectId); if (originalProject != null) { projectedDocument = originalProject.AddDocument ( projectedEditor.FileName, projectedEditor ); } } } projectedEditor.TextChanged += delegate(object sender, TextChangeEventArgs e) { if (projectedDocument != null) projectedDocument = projectedDocument.WithText (projectedEditor); ReparseDocument (); }; ReparseDocument (); }
/// <summary> /// Initializes a new instance of the <see cref="KDocumentBase"/> class. /// </summary> public CSDocument(Microsoft.CodeAnalysis.Document document) { this.IsGraphActive = true; this.Document = document; this.Name = document.Name; this.FilePath = document.FilePath; this.AvalonDocument = new ICSharpCode.AvalonEdit.Document.TextDocument() { FileName = this.Name, Text = File.ReadAllText(document.FilePath) }; this.AvalonDocument.TextChanged += AvalonDocument_TextChanged; if (File.Exists(this.GraphFilePath)) { _graph = GraphSerializer.Deserialize <CSGraph>(File.ReadAllText(this.GraphFilePath)); } else { _graph = new CSGraph(); } this.Graph.Name = Path.GetFileNameWithoutExtension(document.Name); this.Graph.FilePath = this.GraphFilePath; this.Graph.Document = document; _graph.GraphChanged += _graph_GraphChanged; _graph.NodeChanged += _graph_NodeChanged; _graph.NodeSelectionChanged += _graph_NodeSelectionChanged; _graph.CodeChanged += _graph_CodeChanged; OnNodeSelectionChanged(); }
public async System.Threading.Tasks.Task HandleChangeAsync(IWpfTextView textView) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); try { var profiler = MiniProfiler.StartNew(nameof(HandleChangeAsync)); profiler.Storage = new NLogStorage(LogManager.GetLogger("profiler")); using (profiler.Step("HandleChangeCode")) { SnapshotPoint caretPosition = textView.Caret.Position.BufferPosition; Microsoft.CodeAnalysis.Document roslynDocument = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); if (roslynDocument == null) { OutputWindowLogger.WriteLn($"Unable to get c# file to process. Name {caretPosition.Snapshot.ContentType.DisplayName}"); return; } await GotoAsyncPackage.Storage.AnalyzeAndUpdateSingleAsync(roslynDocument); } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "CSharpFileContentOnChange.HandleChange"); OutputWindowLogger.WriteLn($"Exception occured during handling csharp file change: {ex.Message}"); } }
public static StringBuilder Display(string documentFullPath) { StringBuilder sb = new StringBuilder(); Microsoft.CodeAnalysis.Document document = null; return(Display(document)); }
static StringBuilder Display(Microsoft.CodeAnalysis.Document document) { StringBuilder sb = new StringBuilder(); sb.AppendLine(MethodBase.GetCurrentMethod().DeclaringType + "." + MethodBase.GetCurrentMethod().Name + " Not Implemented Yet"); return(sb); }
private bool CanProcessDocument(Document doc) { if (doc.Project != ProjectData.Project) { return(false); } return(_analyzeDocuments.Contains(doc)); }
public AbstractFileCodeElementTests(string file) { var pair = FileCodeModelTestHelpers.CreateWorkspaceAndFileCodeModel(file); Workspace = pair.Item1; CodeModel = pair.Item2; CurrentSolution = Workspace.CurrentSolution; CurrentProject = CurrentSolution.Projects.Single(); CurrentDocument = CurrentProject.Documents.Single(); }
/// <summary> /// Initializes a new instance of the <see cref="KDocumentBase"/> class. /// </summary> public XamlDocument(Microsoft.CodeAnalysis.Document document) { this.ContentId = Constants.WPF_DESIGNER; this.IsDesignerActive = true; this.Document = document; this.Name = document.Name; this.FilePath = document.FilePath; this.AvalonDocument = new ICSharpCode.AvalonEdit.Document.TextDocument() { FileName = this.Name, Text = File.ReadAllText(FilePath) }; this.AvalonDocument.TextChanged += AvalonDocument_TextChanged; }
public static void Rename(ILogger _logger, string solutionPath, string projectPath, List <PreRenameData> lstRenames, CancellationToken cancellationToken) { using (Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace workspace = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create()) { // Open the solution within the workspace. Microsoft.CodeAnalysis.Solution solution = workspace.OpenSolutionAsync(solutionPath).Result; bool isProjectFound = false; foreach (Microsoft.CodeAnalysis.ProjectId projectId in solution.ProjectIds) { // Look up the snapshot for the original project in the latest forked solution. Microsoft.CodeAnalysis.Project project = solution.GetProject(projectId); if (project.FilePath == projectPath) { isProjectFound = true; foreach (Microsoft.CodeAnalysis.DocumentId documentId in project.DocumentIds) { // Look up the snapshot for the original document in the latest forked solution. Microsoft.CodeAnalysis.Document document = solution.GetDocument(documentId); //tg.RelativePathToGeneratedFile // only in 'main' declaration files //TODO implement based on knowledge of generated file ??? if (Path.GetDirectoryName(document.FilePath).EndsWith("ViewModels")) { if (Path.GetExtension(document.FilePath) == "cs") { CodeAnalysisCSharp.Rename(_logger, solution, document, lstRenames, cancellationToken).Wait(); } else if (Path.GetExtension(document.FilePath) == "vb") { CodeAnalysisVisualBasic.Rename(solution, document, lstRenames, cancellationToken).Wait(); } else { throw new NotSupportedException(); } } } } } if (!isProjectFound) { throw new Exception("Project not found"); } } }
private async Task <InvocationContext> GetInvocation(Microsoft.CodeAnalysis.Document document, int offset) { var sourceText = await document.GetTextAsync(); var position = offset; var tree = await document.GetSyntaxTreeAsync(); var root = await tree.GetRootAsync(); var node = root.FindToken(position).Parent; // Walk up until we find a node that we're interested in. while (node != null) { if (node is InvocationExpressionSyntax invocation && invocation.ArgumentList.Span.Contains(position)) { var semanticModel = await document.GetSemanticModelAsync(); return(new InvocationContext(semanticModel, position, invocation.Expression, invocation.ArgumentList, invocation.IsInStaticContext())); } if (node is ObjectCreationExpressionSyntax objectCreation && objectCreation.ArgumentList.Span.Contains(position)) { var semanticModel = await document.GetSemanticModelAsync(); return(new InvocationContext(semanticModel, position, objectCreation, objectCreation.ArgumentList, objectCreation.IsInStaticContext())); } if (node is AttributeSyntax attributeSyntax && attributeSyntax.ArgumentList.Span.Contains(position)) { var semanticModel = await document.GetSemanticModelAsync(); return(new InvocationContext(semanticModel, position, attributeSyntax, attributeSyntax.ArgumentList, attributeSyntax.IsInStaticContext())); } node = node.Parent; } return(null); }
public ProjectedDocumentContext(TextEditor projectedEditor, DocumentContext originalContext) { if (projectedEditor == null) { throw new ArgumentNullException("projectedEditor"); } if (originalContext == null) { throw new ArgumentNullException("originalContext"); } this.projectedEditor = projectedEditor; this.originalContext = originalContext; if (originalContext.Project != null) { var originalProjectId = IdeApp.TypeSystemService.GetProjectId(originalContext.Project); if (originalProjectId != null) { var originalProject = IdeApp.TypeSystemService.Workspace.CurrentSolution.GetProject(originalProjectId); if (originalProject != null) { projectedDocument = originalProject.AddDocument( projectedEditor.FileName, projectedEditor ); } } } projectedEditor.TextChanged += delegate(object sender, TextChangeEventArgs e) { if (projectedDocument != null) { projectedDocument = projectedDocument.WithText(projectedEditor); } ReparseDocument(); }; ReparseDocument(); }
public RefactorDialog() { InitializeComponent(); ThreadHelper.ThrowIfNotOnUIThread(); var solution = ((IComponentModel)Package.GetGlobalService(typeof(SComponentModel))) .GetService <VisualStudioWorkspace>().CurrentSolution; var activeDocument = ((DTE)Package.GetGlobalService(typeof(DTE))).ActiveDocument; var documentId = solution.GetDocumentIdsWithFilePath(activeDocument.FullName).FirstOrDefault(); if (documentId == null) { throw new Exception(Resources.UnexpectedErrorMessage); } _activeDocument = solution.GetDocument(documentId); var syntaxRootTask = _activeDocument.GetSyntaxRootAsync(); var classesInCurrentFile = syntaxRootTask.Result.GetClassesFromNode(); ComboBox.DataSource = classesInCurrentFile; ComboBox.DisplayMember = "Identifier"; ComboBox.AutoCompleteSource = AutoCompleteSource.ListItems; }
public static CGFDocument Parse(CGFParserReporter reporter, Microsoft.CodeAnalysis.Document document, List <CGFTypeSymbol> types) { CGFDocument cgfDocument = new CGFDocument(document, types); return(cgfDocument); }
CGFDocument(Microsoft.CodeAnalysis.Document document, List <CGFTypeSymbol> types) { m_Document = document; Types = types; }
public CodeInfo RemoveActiveNodeFromActiveDocument(Microsoft.CodeAnalysis.Document activeDocument, Microsoft.CodeAnalysis.SyntaxNode activeSyntaxNode, string serverMethodFolderPath) { throw new NotImplementedException(); }
public DocumentChangedEventArgs(Microsoft.CodeAnalysis.Document document) { this.Document = document; }