示例#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));
                }
        }
        private static async Task <FileMemberElement> GetContainingMemberAsync(OmniSharpTestHost host, string filePath, int line, int column)
        {
            var membersAsTreeService = host.GetRequestHandler <MembersAsTreeService>(OmniSharpEndpoints.MembersTree);

            var request = new MembersTreeRequest
            {
                FileName = filePath
            };

            var response = await membersAsTreeService.Handle(request);

            FileMemberElement containingMember = null;

            foreach (var node in response.TopLevelTypeDefinitions)
            {
                foreach (var child in node.ChildNodes)
                {
                    if (child.Location.Contains(line, column))
                    {
                        Assert.Null(containingMember);
                        containingMember = child;
                    }
                }
            }

            Assert.NotNull(containingMember);

            return(containingMember);
        }
        public async override Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken token)
        {
            var omnisharpRequest = new MembersTreeRequest()
            {
                FileName = Helpers.FromUri(request.TextDocument.Uri),
            };

            var omnisharpResponse = await _membersAsTreeHandler.Handle(omnisharpRequest);

            var codeLenseContainer = new List <CodeLens>();

            foreach (var node in omnisharpResponse.TopLevelTypeDefinitions)
            {
                ToCodeLens(request.TextDocument, node, codeLenseContainer);
            }

            return(codeLenseContainer);
        }
        public async Task <DocumentSymbolInformationContainer> Handle(DocumentSymbolParams request, CancellationToken token)
        {
            var omnisharpRequest = new MembersTreeRequest()
            {
                FileName = Helpers.FromUri(request.TextDocument.Uri),
            };

            var omnisharpResponse = await _membersAsTreeHandler.Handle(omnisharpRequest);

            var symbolInformationContainer = new List <DocumentSymbolInformation>();

            foreach (var node in omnisharpResponse.TopLevelTypeDefinitions)
            {
                ToDocumentSymbol(node, symbolInformationContainer);
            }

            return(symbolInformationContainer);
        }