Exemplo n.º 1
0
 internal static void InformDocumentOpen(Microsoft.CodeAnalysis.Workspace ws, Microsoft.CodeAnalysis.DocumentId analysisDocument, TextEditor editor)
 {
     if (ws == null)
     {
         throw new ArgumentNullException(nameof(ws));
     }
     if (analysisDocument == null)
     {
         throw new ArgumentNullException(nameof(analysisDocument));
     }
     if (editor == null)
     {
         throw new ArgumentNullException(nameof(editor));
     }
     ((MonoDevelopWorkspace)ws).InformDocumentOpen(analysisDocument, editor);
 }
 public static Microsoft.CodeAnalysis.Document GetCodeAnalysisDocument(Microsoft.CodeAnalysis.DocumentId docId, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (docId == null)
     {
         throw new ArgumentNullException("docId");
     }
     foreach (var w in workspaces)
     {
         var documentId = w.GetDocument(docId, cancellationToken);
         if (documentId != null)
         {
             return(documentId);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 internal static void InformDocumentOpen(Microsoft.CodeAnalysis.DocumentId analysisDocument, TextEditor editor)
 {
     foreach (var w in workspaces)
     {
         if (w.Contains(analysisDocument.ProjectId))
         {
             w.InformDocumentOpen(analysisDocument, editor);
             return;
         }
     }
     if (!gotDocumentRequestError)
     {
         gotDocumentRequestError = true;
         LoggingService.LogWarning("Can't open requested document : " + analysisDocument + ":" + editor.FileName);
     }
 }
Exemplo n.º 4
0
        public static MonoDevelop.Projects.Project GetMonoProject(Microsoft.CodeAnalysis.DocumentId documentId)
        {
            foreach (var w in workspaces)
            {
                var doc = w.GetDocument(documentId);
                if (doc == null)
                {
                    continue;
                }

                var p = doc.Project;
                if (p != null)
                {
                    return(GetMonoProject(p));
                }
            }
            return(null);
        }
        Task EnsureAnalysisDocumentIsOpen()
        {
            if (analysisDocument != null)
            {
                Microsoft.CodeAnalysis.Document doc;
                try {
                    doc = RoslynWorkspace.CurrentSolution.GetDocument(analysisDocument);
                    if (doc == null && RoslynWorkspace.CurrentSolution.ContainsAdditionalDocument(analysisDocument))
                    {
                        return(Task.CompletedTask);
                    }
                } catch (Exception) {
                    doc = null;
                }
                if (doc != null)
                {
                    return(Task.CompletedTask);
                }
            }

            if (Editor == null)
            {
                UnsubscribeAnalysisDocument();
                UpdateTextBufferRegistration();
                return(Task.CompletedTask);
            }

            lock (analysisDocumentLock) {
                UnsubscribeRoslynWorkspace();
                RoslynWorkspace = typeSystemService.GetWorkspaceInternal(Project?.ParentSolution);
                SubscribeRoslynWorkspace();
                var newAnalysisDocument = FileName != null?typeSystemService.GetDocumentId(Project, FileName) : null;

                var changedAnalysisDocument = newAnalysisDocument != analysisDocument;
                analysisDocument = newAnalysisDocument;
                if (changedAnalysisDocument)
                {
                    OnAnalysisDocumentChanged(EventArgs.Empty);
                }
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 6
0
 public Document(IWorkbenchWindow window)
 {
     Counters.OpenDocuments++;
     LastTimeActive = DateTime.Now;
     this.window    = window;
     window.Closed += OnClosed;
     window.ActiveViewContentChanged += OnActiveViewContentChanged;
     if (IdeApp.Workspace != null)
     {
         IdeApp.Workspace.ItemRemovedFromSolution += OnEntryRemoved;
     }
     if (window.ViewContent.Project != null)
     {
         window.ViewContent.Project.Modified += HandleProjectModified;
     }
     window.ViewsChanged += HandleViewsChanged;
     window.ViewContent.ContentNameChanged += delegate {
         analysisDocument = null;
     };
     MonoDevelopWorkspace.LoadingFinished += TypeSystemService_WorkspaceItemLoaded;
 }
Exemplo n.º 7
0
        Task EnsureAnalysisDocumentIsOpen()
        {
            if (analysisDocument != null)
            {
                Microsoft.CodeAnalysis.Document doc;
                try {
                    doc = RoslynWorkspace.CurrentSolution.GetDocument(analysisDocument);
                    if (doc == null && RoslynWorkspace.CurrentSolution.ContainsAdditionalDocument(analysisDocument))
                    {
                        return(Task.CompletedTask);
                    }
                } catch (Exception) {
                    doc = null;
                }
                if (doc != null)
                {
                    return(Task.CompletedTask);
                }
            }
            if (Editor == null)
            {
                UnsubscribeAnalysisDocument();
                return(Task.CompletedTask);
            }
            if (Project != null && !IsUnreferencedSharedProject(Project))
            {
                lock (analysisDocumentLock) {
                    UnsubscribeRoslynWorkspace();
                    RoslynWorkspace = TypeSystemService.GetWorkspace(this.Project.ParentSolution);
                    if (RoslynWorkspace == null)                     // Solution not loaded yet
                    {
                        return(Task.CompletedTask);
                    }
                    SubscribeRoslynWorkspace();
                    analysisDocument = FileName != null?TypeSystemService.GetDocumentId(this.Project, this.FileName) : null;

                    if (analysisDocument != null && !RoslynWorkspace.CurrentSolution.ContainsAdditionalDocument(analysisDocument) && !RoslynWorkspace.IsDocumentOpen(analysisDocument))
                    {
                        TypeSystemService.InformDocumentOpen(analysisDocument, Editor, this);
                        OnAnalysisDocumentChanged(EventArgs.Empty);
                    }
                    return(Task.CompletedTask);
                }
            }
            lock (adhocProjectLock) {
                var token = analysisDocumentSrc.Token;
                if (adhocProject != null || IsInProjectSettingLoadingProcess)
                {
                    return(Task.CompletedTask);
                }

                if (Editor != null)
                {
                    var node = TypeSystemService.GetTypeSystemParserNode(Editor.MimeType, BuildAction.Compile);
                    if (Editor.MimeType == "text/x-csharp" || node?.Parser.CanGenerateAnalysisDocument(Editor.MimeType, BuildAction.Compile, new string[0]) == true)
                    {
                        var newProject = Services.ProjectService.CreateDotNetProject("C#");

                        this.adhocProject = newProject;

                        newProject.Name = "InvisibleProject";
                        newProject.References.Add(ProjectReference.CreateAssemblyReference("mscorlib"));
                        newProject.References.Add(ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
                        newProject.References.Add(ProjectReference.CreateAssemblyReference("System.Core"));

                        // Use a different name for each project, otherwise the msbuild builder will complain about duplicate projects.
                        newProject.FileName = "adhoc_" + (++adhocProjectCount) + ".csproj";
                        if (!Window.ViewContent.IsUntitled)
                        {
                            adHocFile = Editor.FileName;
                        }
                        else
                        {
                            adHocFile = (Platform.IsWindows ? "C:\\" : "/") + Window.ViewContent.UntitledName + ".cs";
                        }

                        newProject.Files.Add(new ProjectFile(adHocFile, BuildAction.Compile));

                        adhocSolution = new Solution();
                        adhocSolution.AddConfiguration("", true);
                        adhocSolution.DefaultSolutionFolder.AddItem(newProject);
                        return(TypeSystemService.Load(adhocSolution, new ProgressMonitor(), token, false).ContinueWith(task => {
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            UnsubscribeRoslynWorkspace();
                            RoslynWorkspace = task.Result.FirstOrDefault();                              // 1 solution loaded ->1 workspace as result
                            SubscribeRoslynWorkspace();
                            analysisDocument = RoslynWorkspace.CurrentSolution.Projects.First().DocumentIds.First();
                            TypeSystemService.InformDocumentOpen(RoslynWorkspace, analysisDocument, Editor, this);
                            OnAnalysisDocumentChanged(EventArgs.Empty);
                        }));
                    }
                }
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 8
0
 internal override void UpdateDocumentId(Microsoft.CodeAnalysis.DocumentId newId)
 {
     this.analysisDocument = newId;
     OnAnalysisDocumentChanged(EventArgs.Empty);
 }
Exemplo n.º 9
0
        Task EnsureAnalysisDocumentIsOpen()
        {
            if (analysisDocument != null)
            {
                Microsoft.CodeAnalysis.Document doc;
                try {
                    doc = RoslynWorkspace.CurrentSolution.GetDocument(analysisDocument);
                } catch (Exception) {
                    doc = null;
                }
                if (doc != null)
                {
                    return(SpecializedTasks.EmptyTask);
                }
            }
            if (Editor == null)
            {
                UnsubscibeAnalysisdocument();
                return(SpecializedTasks.EmptyTask);
            }
            if (Project != null && Editor.MimeType == "text/x-csharp" && !IsUnreferencedSharedProject(Project))
            {
                UnsubscribeRoslynWorkspace();
                RoslynWorkspace = TypeSystemService.GetWorkspace(this.Project.ParentSolution);
                SubscribeRoslynWorkspace();
                analysisDocument = TypeSystemService.GetDocumentId(this.Project, this.FileName);
                if (analysisDocument != null)
                {
                    TypeSystemService.InformDocumentOpen(analysisDocument, Editor);
                }
            }
            else
            {
                CancelEnsureAnalysisDocumentIsOpen();
                lock (adhocProjectLock) {
                    var token = analysisDocumentSrc.Token;
                    if (adhocProject != null)
                    {
                        return(SpecializedTasks.EmptyTask);
                    }
                    if (Editor != null && Editor.MimeType == "text/x-csharp")
                    {
                        var newProject = Services.ProjectService.CreateDotNetProject("C#");
                        this.adhocProject = newProject;

                        newProject.Name = "InvisibleProject";
                        newProject.References.Add(ProjectReference.CreateAssemblyReference("mscorlib"));
                        newProject.References.Add(ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
                        newProject.References.Add(ProjectReference.CreateAssemblyReference("System.Core"));

                        newProject.FileName = "test.csproj";
                        if (!Window.ViewContent.IsUntitled)
                        {
                            adHocFile = Editor.FileName;
                        }
                        else
                        {
                            adHocFile = (Platform.IsWindows ? "C:\\" : "/") + Window.ViewContent.UntitledName + ".cs";
                        }

                        newProject.Files.Add(new ProjectFile(adHocFile, BuildAction.Compile));

                        adhocSolution = new Solution();
                        adhocSolution.AddConfiguration("", true);
                        adhocSolution.DefaultSolutionFolder.AddItem(newProject);
                        return(TypeSystemService.Load(adhocSolution, new ProgressMonitor(), token).ContinueWith(task => {
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            UnsubscribeRoslynWorkspace();
                            RoslynWorkspace = task.Result.FirstOrDefault();                             // 1 solution loaded ->1 workspace as result
                            SubscribeRoslynWorkspace();
                            analysisDocument = TypeSystemService.GetDocumentId(RoslynWorkspace, newProject, adHocFile);
                            TypeSystemService.InformDocumentOpen(RoslynWorkspace, analysisDocument, Editor);
                        }));
                    }
                }
            }
            return(SpecializedTasks.EmptyTask);
        }
 internal static void InformDocumentOpen(Microsoft.CodeAnalysis.Workspace ws, Microsoft.CodeAnalysis.DocumentId analysisDocument, TextEditor editor)
 {
     ((MonoDevelopWorkspace)ws).InformDocumentOpen(analysisDocument, editor);
 }
Exemplo n.º 11
0
 internal virtual void UpdateDocumentId(Microsoft.CodeAnalysis.DocumentId newId)
 {
 }
Exemplo n.º 12
0
 void UnsubscribeAnalysisDocument()
 {
     analysisDocument = null;
 }