Пример #1
0
        public async Task TestUnknownProject()
        {
            var workspace = new AdhocWorkspace(TestHostServices.CreateHostServices());
            var solution  = workspace.CurrentSolution.AddProject("unknown", "unknown", NoCompilationConstants.LanguageName).Solution;

            var client = (InProcRemoteHostClient)(await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false));

            await UpdatePrimaryWorkspace(client, solution);
            await VerifyAssetStorageAsync(client, solution);

            Assert.Equal(
                await solution.State.GetChecksumAsync(CancellationToken.None),
                await RemoteWorkspace.CurrentSolution.State.GetChecksumAsync(CancellationToken.None));
        }
Пример #2
0
        public async Task <RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken)
        {
            // this is the point where we can create different kind of remote host client in future (cloud or etc)
            if (workspace.Options.GetOption(RemoteHostClientFactoryOptions.RemoteHost_InProc))
            {
                var client = await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup : true, cancellationToken : cancellationToken).ConfigureAwait(false);

                // register workspace host for in proc remote host client
                await ServiceHubRemoteHostClient.RegisterWorkspaceHostAsync(workspace, client).ConfigureAwait(false);

                return(client);
            }

            return(await ServiceHubRemoteHostClient.CreateAsync(workspace, cancellationToken).ConfigureAwait(false));
        }
Пример #3
0
        public InProcRemoteHostClientProvider(HostWorkspaceServices services)
        {
            _services = services;

            _lazyClient = new AsyncLazy <RemoteHostClient?>(cancellationToken =>
            {
                var optionService = _services.GetRequiredService <IOptionService>();
                if (optionService.GetOption(RemoteHostOptions.RemoteHostTest))
                {
                    return(InProcRemoteHostClient.CreateAsync(_services, runCacheCleanup: false).AsNullable());
                }

                return(SpecializedTasks.Null <RemoteHostClient>());
            }, cacheResult: true);
        }
Пример #4
0
        public async Task <RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken)
        {
            try
            {
                // this is the point where we can create different kind of remote host client in future (cloud or etc)
                if (workspace.Options.GetOption(RemoteHostClientFactoryOptions.RemoteHost_InProc))
                {
                    return(await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup : true, cancellationToken : cancellationToken).ConfigureAwait(false));
                }

                return(await ServiceHubRemoteHostClient.CreateAsync(workspace, cancellationToken).ConfigureAwait(false));
            }
            catch
            {
                return(null);
            }
        }
Пример #5
0
        public Task <RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken)
        {
            try
            {
                // this is the point where we can create different kind of remote host client in future (cloud or etc)
                if (workspace.Options.GetOption(RemoteHostClientFactoryOptions.RemoteHost_InProc))
                {
                    return(InProcRemoteHostClient.CreateAsync(workspace, cancellationToken));
                }

                return(ServiceHubRemoteHostClient.CreateAsync(workspace, cancellationToken));
            }
            catch
            {
                return(Task.FromResult <RemoteHostClient>(null));
            }
        }
Пример #6
0
        public async Task TestTodoComments()
        {
            var code = @"// TODO: Test";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var client = (InProcRemoteHostClient)(await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false, cancellationToken: CancellationToken.None));

                var solution = workspace.CurrentSolution;

                var comments = await client.RunCodeAnalysisServiceOnRemoteHostAsync <IList <TodoComment> >(
                    solution, nameof(IRemoteTodoCommentService.GetTodoCommentsAsync),
                    new object[] { solution.Projects.First().DocumentIds.First(), ImmutableArray.Create(new TodoCommentDescriptor("TODO", 0)) }, CancellationToken.None);

                Assert.Equal(comments.Count, 1);
            }
        }
