示例#1
0
        private static OmnisharpWorkspace GetWorkspaceWithProjects()
        {
            var workspace = new OmnisharpWorkspace();

            TestHelpers.AddProjectToWorkspace(workspace, Path.Combine("src", "project.json"),
                                              new[] { "dnx451", "dnxcore50" },
                                              new Dictionary <string, string>()
            {
                { Path.Combine("src", "a.cs"), "class C {}" }
            });

            TestHelpers.AddProjectToWorkspace(workspace, Path.Combine("test", "project.json"),
                                              new[] { "dnx451", "dnxcore50" },
                                              new Dictionary <string, string>()
            {
                { Path.Combine("test", "b.cs"), "class C {}" }
            });

            Assert.Equal(4, workspace.CurrentSolution.Projects.Count());
            foreach (var project in workspace.CurrentSolution.Projects)
            {
                Assert.Equal(1, project.Documents.Count());
            }

            return(workspace);
        }
        private static OmniSharpWorkspace GetWorkspaceWithProjects()
        {
            var workspace = new OmniSharpWorkspace(
                new HostServicesAggregator(
                    Enumerable.Empty <IHostServicesProvider>(), new LoggerFactory()),
                new LoggerFactory());

            TestHelpers.AddProjectToWorkspace(workspace,
                                              filePath: Path.Combine("src", "project.json"),
                                              frameworks: new[] { "dnx451", "dnxcore50" },
                                              testFiles: new [] { new TestFile(Path.Combine("src", "a.cs"), "class C {}") });

            TestHelpers.AddProjectToWorkspace(workspace,
                                              filePath: Path.Combine("test", "project.json"),
                                              frameworks: new[] { "dnx451", "dnxcore50" },
                                              testFiles: new [] { new TestFile(Path.Combine("test", "b.cs"), "class C {}") });

            Assert.Equal(4, workspace.CurrentSolution.Projects.Count());
            foreach (var project in workspace.CurrentSolution.Projects)
            {
                Assert.Single(project.Documents);
            }

            return(workspace);
        }
        public async Task UpdateBufferFindsProjectBasedOnNearestPath()
        {
            var workspace = new OmnisharpWorkspace(
                new HostServicesAggregator(
                    Enumerable.Empty <IHostServicesProvider>()));

            await TestHelpers.AddProjectToWorkspace(workspace, Path.Combine("src", "root", "foo.csproj"),
                                                    new[] { "" },
                                                    new Dictionary <string, string>() { { Path.Combine("src", "root", "foo.cs"), "class C1 {}" } });

            await TestHelpers.AddProjectToWorkspace(workspace, Path.Combine("src", "root", "foo", "bar", "insane.csproj"),
                                                    new[] { "" },
                                                    new Dictionary <string, string>() { { Path.Combine("src", "root", "foo", "bar", "nested", "code.cs"), "class C2 {}" } });

            await workspace.BufferManager.UpdateBuffer(new Request()
            {
                FileName = Path.Combine("src", "root", "bar.cs"), Buffer = "enum E {}"
            });

            var documents = workspace.GetDocuments(Path.Combine("src", "root", "bar.cs"));

            Assert.Equal(1, documents.Count());
            Assert.Equal(Path.Combine("src", "root", "foo.csproj"), documents.ElementAt(0).Project.FilePath);
            Assert.Equal(2, documents.ElementAt(0).Project.Documents.Count());

            await workspace.BufferManager.UpdateBuffer(new Request()
            {
                FileName = Path.Combine("src", "root", "foo", "bar", "nested", "paths", "dance.cs"), Buffer = "enum E {}"
            });

            documents = workspace.GetDocuments(Path.Combine("src", "root", "foo", "bar", "nested", "paths", "dance.cs"));
            Assert.Equal(1, documents.Count());
            Assert.Equal(Path.Combine("src", "root", "foo", "bar", "insane.csproj"), documents.ElementAt(0).Project.FilePath);
            Assert.Equal(2, documents.ElementAt(0).Project.Documents.Count());
        }
示例#4
0
        private async static Task <OmnisharpWorkspace> GetWorkspaceWithProjects()
        {
            var workspace = new OmnisharpWorkspace(new HostServicesBuilder(Enumerable.Empty <ICodeActionProvider>()));

            await TestHelpers.AddProjectToWorkspace(workspace, Path.Combine("src", "project.json"),
                                                    new[] { "dnx451", "dnxcore50" },
                                                    new Dictionary <string, string>() { { Path.Combine("src", "a.cs"), "class C {}" } });

            await TestHelpers.AddProjectToWorkspace(workspace, Path.Combine("test", "project.json"),
                                                    new[] { "dnx451", "dnxcore50" },
                                                    new Dictionary <string, string>() { { Path.Combine("test", "b.cs"), "class C {}" } });

            Assert.Equal(4, workspace.CurrentSolution.Projects.Count());
            foreach (var project in workspace.CurrentSolution.Projects)
            {
                Assert.Equal(1, project.Documents.Count());
            }

            return(workspace);
        }
        public async Task UpdateBufferFindsProjectBasedOnNearestPath()
        {
            var workspace = new OmniSharpWorkspace(
                new HostServicesAggregator(
                    Enumerable.Empty <IHostServicesProvider>(), new LoggerFactory()),
                new LoggerFactory());

            TestHelpers.AddProjectToWorkspace(workspace,
                                              filePath: Path.Combine("src", "root", "foo.csproj"),
                                              frameworks: null,
                                              testFiles: new[] { new TestFile(Path.Combine("src", "root", "foo.cs"), "class C1 {}") });

            TestHelpers.AddProjectToWorkspace(workspace,
                                              filePath: Path.Combine("src", "root", "foo", "bar", "insane.csproj"),
                                              frameworks: null,
                                              testFiles: new [] { new TestFile(Path.Combine("src", "root", "foo", "bar", "nested", "code.cs"), "class C2 {}") });

            await workspace.BufferManager.UpdateBufferAsync(new Request()
            {
                FileName = Path.Combine("src", "root", "bar.cs"), Buffer = "enum E {}"
            });

            var documents = workspace.GetDocuments(Path.Combine("src", "root", "bar.cs"));

            Assert.Single(documents);
            Assert.Equal(Path.Combine("src", "root", "foo.csproj"), documents.ElementAt(0).Project.FilePath);
            Assert.Equal(2, documents.ElementAt(0).Project.Documents.Count());

            await workspace.BufferManager.UpdateBufferAsync(new Request()
            {
                FileName = Path.Combine("src", "root", "foo", "bar", "nested", "paths", "dance.cs"), Buffer = "enum E {}"
            });

            documents = workspace.GetDocuments(Path.Combine("src", "root", "foo", "bar", "nested", "paths", "dance.cs"));
            Assert.Single(documents);
            Assert.Equal(Path.Combine("src", "root", "foo", "bar", "insane.csproj"), documents.ElementAt(0).Project.FilePath);
            Assert.Equal(2, documents.ElementAt(0).Project.Documents.Count());
        }