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 ();
		}
Ejemplo n.º 2
0
        /// <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();
        }
Ejemplo n.º 3
0
        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}");
            }
        }
Ejemplo n.º 4
0
        public static StringBuilder Display(string documentFullPath)
        {
            StringBuilder sb = new StringBuilder();

            Microsoft.CodeAnalysis.Document document = null;
            return(Display(document));
        }
Ejemplo n.º 5
0
        static StringBuilder Display(Microsoft.CodeAnalysis.Document document)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(MethodBase.GetCurrentMethod().DeclaringType + "." + MethodBase.GetCurrentMethod().Name + " Not Implemented Yet");

            return(sb);
        }
Ejemplo n.º 6
0
 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();
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        /// <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;
        }
Ejemplo n.º 10
0
        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");
                }
            }
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
0
        public static CGFDocument Parse(CGFParserReporter reporter, Microsoft.CodeAnalysis.Document document, List <CGFTypeSymbol> types)
        {
            CGFDocument cgfDocument = new CGFDocument(document, types);

            return(cgfDocument);
        }
Ejemplo n.º 15
0
 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;
 }