Пример #7
0
        public async Task TestDesignerAttributes()
        {
            using var workspace = TestWorkspace.CreateCSharp(
                      @"[System.ComponentModel.DesignerCategory(""Form"")]
class Test { }");

            var cancellationTokenSource = new CancellationTokenSource();

            var solution = workspace.CurrentSolution;

            // Ensure remote workspace is in sync with normal workspace.
            var solutionService = await GetSolutionServiceAsync(solution);

            var solutionChecksum = await solution.State.GetChecksumAsync(CancellationToken.None);

            await solutionService.UpdatePrimaryWorkspaceAsync(solutionChecksum, solution.WorkspaceVersion, CancellationToken.None);

            var callback = new DesignerListener();

            using var client = await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup : false);

            var session = await client.TryCreateKeepAliveSessionAsync(
                WellKnownServiceHubServices.RemoteDesignerAttributeService,
                callback,
                cancellationTokenSource.Token);

            var invokeTask = session.TryInvokeAsync(
                nameof(IRemoteDesignerAttributeService.StartScanningForDesignerAttributesAsync),
                solution: null,
                arguments: Array.Empty <object>(),
                cancellationTokenSource.Token);

            var infos = await callback.Infos;

            Assert.Equal(1, infos.Count);

            var info = infos[0];

            Assert.Equal("Form", info.Category);
            Assert.Equal(solution.Projects.Single().Documents.Single().Id, info.DocumentId);

            cancellationTokenSource.Cancel();

            await invokeTask;
        }
Пример #8
0
        public async Task TestDesignerAttributes()
        {
            var code = @"[System.ComponentModel.DesignerCategory(""Form"")]
                class Test { }";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var client = (InProcRemoteHostClient)(await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false, cancellationToken: CancellationToken.None));

                var solution = workspace.CurrentSolution;

                var result = await client.RunCodeAnalysisServiceOnRemoteHostAsync <DesignerAttributeResult>(
                    solution, nameof(IRemoteDesignerAttributeService.ScanDesignerAttributesAsync),
                    solution.Projects.First().DocumentIds.First(), CancellationToken.None);

                Assert.Equal(result.DesignerAttributeArgument, "Form");
            }
        }
Пример #9
0
        public async Task TestRemoteHostSynchronize()
        {
            var code = @"class Test { void Method() { } }";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var client = (InProcRemoteHostClient)(await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false));

                var solution = workspace.CurrentSolution;

                await UpdatePrimaryWorkspace(client, solution);
                await VerifyAssetStorageAsync(client, solution);

                Assert.Equal(
                    await solution.State.GetChecksumAsync(CancellationToken.None),
                    await RemoteWorkspace.CurrentSolution.State.GetChecksumAsync(CancellationToken.None));
            }
        }
Пример #10
0
        public async Task TestRemoteHostSynchronizeGlobalAssets()
        {
            var code = @"class Test { void Method() { } }";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var client = (InProcRemoteHostClient)(await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false));

                await client.TryRunRemoteAsync(
                    WellKnownRemoteHostServices.RemoteHostService,
                    workspace.CurrentSolution,
                    nameof(IRemoteHostService.SynchronizeGlobalAssetsAsync),
                    new object[] { new Checksum[0] {
                                   } }, CancellationToken.None);

                var storage = client.AssetStorage;
                Assert.Equal(0, storage.GetGlobalAssetsOfType <object>(CancellationToken.None).Count());
            }
        }
Пример #11
0
        private async Task <ImmutableArray <SymbolInformation> > GetVsSearchResultsAsync(TestWorkspace workspace, string query)
        {
            var solution = workspace.CurrentSolution;
            var client   = (InProcRemoteHostClient)await InProcRemoteHostClient.CreateAsync(workspace.Services, runCacheCleanup : false);

            var document = solution.Projects.First().Documents.First();

            await UpdatePrimaryWorkspace(client, solution.WithDocumentFilePath(document.Id, Path.Combine(TempRoot.Root, document.FilePath)));

            var workspaceSymbolParams = new WorkspaceSymbolParams
            {
                Query = query,
            };

            var symbolResultsBuilder = ArrayBuilder <SymbolInformation> .GetInstance();

            var threadingContext  = workspace.ExportProvider.GetExportedValue <IThreadingContext>();
            var awaitableProgress = new ProgressWithCompletion <SymbolInformation[]>(symbols =>
            {
                symbolResultsBuilder.AddRange(symbols);
            }, threadingContext.JoinableTaskFactory);

            workspaceSymbolParams.PartialResultToken = awaitableProgress;

            using (var jsonRpc = JsonRpc.Attach(await client.RequestServiceAsync(WellKnownServiceHubService.LanguageServer)))
            {
                var result = await jsonRpc.InvokeWithCancellationAsync <JObject>(
                    Methods.InitializeName,
                    new object[] { new InitializeParams() },
                    CancellationToken.None);

                Assert.True(result["capabilities"]["workspaceSymbolProvider"].ToObject <bool>());

                var symbolResult = await jsonRpc.InvokeWithCancellationAsync <SymbolInformation[]>(
                    Methods.WorkspaceSymbolName,
                    new object[] { workspaceSymbolParams },
                    CancellationToken.None);

                await awaitableProgress.WaitAsync(CancellationToken.None);
            }

            return(symbolResultsBuilder.ToImmutableAndFree());
        }
