Skip to content

Commit 9577723

Browse files
author
Samir L. Boulema
committed
Add support for File-scoped namespaces #117
1 parent 4f026f2 commit 9577723

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

CodeNav.Shared/Mappers/NamespaceMapper.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,50 @@ public static CodeNamespaceItem MapNamespace(NamespaceDeclarationSyntax member,
5252
return item;
5353
}
5454

55+
#if VS2022
56+
public static CodeNamespaceItem MapNamespace(BaseNamespaceDeclarationSyntax member,
57+
ICodeViewUserControl control, SemanticModel semanticModel, SyntaxTree tree)
58+
{
59+
if (member == null) return null;
60+
61+
var item = BaseMapper.MapBase<CodeNamespaceItem>(member, member.Name, control, semanticModel);
62+
item.Kind = CodeItemKindEnum.Namespace;
63+
item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access);
64+
item.BorderColor = Colors.DarkGray;
65+
item.IgnoreVisibility = VisibilityHelper.GetIgnoreVisibility(item);
66+
67+
if (TriviaSummaryMapper.HasSummary(member) && SettingsHelper.UseXMLComments)
68+
{
69+
item.Tooltip = TriviaSummaryMapper.Map(member);
70+
}
71+
72+
var regions = RegionMapper.MapRegions(tree, member.Span, control);
73+
74+
foreach (var namespaceMember in member.Members)
75+
{
76+
var memberItem = SyntaxMapper.MapMember(namespaceMember);
77+
if (memberItem != null && !RegionMapper.AddToRegion(regions, memberItem))
78+
{
79+
item.Members.Add(memberItem);
80+
}
81+
}
82+
83+
// Add regions to namespace if they are not present in any children of the namespace
84+
if (regions.Any())
85+
{
86+
foreach (var region in regions)
87+
{
88+
if (FindHelper.FindCodeItem(item.Members, region.Id) == null)
89+
{
90+
item.Members.Add(region);
91+
}
92+
}
93+
}
94+
95+
return item;
96+
}
97+
#endif
98+
5599
public static CodeNamespaceItem MapNamespace(VisualBasicSyntax.NamespaceBlockSyntax member,
56100
ICodeViewUserControl control, SemanticModel semanticModel, SyntaxTree tree)
57101
{

CodeNav.Shared/Mappers/SyntaxMapper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,14 @@ public static CodeItem MapMember(MemberDeclarationSyntax member)
216216
return DelegateEventMapper.MapEvent(member as EventFieldDeclarationSyntax, _control, _semanticModel);
217217
case SyntaxKind.DelegateDeclaration:
218218
return DelegateEventMapper.MapDelegate(member as DelegateDeclarationSyntax, _control, _semanticModel);
219+
#if VS2022
220+
case SyntaxKind.FileScopedNamespaceDeclaration:
219221
case SyntaxKind.NamespaceDeclaration:
220-
return NamespaceMapper.MapNamespace(member as NamespaceDeclarationSyntax, _control, _semanticModel, _tree);
222+
return NamespaceMapper.MapNamespace(member as BaseNamespaceDeclarationSyntax, _control, _semanticModel, _tree);
223+
#else
224+
case SyntaxKind.NamespaceDeclaration:
225+
return NamespaceMapper.MapNamespace(member as NamespaceDeclarationSyntax, _control, _semanticModel, _tree);
226+
#endif
221227
case SyntaxKind.ConstructorDeclaration:
222228
return MethodMapper.MapConstructor(member as ConstructorDeclarationSyntax, _control, _semanticModel);
223229
case SyntaxKind.IndexerDeclaration:

CodeNav.VS2019/CodeNav.VS2019.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<DebugType>full</DebugType>
6363
<Optimize>false</Optimize>
6464
<OutputPath>bin\Debug\</OutputPath>
65-
<DefineConstants>DEBUG;TRACE</DefineConstants>
65+
<DefineConstants>TRACE;DEBUG;VS2019</DefineConstants>
6666
<ErrorReport>prompt</ErrorReport>
6767
<WarningLevel>4</WarningLevel>
6868
<DeployExtension Condition=" '$(AppVeyor)' != '' Or '$(TF_BUILD)' != '' ">False</DeployExtension>
@@ -73,7 +73,7 @@
7373
<DebugType>pdbonly</DebugType>
7474
<Optimize>true</Optimize>
7575
<OutputPath>bin\Release\</OutputPath>
76-
<DefineConstants>TRACE</DefineConstants>
76+
<DefineConstants>TRACE;VS2019</DefineConstants>
7777
<ErrorReport>prompt</ErrorReport>
7878
<WarningLevel>4</WarningLevel>
7979
<DeployExtension Condition=" '$(AppVeyor)' != '' Or '$(TF_BUILD)' != '' ">False</DeployExtension>

CodeNav.VS2022/CodeNav.VS2022.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<DebugType>full</DebugType>
6363
<Optimize>false</Optimize>
6464
<OutputPath>bin\Debug\</OutputPath>
65-
<DefineConstants>DEBUG;TRACE</DefineConstants>
65+
<DefineConstants>TRACE;DEBUG;VS2022</DefineConstants>
6666
<ErrorReport>prompt</ErrorReport>
6767
<WarningLevel>4</WarningLevel>
6868
<DeployExtension Condition=" '$(AppVeyor)' != '' Or '$(TF_BUILD)' != '' ">False</DeployExtension>
@@ -73,7 +73,7 @@
7373
<DebugType>pdbonly</DebugType>
7474
<Optimize>true</Optimize>
7575
<OutputPath>bin\Release\</OutputPath>
76-
<DefineConstants>TRACE</DefineConstants>
76+
<DefineConstants>TRACE;VS2022</DefineConstants>
7777
<ErrorReport>prompt</ErrorReport>
7878
<WarningLevel>4</WarningLevel>
7979
<DeployExtension Condition=" '$(AppVeyor)' != '' Or '$(TF_BUILD)' != '' ">False</DeployExtension>

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trigger:
77
- main
88
- feature/*
99

10-
name: 8.2.$(Build.BuildId)
10+
name: 8.3.$(Build.BuildId)
1111

1212
steps:
1313
- task: NuGetCommand@2

0 commit comments

Comments
 (0)