Beispiel #1
0
        public async Task CodeCheckSpecifiedFileOnly(string filename)
        {
            var testFile = new TestFile(filename, "class C { int n = true; }");

            SharedOmniSharpTestHost.AddFilesToWorkspace(testFile);
            var messages  = new List <DiagnosticMessage>();
            var emitter   = new DiagnosticTestEmitter(messages);
            var forwarder = new DiagnosticEventForwarder(emitter)
            {
                IsEnabled = true
            };

            var service = new CSharpDiagnosticService(SharedOmniSharpTestHost.Workspace, forwarder, this.LoggerFactory);

            service.QueueDiagnostics(filename);

            await emitter.Emitted;

            Assert.Single(messages);
            var message = messages.First();

            Assert.Single(message.Results);
            var result = message.Results.First();

            Assert.Single(result.QuickFixes);
            Assert.Equal(filename, result.FileName);
        }
Beispiel #2
0
        public async Task CodeCheckSpecifiedFileOnly()
        {
            var workspace = await TestHelpers.CreateSimpleWorkspace(new Dictionary <string, string>
            {
                { "a.cs", "class C { int n = true; }" }
            });

            var fakeLoggerFactory = new FakeLoggerFactory();
            var messages          = new List <OmniSharp.Models.DiagnosticMessage>();
            var emitter           = new DiagnosticTestEmitter(messages);
            var forwarder         = new DiagnosticEventForwarder(emitter);

            forwarder.IsEnabled = true;
            var service = new CSharpDiagnosticService(workspace, forwarder, fakeLoggerFactory);

            service.QueueDiagnostics("a.cs");

            await emitter.Emitted;

            Assert.Equal(1, messages.Count);
            var message = messages.First();

            Assert.Equal(1, message.Results.Count());
            var result = message.Results.First();

            Assert.Equal(1, result.QuickFixes.Count());
            Assert.Equal("a.cs", result.FileName);
        }
        public Task <DiagnosticsResponse> Handle(DiagnosticsRequest request)
        {
            if (!_forwarder.IsEnabled)
            {
                _forwarder.IsEnabled = true;
            }

            var documents = request.FileName != null
                ? new [] { request.FileName }
                : _workspace.CurrentSolution.Projects.SelectMany(project => project.Documents.Select(x => x.FilePath));

            _diagnostics.QueueDiagnostics(documents.ToArray());

            return(Task.FromResult(new DiagnosticsResponse()));
        }