Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.

Commit 8438ce5

Browse files
committed
Fixed formatting
1 parent 9fa21f2 commit 8438ce5

16 files changed

+709
-674
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[*]
2+
end_of_line = crlf
3+
4+
[*.cs]
5+
indent_style = space
6+
indent_size = 4
7+
trim_trailing_whitespace = true
8+
insert_final_newline = false
9+
csharp_style_var_when_type_is_apparent = true : suggestion
10+
csharp_new_line_before_open_brace = all
11+
csharp_prefer_braces = true
12+
dotnet_sort_system_directives_first = true
13+
dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion
14+
dotnet_style_predefined_type_for_member_access = true : suggestion
15+
dotnet_style_explicit_tuple_names = true : suggestion

IntelliSenseExtender.sln

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26430.4
4+
VisualStudioVersion = 15.0.27004.2002
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelliSenseExtender", "IntelliSenseExtender\IntelliSenseExtender.csproj", "{2E41A5F8-16A0-4694-960B-73A8199AE37D}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelliSenseExtender.Tests", "IntelliSenseExtender.Tests\IntelliSenseExtender.Tests.csproj", "{D763B057-96A5-48A1-BF68-71A11647F837}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DEE3D316-D05B-48A3-AAD3-FF4A106178EF}"
11+
ProjectSection(SolutionItems) = preProject
12+
.editorconfig = .editorconfig
13+
EndProjectSection
14+
EndProject
1015
Global
1116
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1217
Debug|Any CPU = Debug|Any CPU
@@ -25,4 +30,7 @@ Global
2530
GlobalSection(SolutionProperties) = preSolution
2631
HideSolutionNode = FALSE
2732
EndGlobalSection
33+
GlobalSection(ExtensibilityGlobals) = postSolution
34+
SolutionGuid = {E18C549E-2658-476D-8984-10C7305DD334}
35+
EndGlobalSection
2836
EndGlobal

IntelliSenseExtender/Editor/NamespaceResolver.cs

+32-31
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,36 @@
44

55
namespace IntelliSenseExtender.Editor
66
{
7-
public class NamespaceResolver
8-
{
9-
private DTE GetDTE()
10-
{
11-
return (DTE)Package.GetGlobalService(typeof(DTE));
12-
}
13-
14-
private string GetNamespaceUsing(string nsName) => $"using {nsName};" + Environment.NewLine;
15-
16-
private string GetStaticUsing(string className) => $"using static {className};" + Environment.NewLine;
17-
18-
19-
/// <summary>
20-
/// Add namespace to current document
21-
/// </summary>
22-
public void AddNamespaceOrStatic(string namespaceOrClassName, bool isNamespace = true)
23-
{
24-
//TODO: use roslyn
25-
var dte = GetDTE();
26-
if (isNamespace && namespaceOrClassName == @"<global namespace>") return;//no need to import global namespace
27-
if (dte.ActiveDocument.Object() is TextDocument textDoc) {
28-
var textToInsert = isNamespace ? GetNamespaceUsing(namespaceOrClassName) : GetStaticUsing(namespaceOrClassName);
29-
30-
var startPoint = textDoc.StartPoint;
31-
var editPoint = textDoc.CreateEditPoint(startPoint);
32-
editPoint.Insert(textToInsert);
33-
}
34-
}
35-
36-
37-
}
7+
public class NamespaceResolver
8+
{
9+
private DTE GetDTE()
10+
{
11+
return (DTE)Package.GetGlobalService(typeof(DTE));
12+
}
13+
14+
private string GetNamespaceUsing(string nsName) => $"using {nsName};" + Environment.NewLine;
15+
16+
private string GetStaticUsing(string className) => $"using static {className};" + Environment.NewLine;
17+
18+
19+
/// <summary>
20+
/// Add namespace to current document
21+
/// </summary>
22+
public void AddNamespaceOrStatic(string namespaceOrClassName, bool isNamespace = true)
23+
{
24+
//TODO: use roslyn
25+
var dte = GetDTE();
26+
if (isNamespace && namespaceOrClassName == @"<global namespace>") return;//no need to import global namespace
27+
if (dte.ActiveDocument.Object() is TextDocument textDoc)
28+
{
29+
var textToInsert = isNamespace ? GetNamespaceUsing(namespaceOrClassName) : GetStaticUsing(namespaceOrClassName);
30+
31+
var startPoint = textDoc.StartPoint;
32+
var editPoint = textDoc.CreateEditPoint(startPoint);
33+
editPoint.Insert(textToInsert);
34+
}
35+
}
36+
37+
38+
}
3839
}

IntelliSenseExtender/ExposedInternals/SymbolCompletionItem.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Reflection;
44
using System.Threading;

