Esempio n. 1
0
        public async Task LoadOnDemandProjectAndItsReference()
        {
            var configData = new Dictionary <string, string> {
                [$"MsBuild:{nameof(MSBuildOptions.LoadProjectsOnDemand)}"] = "true"
            }.ToConfiguration();

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("TwoProjectsWithSolution"))
                using (var host = CreateMSBuildTestHost(testProject.Directory, configurationData: configData))
                {
                    MSBuildWorkspaceInfo workspaceInfo = await host.RequestMSBuildWorkspaceInfoAsync();

                    // Expect empty workspace initially since no documents have been requested yet
                    Assert.Null(workspaceInfo.SolutionPath);
                    Assert.NotNull(workspaceInfo.Projects);
                    Assert.Equal(0, workspaceInfo.Projects.Count);

                    // Requesting app document should load both projects
                    MembersAsTreeService membersAsTreeService = host.GetRequestHandler <MembersAsTreeService>(OmniSharpEndpoints.MembersTree);
                    var request = new MembersTreeRequest {
                        FileName = Path.Combine(testProject.Directory, "App", "Program.cs")
                    };
                    FileMemberTree response = await membersAsTreeService.Handle(request);

                    workspaceInfo = await host.RequestMSBuildWorkspaceInfoAsync();

                    Assert.NotNull(request);
                    Assert.Null(workspaceInfo.SolutionPath);
                    Assert.NotNull(workspaceInfo.Projects);
                    Assert.Equal(2, workspaceInfo.Projects.Count);
                    Assert.Equal("App.csproj", Path.GetFileName(workspaceInfo.Projects[0].Path));
                    Assert.Equal("Lib.csproj", Path.GetFileName(workspaceInfo.Projects[1].Path));
                }
        }
        public static async Task <FileMemberTree> TranslateAsync(this FileMemberTree response, OmniSharpWorkspace workspace, Request request)
        {
            var zeroIndex = await LineIndexHelper.TranslateToGenerated(request.FileName, 0, workspace);

            var topLevelTypeDefinitions = new List <FileMemberElement>();

            foreach (var topLevelTypeDefinition in response.TopLevelTypeDefinitions)
            {
                if (topLevelTypeDefinition.Location.Line < zeroIndex)
                {
                    continue;
                }

                await topLevelTypeDefinition.TranslateAsync(workspace, request);

                if (topLevelTypeDefinition.Location.Line >= 0)
                {
                    topLevelTypeDefinitions.Add(topLevelTypeDefinition);
                }
            }

            response.TopLevelTypeDefinitions = topLevelTypeDefinitions;
            return(response);
        }