Skip to content

Commit 2ee49fd

Browse files
Minor fix
1 parent 8efd91d commit 2ee49fd

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/RoslynAnalyzerServer/Analysis/RoslynProjectCompilationProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace SonarLint.VisualStudio.RoslynAnalyzerServer.Analysis;
3333
[method: ImportingConstructor]
3434
internal class RoslynProjectCompilationProvider(ILogger logger) : IRoslynProjectCompilationProvider
3535
{
36-
private readonly ILogger logger = logger.ForContext("Roslyn Analysis", "Analyzer Exception");
36+
private readonly ILogger analyzerExceptionLogger = logger.ForContext("Roslyn Analysis", "Analyzer Exception");
3737

3838
public async Task<IRoslynCompilationWithAnalyzersWrapper> GetProjectCompilationAsync(
3939
IRoslynProjectWrapper project,
@@ -82,7 +82,7 @@ private static IRoslynCompilationWrapper ApplyDiagnosticOptions(
8282
}
8383

8484
private void OnAnalyzerException(Exception arg1, DiagnosticAnalyzer arg2, Diagnostic arg3) =>
85-
logger.LogVerbose(
85+
analyzerExceptionLogger.LogVerbose(
8686
new MessageLevelContext { VerboseContext = [arg2.GetType().Name, arg3.Id] },
8787
arg1.ToString());
8888
}

src/RoslynAnalyzerServer/Analysis/Wrappers/RoslynProjectWrapper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ public bool ContainsDocument(
4242
.Select(document => document.FilePath)
4343
.Where(path => path != null)
4444
.FirstOrDefault(candidatePath =>
45-
candidatePath!.Equals(filePath) || IsCodeBehindRazor(filePath, candidatePath));
45+
candidatePath!.Equals(filePath) || IsAssociatedGeneratedFile(filePath, candidatePath));
4646

4747
return analysisFilePath != null;
4848
}
4949

50-
private static bool IsCodeBehindRazor(string razorFilePath, string candidateDocumentPath) =>
51-
candidateDocumentPath.StartsWith(razorFilePath) && candidateDocumentPath.EndsWith(".g.cs"); // cshtml razor files are converted into .\file.cshtml.<random chars>.g.cs files when included in the compilation
50+
// cshtml razor files are converted into .\file.cshtml.<random chars>.g.cs files when included in the compilation
51+
private static bool IsAssociatedGeneratedFile(string razorFilePath, string candidateDocumentPath) =>
52+
candidateDocumentPath.StartsWith(razorFilePath) && candidateDocumentPath.EndsWith(".g.cs");
5253
}

0 commit comments

Comments
 (0)