-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't fail for Razor: SymbolReference locations for @typeparam are misplaced #8424
Don't fail for Razor: SymbolReference locations for @typeparam are misplaced #8424
Conversation
} | ||
} else if (declarationRange.get().overlap(referenceRange.get())) { | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("The declaration token at {} overlaps with the referencing token {} in file {}", declarationRange.get(), referenceRange.get(), file.filename()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the actual fix here? It's hard for me to follow what the difference is from the diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the condition from the if statement: declarationRange.get().overlap(referenceRange.get())
. If we add the range directly, the API we use (symbol.newReference
) will throw.
So this check ensures that we log a warning (in debug) and continue the import ignoring the second range that is overlaping.
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class RazorImporterTestBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New base class for all tests that interact with "src/test/resources/RazorProtobufImporter" files.
Tuple.tuple(CoreMetrics.CLASSES, 1), | ||
Tuple.tuple(CoreMetrics.STATEMENTS, 15), | ||
Tuple.tuple(CoreMetrics.FUNCTIONS, 4), | ||
Tuple.tuple(CoreMetrics.COMPLEXITY, 5), | ||
Tuple.tuple(CoreMetrics.FUNCTIONS, 3), | ||
Tuple.tuple(CoreMetrics.COMMENT_LINES, 0), | ||
Tuple.tuple(CoreMetrics.COGNITIVE_COMPLEXITY, 1), | ||
Tuple.tuple(CoreMetrics.NCLOC, 14)); | ||
Tuple.tuple(CoreMetrics.CLASSES, 0), | ||
Tuple.tuple(CoreMetrics.NCLOC, 13), | ||
Tuple.tuple(CoreMetrics.STATEMENTS, 6)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some values changed, likely because the pd files were created new, and the old ones didn't fit "Cases.razor" or because the old ones were created with .Net 7 SDK and the new ones with .Net 8 SDK.
var referenceRange = toTextRange(file, refTextRange); | ||
if (referenceRange.isEmpty()) { | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("The reported token was out of the range. File {}, Range {}", file.filename(), refTextRange); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We lost coverage for that line because in the new pb, there is not "out of range" anymore (either fixed in .Net 8 SDK or fixed somewhere else).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They fixed the tab problem and we used tabs to reproduce that out-of-range issue.
SonarCloud Quality Gate failed.
|
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Roslyn version: 4.8.0.0Language version: CSharp12!Concurrent execution: enabled��File 'Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\OverlapSymbolReferences_razor.g.cs' was recognized as razor generated��File 'Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Cases_razor.g.cs' was recognized as razor generatedvrFile 'C:\Users\martin.strecker\Desktop\WebAss\obj\Debug\net8.0\WebAss.AssemblyInfo.cs' was recognized as generated��File 'C:\Users\martin.strecker\Desktop\WebAss\obj\Debug\net8.0\.NETCoreApp,Version=v8.0.AssemblyAttributes.cs' was recognized as generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double check I understand well: did you recreate these PB files with .NET 8 @martin-strecker-sonarsource ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I also added the csproj as part of the PR, so it is more easy to recreate the pb files (before, the csproj was missing):
Line 4 in 1f45892
<TargetFramework>net8.0</TargetFramework> |
Peach validation: Other references work as well. See e.g. the |
It's just a type and I do not know where it is defined. It is highly likely defined either in the project or in the framework. I just wanted to show that symbol references work for the properties in that "normal" C# file: |
@@ -0,0 +1,6 @@ | |||
namespace WebAss; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first chars look strange. Is the encoding set correctly on the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Sorry, Martin, until now I only looked at the general picture which looked good.
I did not a complete review and I've noticed some small improvements. Up to you if you want to takle them or not.
.setMetadata(new FileMetadata(mock(AnalysisWarnings.class)).readMetadata(new FileReader(TEST_FILE))) | ||
.build(); | ||
sensorContext.fileSystem().add(inputFile); | ||
public void test_symbol_refs_get_imported_cases() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pedantic: there is an empty line at the beginning of the tests that is not needed
public void test_symbol_refs_get_imported_overlapSymbolReferences() { | ||
|
||
var inputFile = OverlapSymbolReferencesInputFile; | ||
var sut = new SymbolRefsImporter(sensorContext, s -> Paths.get(s).getFileName().toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var sut = new SymbolRefsImporter(sensorContext, RazorImporterTestBase::fileName);
var sut = new SymbolRefsImporter(sensorContext, RazorImporterTestBase::fileName); | ||
sut.accept(protobuf.toPath()); | ||
sut.save(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating the sut
is duplicated (but slightly different), we should extract a function to create it.
See #8417
The PR turns the hard failure into a log message.