Skip to content

Commit

Permalink
Update CodeStructureService with FileScoped Namespace support
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Sep 2, 2021
1 parent 1ff2a19 commit 2eb2e13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private IEnumerable<CodeElement> CreateCodeElements(SyntaxNode node, SourceText
case EnumDeclarationSyntax enumDeclaration:
yield return CreateCodeElement(enumDeclaration, text, semanticModel);
break;
case NamespaceDeclarationSyntax namespaceDeclaration:
case BaseNamespaceDeclarationSyntax namespaceDeclaration:
yield return CreateCodeElement(namespaceDeclaration, text, semanticModel);
break;
case BaseMethodDeclarationSyntax baseMethodDeclaration:
Expand Down Expand Up @@ -186,7 +186,7 @@ private CodeElement CreateCodeElement(EnumDeclarationSyntax enumDeclaration, Sou
return builder.ToCodeElement();
}

private CodeElement CreateCodeElement(NamespaceDeclarationSyntax namespaceDeclaration, SourceText text, SemanticModel semanticModel)
private CodeElement CreateCodeElement(BaseNamespaceDeclarationSyntax namespaceDeclaration, SourceText text, SemanticModel semanticModel)
{
var symbol = semanticModel.GetDeclaredSymbol(namespaceDeclaration);
if (symbol == null)
Expand Down
27 changes: 27 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/CodeStructureFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ struct S { }
AssertElement(children[4], SymbolKinds.Struct, "S", "N.S");
}

[Fact]
public async Task AllTypesInFileScopedNamespace()
{
const string source = @"
namespace N;
class C { }
delegate void D(int i, ref string s);
enum E { One, Two, Three }
interface I { }
struct S { }
";

var response = await GetCodeStructureAsync(source);

var elementN = Assert.Single(response.Elements);
AssertElement(elementN, SymbolKinds.Namespace, "N", "N");

var children = elementN.Children;
Assert.Equal(5, children.Count);
AssertElement(children[0], SymbolKinds.Class, "C", "N.C");
AssertElement(children[1], SymbolKinds.Delegate, "D", "N.D");
AssertElement(children[2], SymbolKinds.Enum, "E", "N.E");
AssertElement(children[3], SymbolKinds.Interface, "I", "N.I");
AssertElement(children[4], SymbolKinds.Struct, "S", "N.S");
}

[Fact]
public async Task GenericTypesInNamespace()
{
Expand Down

0 comments on commit 2eb2e13

Please sign in to comment.