IntelliSenseExtender/ExposedInternals/SyntaxTreeExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Reflection;
44
using System.Threading;

IntelliSenseExtender/Extensions/SymbolExtensions.cs

+42-40
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,53 @@
44

55
namespace IntelliSenseExtender.Extensions
66
{
7-
public static class SymbolExtensions
8-
{
9-
public static string GetNamespace(this ISymbol symbol)
7+
public static class SymbolExtensions
108
{
11-
return symbol.ContainingNamespace.ToDisplayString();
12-
}
13-
14-
/// <summary>
15-
/// Is this good for static import?
16-
/// </summary>
17-
/// <param name="symbol"></param>
18-
/// <returns></returns>
19-
public static bool IsStaticImportable(this ISymbol symbol)
20-
{
21-
return symbol.ContainingType != null &&
22-
((symbol.Kind == SymbolKind.Field && (symbol.IsStatic || (symbol is IFieldSymbol field && field.IsConst))) ||
23-
(symbol.Kind == SymbolKind.Property && symbol.IsStatic) ||
24-
(symbol is IMethodSymbol method && method.IsStatic && !method.IsExtensionMethod && method.MethodKind == MethodKind.Ordinary)
25-
);
26-
}
9+
public static string GetNamespace(this ISymbol symbol)
10+
{
11+
return symbol.ContainingNamespace.ToDisplayString();
12+
}
2713

28-
public static string GetFullyQualifiedName(this ISymbol symbol)
29-
{
30-
return symbol.ToDisplayString();
31-
}
14+
/// <summary>
15+
/// Is this good for static import?
16+
/// </summary>
17+
/// <param name="symbol"></param>
18+
/// <returns></returns>
19+
public static bool IsStaticImportable(this ISymbol symbol)
20+
{
21+
return symbol.ContainingType != null &&
22+
((symbol.Kind == SymbolKind.Field && (symbol.IsStatic || (symbol is IFieldSymbol field && field.IsConst))) ||
23+
(symbol.Kind == SymbolKind.Property && symbol.IsStatic) ||
24+
(symbol is IMethodSymbol method && method.IsStatic && !method.IsExtensionMethod && method.MethodKind == MethodKind.Ordinary)
25+
);
26+
}
3227

33-
public static bool IsObsolete(this ISymbol symbol)
34-
{
35-
return symbol
36-
.GetAttributes()
37-
.Any(attribute => attribute.AttributeClass.Name == nameof(ObsoleteAttribute));
38-
}
28+
public static string GetFullyQualifiedName(this ISymbol symbol)
29+
{
30+
return symbol.ToDisplayString();
31+
}
3932

40-
public static bool IsAttribute(this INamedTypeSymbol typeSymbol)
41-
{
42-
var currentSymbol = typeSymbol.BaseType;
43-
while (currentSymbol != null) {
44-
if (currentSymbol.Name == nameof(Attribute)
45-
&& currentSymbol.ContainingNamespace?.Name == nameof(System)) {
46-
return true;
33+
public static bool IsObsolete(this ISymbol symbol)
34+
{
35+
return symbol
36+
.GetAttributes()
37+
.Any(attribute => attribute.AttributeClass.Name == nameof(ObsoleteAttribute));
4738
}
4839

49-
currentSymbol = currentSymbol.BaseType;
50-
}
51-
return false;
40+
public static bool IsAttribute(this INamedTypeSymbol typeSymbol)
41+
{
42+
var currentSymbol = typeSymbol.BaseType;
43+
while (currentSymbol != null)
44+
{
45+
if (currentSymbol.Name == nameof(Attribute)
46+
&& currentSymbol.ContainingNamespace?.Name == nameof(System))
47+
{
48+
return true;
49+
}
50+
51+
currentSymbol = currentSymbol.BaseType;
52+
}
53+
return false;
54+
}
5255
}
53-
}
5456
}

IntelliSenseExtender/Extensions/SyntaxTreeExtensions.cs

+61-55
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,76 @@
88

99
namespace IntelliSenseExtender.Extensions
1010
{
11-
public static class SyntaxTreeExtensions
12-
{
13-
public static IReadOnlyList<string> GetImportedNamespaces(this SyntaxTree tree)
14-
{
15-
if (tree.GetRoot() is CompilationUnitSyntax compilationUnitSyntax) {
16-
var childNodes = compilationUnitSyntax.ChildNodes().ToArray();
11+
public static class SyntaxTreeExtensions
12+
{
13+
public static IReadOnlyList<string> GetImportedNamespaces(this SyntaxTree tree)
14+
{
15+
if (tree.GetRoot() is CompilationUnitSyntax compilationUnitSyntax)
16+
{
17+
var childNodes = compilationUnitSyntax.ChildNodes().ToArray();
1718

18-
var namespaces = childNodes
19-
.OfType<UsingDirectiveSyntax>()
20-
.Where(u => u.StaticKeyword.Value == null)
21-
.Select(u => u.Name.ToString()).ToList();
19+
var namespaces = childNodes
20+
.OfType<UsingDirectiveSyntax>()
21+
.Where(u => u.StaticKeyword.Value == null)
22+
.Select(u => u.Name.ToString()).ToList();
2223

23-
var currentNamespaces = childNodes
24-
.OfType<NamespaceDeclarationSyntax>()
25-
.Select(nsSyntax => nsSyntax.Name.ToString());
24+
var currentNamespaces = childNodes
25+
.OfType<NamespaceDeclarationSyntax>()
26+
.Select(nsSyntax => nsSyntax.Name.ToString());
2627

27-
namespaces.AddRange(currentNamespaces);
28-
namespaces.AddRange(currentNamespaces.SelectMany(GetParentNamespaces));
28+
namespaces.AddRange(currentNamespaces);
29+
namespaces.AddRange(currentNamespaces.SelectMany(GetParentNamespaces));
2930

30-
return namespaces;
31-
}
32-
else {
33-
return new string[] { };
34-
}
35-
}
31+
return namespaces;
32+
}
33+
else
34+
{
35+
return new string[] { };
36+
}
37+
}
3638

37-
public static IReadOnlyList<string> GetImportedStatics(this SyntaxTree tree)
38-
{
39-
if (tree.GetRoot() is CompilationUnitSyntax compilationUnitSyntax) {
40-
var childNodes = compilationUnitSyntax.ChildNodes().ToArray();
39+
public static IReadOnlyList<string> GetImportedStatics(this SyntaxTree tree)
40+
{
41+
if (tree.GetRoot() is CompilationUnitSyntax compilationUnitSyntax)
42+
{
43+
var childNodes = compilationUnitSyntax.ChildNodes().ToArray();
4144

42-
return childNodes
43-
.OfType<UsingDirectiveSyntax>()
44-
.Where(u => u.StaticKeyword.Value != null)
45-
.Select(u => u.Name.ToString()).ToList();
46-
}
47-
else {
48-
return new string[] { };
49-
}
50-
}
45+
return childNodes
46+
.OfType<UsingDirectiveSyntax>()
47+
.Where(u => u.StaticKeyword.Value != null)
48+
.Select(u => u.Name.ToString()).ToList();
49+
}
50+
else
51+
{
52+
return new string[] { };
53+
}
54+
}
5155

52-
public static bool IsMemberAccessContext(this SyntaxTree syntaxTree, int position, out ExpressionSyntax accessedExpressionSyntax, CancellationToken cancellationToken)
53-
{
54-
accessedExpressionSyntax = null;
56+
public static bool IsMemberAccessContext(this SyntaxTree syntaxTree, int position, out ExpressionSyntax accessedExpressionSyntax, CancellationToken cancellationToken)
57+
{
58+
accessedExpressionSyntax = null;
5559

56-
var token = syntaxTree.FindTokenOnLeftOfPosition(position, cancellationToken);
57-
if (token.Kind() == SyntaxKind.DotToken
58-
&& token.Parent is MemberAccessExpressionSyntax memberAccessNode) {
59-
accessedExpressionSyntax = memberAccessNode.Expression;
60-
}
61-
return accessedExpressionSyntax != null;
62-
}
60+
var token = syntaxTree.FindTokenOnLeftOfPosition(position, cancellationToken);
61+
if (token.Kind() == SyntaxKind.DotToken
62+
&& token.Parent is MemberAccessExpressionSyntax memberAccessNode)
63+
{
64+
accessedExpressionSyntax = memberAccessNode.Expression;
65+
}
66+
return accessedExpressionSyntax != null;
67+
}
6368

64-
private static IReadOnlyList<string> GetParentNamespaces(string nsName)
65-
{
66-
var splittedNs = nsName.Split('.');
69+
private static IReadOnlyList<string> GetParentNamespaces(string nsName)
70+
{
71+
var splittedNs = nsName.Split('.');
6772

68-
var parentNamespaces = new List<string>();
69-
for (int i = 1; i < splittedNs.Length; i++) {
70-
var parentNs = string.Join(".", splittedNs.Take(i));
71-
parentNamespaces.Add(parentNs);
72-
}
73+
var parentNamespaces = new List<string>();
74+
for (int i = 1; i < splittedNs.Length; i++)
75+
{
76+
var parentNs = string.Join(".", splittedNs.Take(i));
77+
parentNamespaces.Add(parentNs);
78+
}
7379

74-
return parentNamespaces;
75-
}
76-
}
80+
return parentNamespaces;
81+
}
82+
}
7783
}

0 commit comments

Comments
 (0)