Пример #12
0
        public async Task TestRemoteHostTextSynchronize()
        {
            var code = @"class Test { void Method() { } }";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var client = (InProcRemoteHostClient)(await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false));

                var solution = workspace.CurrentSolution;

                // sync base solution
                await UpdatePrimaryWorkspace(client, solution);
                await VerifyAssetStorageAsync(client, solution);

                // get basic info
                var oldDocument = solution.Projects.First().Documents.First();
                var oldState    = await oldDocument.State.GetStateChecksumsAsync(CancellationToken.None);

                var oldText = await oldDocument.GetTextAsync();

                // update text
                var newText = oldText.WithChanges(new TextChange(TextSpan.FromBounds(0, 0), "/* test */"));

                // sync
                _ = await client.TryRunRemoteAsync(
                    WellKnownRemoteHostServices.RemoteHostService,
                    nameof(IRemoteHostService.SynchronizeTextAsync),
                    solution : null,
                    new object[] { oldDocument.Id, oldState.Text, newText.GetTextChanges(oldText) },
                    callbackTarget : null,
                    CancellationToken.None);

                // apply change to solution
                var newDocument = oldDocument.WithText(newText);
                var newState    = await newDocument.State.GetStateChecksumsAsync(CancellationToken.None);

                // check that text already exist in remote side
                Assert.True(client.AssetStorage.TryGetAsset <SourceText>(newState.Text, out var remoteText));
                Assert.Equal(newText.ToString(), remoteText.ToString());
            }
        }
Пример #13
0
        public async Task TestDesignerAttributes()
        {
            var code = @"[System.ComponentModel.DesignerCategory(""Form"")]
                class Test { }";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var client = (InProcRemoteHostClient)await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup : false);

                var solution = workspace.CurrentSolution;

                var result = await client.TryRunRemoteAsync <DesignerAttributeResult>(
                    WellKnownServiceHubServices.CodeAnalysisService,
                    nameof(IRemoteDesignerAttributeService.ScanDesignerAttributesAsync),
                    solution,
                    new[] { solution.Projects.First().DocumentIds.First() },
                    callbackTarget : null,
                    CancellationToken.None);

                Assert.Equal("Form", result.Value.DesignerAttributeArgument);
            }
        }
Пример #14
0
        public async Task TestUnknownProject()
        {
            var workspace = new AdhocWorkspace(TestHostServices.CreateHostServices());
            var solution  = workspace.CurrentSolution.AddProject("unknown", "unknown", NoCompilationConstants.LanguageName).Solution;

            var client = (InProcRemoteHostClient)(await InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false));

            await UpdatePrimaryWorkspace(client, solution);
            await VerifyAssetStorageAsync(client, solution);

            // Only C# and VB projects are supported in Remote workspace.
            // See "RemoteSupportedLanguages.IsSupported"
            Assert.Empty(RemoteWorkspace.CurrentSolution.Projects);

            Assert.NotEqual(
                await solution.State.GetChecksumAsync(CancellationToken.None),
                await RemoteWorkspace.CurrentSolution.State.GetChecksumAsync(CancellationToken.None));

            solution = solution.RemoveProject(solution.ProjectIds.Single());
            Assert.Equal(
                await solution.State.GetChecksumAsync(CancellationToken.None),
                await RemoteWorkspace.CurrentSolution.State.GetChecksumAsync(CancellationToken.None));
        }
Пример #15
0
 public Task <RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken)
 {
     return(InProcRemoteHostClient.CreateAsync(workspace, cancellationToken));
 }
Пример #16
0
 public Task <RemoteHostClient> CreateAsync(HostWorkspaceServices services, CancellationToken cancellationToken)
 {
     return(InProcRemoteHostClient.CreateAsync(services, runCacheCleanup: false));
 }
Пример #17
0
 public Task <RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken)
 {
     return(InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false, cancellationToken: cancellationToken));
 }