Skip to content

Commit c854523

Browse files
CopilotAArnott
andauthored
Fix VSMEF008 to emit fully-qualified type names in diagnostic messages (#686)
* Initial plan * Fix VSMEF008 diagnostic to use fully-qualified type names in error message Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
1 parent 8013366 commit c854523

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Microsoft.VisualStudio.Composition.Analyzers/VSMEF008ImportContractTypeMismatchAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ private static void AnalyzeMember(
183183
context.ReportDiagnostic(Diagnostic.Create(
184184
Descriptor,
185185
location,
186-
explicitContractType.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat),
187-
expectedType.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat)));
186+
explicitContractType.ToDisplayString(FullyQualifiedTypeNameFormat),
187+
expectedType.ToDisplayString(FullyQualifiedTypeNameFormat)));
188188
}
189189
}
190190
}

test/Microsoft.VisualStudio.Composition.Analyzers.Tests/VSMEF008ImportContractTypeMismatchAnalyzerTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using Microsoft.CodeAnalysis.Text;
5+
using Microsoft.VisualStudio.Composition.Analyzers;
56
using VerifyCS = CSharpCodeFixVerifier<Microsoft.VisualStudio.Composition.Analyzers.VSMEF008ImportContractTypeMismatchAnalyzer, Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>;
67

78
public class VSMEF008ImportContractTypeMismatchAnalyzerTests
@@ -280,4 +281,30 @@ class Foo
280281
("vs-mef.ContractNamesAssignability.txt", SourceText.From(allowList)));
281282
await verifier.RunAsync();
282283
}
284+
285+
[Fact]
286+
public async Task DiagnosticMessage_UsesFullyQualifiedTypeNames()
287+
{
288+
string test = """
289+
using System.ComponentModel.Composition;
290+
291+
namespace MyCompany.Services
292+
{
293+
interface IServiceBroker { }
294+
class SVsServiceProvider { }
295+
296+
class Foo
297+
{
298+
[Import(typeof(SVsServiceProvider))]
299+
public IServiceBroker {|#0:Value|} { get; set; }
300+
}
301+
}
302+
""";
303+
304+
await VerifyCS.VerifyAnalyzerAsync(
305+
test,
306+
VerifyCS.Diagnostic(VSMEF008ImportContractTypeMismatchAnalyzer.Id)
307+
.WithLocation(0)
308+
.WithArguments("MyCompany.Services.SVsServiceProvider", "MyCompany.Services.IServiceBroker"));
309+
}
283310
}

0 commit comments

Comments
 (0)