Exemplo n.º 1
0
        private DocumentId AddDocument(RoslynWorkspace workspace, DocumentCreationArgs args, Document previousDocument = null)
        {
            var project = CreateProject(workspace.CurrentSolution, args,
                                        CreateCompilationOptions(args, previousDocument == null), previousDocument?.Project);
            var document   = CreateDocument(project, args);
            var documentId = document.Id;

            workspace.SetCurrentSolution(document.Project.Solution);
            workspace.OpenDocument(documentId, args.SourceTextContainer);

            _workspaces.TryAdd(documentId, workspace);

            if (args.OnDiagnosticsUpdated != null)
            {
                _diagnosticsUpdatedNotifiers.TryAdd(documentId, args.OnDiagnosticsUpdated);
            }

            var onTextUpdated = args.OnTextUpdated;

            if (onTextUpdated != null)
            {
                workspace.ApplyingTextChange += (d, s) => {
                    if (documentId == d)
                    {
                        onTextUpdated(s);
                    }
                };
            }

            return(documentId);
        }
Exemplo n.º 2
0
        private static Document SetSubmissionDocument(RoslynWorkspace workspace, SourceTextContainer textContainer, Project project)
        {
            var id       = DocumentId.CreateNewId(project.Id);
            var solution = project.Solution.AddDocument(id, project.Name, textContainer.CurrentText);

            workspace.SetCurrentSolution(solution);
            workspace.OpenDocument(id, textContainer);
            return(solution.GetDocument(id));
        }