|
3 | 3 | using System; |
4 | 4 | using System.Linq; |
5 | 5 | using System.Threading.Tasks; |
| 6 | +using Microsoft.CodeAnalysis; |
6 | 7 | using Microsoft.CodeAnalysis.Completion; |
7 | 8 | using Microsoft.CodeAnalysis.Completion.Providers; |
8 | 9 | using Microsoft.CodeAnalysis.CSharp.Extensions; |
@@ -74,56 +75,65 @@ public override async Task ProvideCompletionsAsync(CompletionContext context) |
74 | 75 |
|
75 | 76 | var span = new TextSpan(position, 0); |
76 | 77 | var semanticModel = await document.GetSemanticModelForSpanAsync(span, cancellationToken).ConfigureAwait(false); |
77 | | - var type = typeInferenceService.InferType(semanticModel, position, |
78 | | - objectAsDefault: true, |
| 78 | + var types = typeInferenceService.InferTypes(semanticModel, position, |
79 | 79 | cancellationToken: cancellationToken); |
80 | 80 |
|
81 | | - // If we have a Nullable<T>, unwrap it. |
82 | | - if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) |
| 81 | + if (types.Length == 0) |
83 | 82 | { |
84 | | - type = type.GetTypeArguments().FirstOrDefault(); |
85 | | - |
86 | | - if (type == null) |
87 | | - { |
88 | | - return; |
89 | | - } |
| 83 | + types = ImmutableArray.Create<ITypeSymbol>(semanticModel.Compilation.ObjectType); |
90 | 84 | } |
91 | 85 |
|
92 | | - if (type.TypeKind != TypeKind.Enum) |
| 86 | + foreach (var typeIterator in types) |
93 | 87 | { |
94 | | - type = TryGetEnumTypeInEnumInitializer(semanticModel, token, type, cancellationToken) ?? |
95 | | - TryGetCompletionListType(type, semanticModel.GetEnclosingNamedType(position, cancellationToken), semanticModel.Compilation); |
| 88 | + var type = typeIterator; |
96 | 89 |
|
97 | | - if (type == null) |
| 90 | + // If we have a Nullable<T>, unwrap it. |
| 91 | + if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) |
98 | 92 | { |
99 | | - return; |
| 93 | + type = type.GetTypeArguments().FirstOrDefault(); |
| 94 | + |
| 95 | + if (type == null) |
| 96 | + { |
| 97 | + continue; |
| 98 | + } |
100 | 99 | } |
101 | | - } |
102 | 100 |
|
103 | | - if (!type.IsEditorBrowsable(options.GetOption(CompletionOptions.HideAdvancedMembers, semanticModel.Language), semanticModel.Compilation)) |
104 | | - { |
105 | | - return; |
106 | | - } |
| 101 | + if (type.TypeKind != TypeKind.Enum) |
| 102 | + { |
| 103 | + type = TryGetEnumTypeInEnumInitializer(semanticModel, token, type, cancellationToken) ?? |
| 104 | + TryGetCompletionListType(type, semanticModel.GetEnclosingNamedType(position, cancellationToken), semanticModel.Compilation); |
107 | 105 |
|
108 | | - // Does type have any aliases? |
109 | | - var alias = await type.FindApplicableAlias(position, semanticModel, cancellationToken).ConfigureAwait(false); |
| 106 | + if (type == null) |
| 107 | + { |
| 108 | + continue; |
| 109 | + } |
| 110 | + } |
110 | 111 |
|
111 | | - var displayService = document.GetLanguageService<ISymbolDisplayService>(); |
112 | | - var displayText = alias != null |
113 | | - ? alias.Name |
114 | | - : displayService.ToMinimalDisplayString(semanticModel, position, type); |
| 112 | + if (!type.IsEditorBrowsable(options.GetOption(CompletionOptions.HideAdvancedMembers, semanticModel.Language), semanticModel.Compilation)) |
| 113 | + { |
| 114 | + continue; |
| 115 | + } |
115 | 116 |
|
116 | | - var workspace = document.Project.Solution.Workspace; |
117 | | - var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false); |
| 117 | + // Does type have any aliases? |
| 118 | + var alias = await type.FindApplicableAlias(position, semanticModel, cancellationToken).ConfigureAwait(false); |
118 | 119 |
|
119 | | - var item = SymbolCompletionItem.CreateWithSymbolId( |
120 | | - displayText: displayText, |
121 | | - displayTextSuffix: "", |
122 | | - symbols: ImmutableArray.Create(alias ?? type), |
123 | | - rules: s_rules.WithMatchPriority(MatchPriority.Preselect), |
124 | | - contextPosition: position); |
| 120 | + var displayService = document.GetLanguageService<ISymbolDisplayService>(); |
| 121 | + var displayText = alias != null |
| 122 | + ? alias.Name |
| 123 | + : displayService.ToMinimalDisplayString(semanticModel, position, type); |
125 | 124 |
|
126 | | - context.AddItem(item); |
| 125 | + var workspace = document.Project.Solution.Workspace; |
| 126 | + var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false); |
| 127 | + |
| 128 | + var item = SymbolCompletionItem.CreateWithSymbolId( |
| 129 | + displayText: displayText, |
| 130 | + displayTextSuffix: "", |
| 131 | + symbols: ImmutableArray.Create(alias ?? type), |
| 132 | + rules: s_rules.WithMatchPriority(MatchPriority.Preselect), |
| 133 | + contextPosition: position); |
| 134 | + |
| 135 | + context.AddItem(item); |
| 136 | + } |
127 | 137 | } |
128 | 138 | catch (Exception e) when (FatalError.ReportUnlessCanceled(e)) |
129 | 139 | { |
|
0 commit comments