Skip to content

Commit

Permalink
return empty collections
Browse files Browse the repository at this point in the history
  • Loading branch information
filipw committed May 4, 2021
1 parent c1d5675 commit b41a1bd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Expand Up @@ -56,7 +56,7 @@ public async Task<BlockStructureResponse> Handle(BlockStructureRequest request)
var document = await _workspace.GetDocumentFromFullProjectModelAsync(request.FileName);
if (document == null)
{
return new BlockStructureResponse();
return new BlockStructureResponse { Spans = Array.Empty<CodeFoldingBlock>() };
}

var text = await document.GetTextAsync();
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Threading.Tasks;
Expand Down Expand Up @@ -36,7 +37,7 @@ public async Task<CodeStructureResponse> Handle(CodeStructureRequest request)
var document = await _workspace.GetDocumentFromFullProjectModelAsync(request.FileName);
if (document == null)
{
return new CodeStructureResponse();
return new CodeStructureResponse { Elements = Array.Empty<CodeElement>() };
}

var elements = await GetCodeElementsAsync(document);
Expand Down
5 changes: 3 additions & 2 deletions tests/OmniSharp.Roslyn.CSharp.Tests/BlockStructureFacts.cs
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using OmniSharp.Models.V2;
Expand Down Expand Up @@ -46,14 +47,14 @@ public async Task NonExistingFile()
{
var request = new BlockStructureRequest
{
FileName = "foo.cs"
FileName = $"{Guid.NewGuid().ToString("N")}.cs"
};

var requestHandler = GetRequestHandler(SharedOmniSharpTestHost);
var response = await requestHandler.Handle(request);

Assert.NotNull(response);
Assert.Null(response.Spans);
Assert.Empty(response.Spans);
}

[Fact]
Expand Down
7 changes: 4 additions & 3 deletions tests/OmniSharp.Roslyn.CSharp.Tests/CodeStructureFacts.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using OmniSharp.Mef;
Expand Down Expand Up @@ -418,14 +419,14 @@ public async Task NonExistingFile()
{
var request = new CodeStructureRequest
{
FileName = "foo.cs"
FileName = $"{Guid.NewGuid().ToString("N")}.cs"
};

var requestHandler = GetRequestHandler(SharedOmniSharpTestHost);
var response = await requestHandler.Handle(request);

Assert.NotNull(response);
Assert.Null(response.Elements);
Assert.Empty(response.Elements);
}

private static void AssertRange(CodeElement elementC, TestContent content, string contentSpanName, string elementRangeName)
Expand Down

0 comments on commit b41a1bd

Please sign in to comment.