Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CodeStructureService with FileScoped Namespace support #2226

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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