A Roslyn Workspace that contains documents linked to ITextBuffers.
Inheritance: Microsoft.CodeAnalysis.Workspace
Example #1
0
		void CreateWorkspace(ITextBuffer buffer) {
			if (buffer.GetWorkspace() != null || !buffer.ContentType.IsOfType("Roslyn Languages"))
				return;
			var componentModel = (IComponentModel)ExportProvider.GetService(typeof(SComponentModel));
			var workspace = new EditorWorkspace(MefV1HostServices.Create(componentModel.DefaultExportProvider));

			var project = workspace.CurrentSolution
				.AddProject("Sample Project", "SampleProject", contentTypeLanguages[buffer.ContentType.DisplayName])
				.AddMetadataReferences(new[] { "mscorlib", "System", "System.Core", "System.Xml.Linq" }
					.Select(EditorWorkspace.CreateFrameworkReference)
				);
			project = project.WithParseOptions(project.ParseOptions.WithKind(SourceCodeKind.Script));
			workspace.TryApplyChanges(project.Solution);
			workspace.CreateDocument(project.Id, buffer);
		}
Example #2
0
        void CreateWorkspace(ITextBuffer buffer)
        {
            if (buffer.GetWorkspace() != null || !buffer.ContentType.IsOfType("Roslyn Languages"))
            {
                return;
            }
            var componentModel = (IComponentModel)ExportProvider.GetService(typeof(SComponentModel));
            var workspace      = new EditorWorkspace(MefV1HostServices.Create(componentModel.DefaultExportProvider));

            var project = workspace.CurrentSolution
                          .AddProject("Sample Project", "SampleProject", contentTypeLanguages[buffer.ContentType.DisplayName])
                          .AddMetadataReferences(new[] { "mscorlib", "System", "System.Core", "System.Xml.Linq" }
                                                 .Select(EditorWorkspace.CreateFrameworkReference)
                                                 );

            project = project.WithParseOptions(project.ParseOptions.WithKind(SourceCodeKind.Script));
            workspace.TryApplyChanges(project.Solution);
            workspace.CreateDocument(project.Id, buffer);
        }