Skip to content

Commit

Permalink
SLI-1207 Update to OmniSharp-Roslyn 1.39.10 (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
nquinquenel authored Dec 19, 2023
1 parent faf1043 commit e0622fd
Show file tree
Hide file tree
Showing 13 changed files with 357 additions and 397 deletions.
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ stages:
command: 'restore'
projects: $(slnPath)
restoreArguments: '--locked-mode'
feedsToUse: 'select'
vstsFeed: '399fb241-ecc7-4802-8697-dcdd01fbb832/423b576f-2263-43a1-93bd-69f4def19102'
feedsToUse: config
nugetConfigPath: 'omnisharp-dotnet/nuget.config'
includeNuGetOrg: false

- template: prepare-sq-analysis-steps.yml@commonTemplates
Expand Down
8 changes: 4 additions & 4 deletions its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<goal>wget</goal>
</goals>
<configuration>
<url>https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/1.39.6/omnisharp-roslyn-1.39.6-net472.zip</url>
<url>https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/1.39.10/omnisharp-roslyn-1.39.10-net472.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/omnisharp-win</outputDirectory>
</configuration>
Expand All @@ -104,7 +104,7 @@
<goal>wget</goal>
</goals>
<configuration>
<url>https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/1.39.6/omnisharp-roslyn-1.39.6-mono.zip</url>
<url>https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/1.39.10/omnisharp-roslyn-1.39.10-mono.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/omnisharp-mono</outputDirectory>
</configuration>
Expand All @@ -116,7 +116,7 @@
<goal>wget</goal>
</goals>
<configuration>
<url>https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/1.39.6/omnisharp-roslyn-1.39.6-net6.zip</url>
<url>https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/sonarlint/omnisharp/omnisharp-roslyn/1.39.10/omnisharp-roslyn-1.39.10-net6.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/omnisharp-net6</outputDirectory>
</configuration>
Expand Down Expand Up @@ -161,4 +161,4 @@
</profile>
</profiles>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -224,26 +224,40 @@ void analyzeNet7Solution(@TempDir Path tmpDir) throws Exception {
@Test
void analyzeNet8Solution(@TempDir Path tmpDir) throws Exception {
Path baseDir = prepareTestSolutionAndRestore(tmpDir, "DotNet8Project");
ClientInputFile inputFile = prepareInputFile(baseDir, "DotNet8Project/Program.cs", null, false);
ClientInputFile inputFile = prepareInputFile(baseDir, "DotNet8Project/Program.cs",
"namespace DotNet8Project;\n" +
"\n" +
"public static class Class1\n" +
"{\n" +
"\n" +
" public static void Method2()\n" +
" {\n" +
" Method([\"\", \"\"]);\n" +
" }\n" +
" static void Method(string[] list)\n" +
" {\n" +
" ;\n" +
" }\n" +
"}\n",
false);

final List<Issue> issues = new ArrayList<>();
StandaloneAnalysisConfiguration analysisConfiguration = StandaloneAnalysisConfiguration.builder()
.setBaseDir(baseDir)
.addInputFile(inputFile)
.setModuleKey(SOLUTION1_MODULE_KEY)
.putExtraProperty("sonar.cs.internal.useNet8", "true")
.putExtraProperty("sonar.cs.internal.useNet6", "true")
.putExtraProperty("sonar.cs.internal.solutionPath", baseDir.resolve("DotNet8Project.sln").toString())
.build();
sonarlintEngine.analyze(analysisConfiguration, issues::add, null, null);

assertThat(issues)
.extracting(Issue::getRuleKey, Issue::getMessage, Issue::getStartLine, Issue::getStartLineOffset,
Issue::getEndLine, Issue::getEndLineOffset, i -> i.getInputFile().getPath(), Issue::getSeverity)
.extracting(Issue::getRuleKey, Issue::getMessage, Issue::getStartLine, Issue::getStartLineOffset, Issue::getEndLine, Issue::getEndLineOffset, i -> i.getInputFile().getPath(),
Issue::getSeverity)
.containsOnly(
tuple("csharpsquid:S6561", "Avoid using \"DateTime.Now\" for benchmarking or timespan calculation operations.", 17, 22, 17, 42, inputFile.getPath(), MAJOR),
tuple("csharpsquid:S1155", "Use '.Any()' to test whether this 'IEnumerable<string>' is empty or not.", 10, 19, 10, 24, inputFile.getPath(), MINOR),
tuple("csharpsquid:S1656", "Remove or correct this useless self-assignment.", 9, 4, 9, 11, inputFile.getPath(), MAJOR),
tuple("csharpsquid:S3241", "Change return type to 'void'; not a single caller uses the returned value.", 7, 0, 7, 4, inputFile.getPath(), MINOR));
tuple("csharpsquid:S1116", "Remove this empty statement.", 12, 8, 12, 9, inputFile.getPath(), MINOR),
tuple("csharpsquid:S1172", "Remove this unused method parameter 'list'.", 10, 23, 10, 36, inputFile.getPath(), MAJOR)
);
}

@Test
Expand Down
10 changes: 5 additions & 5 deletions its/src/test/projects/DotNet8Project/DotNet8Project.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNet8Project", "DotNet8Project\DotNet8Project.csproj", "{95A8DB40-57A1-4BAA-AEB5-EBF5E3FD6F15}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNet8Project", "DotNet8Project\DotNet8Project.csproj", "{D426AF11-5650-4CEF-BE28-FBABCAFCB4DB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95A8DB40-57A1-4BAA-AEB5-EBF5E3FD6F15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95A8DB40-57A1-4BAA-AEB5-EBF5E3FD6F15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95A8DB40-57A1-4BAA-AEB5-EBF5E3FD6F15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95A8DB40-57A1-4BAA-AEB5-EBF5E3FD6F15}.Release|Any CPU.Build.0 = Release|Any CPU
{D426AF11-5650-4CEF-BE28-FBABCAFCB4DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D426AF11-5650-4CEF-BE28-FBABCAFCB4DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D426AF11-5650-4CEF-BE28-FBABCAFCB4DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D426AF11-5650-4CEF-BE28-FBABCAFCB4DB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
25 changes: 11 additions & 14 deletions its/src/test/projects/DotNet8Project/DotNet8Project/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// simple method
void print()
{
Console.WriteLine("Hello World");
}
namespace DotNet8Project;

bool HasContent(IEnumerable<string> strings)
public static class Class1
{
strings = strings;
return strings.Count() > 0;
}

// non-compliant example
var start = DateTime.Now;
print();
HasContent(new List<string>() { "a", "b" });
Console.WriteLine($"{(DateTime.Now - start).TotalMilliseconds} ms");
public static void Method2()
{
Method(["", ""]);
}
static void Method(string[] list)
{
;
}
}
2 changes: 1 addition & 1 deletion omnisharp-dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<!-- TODO: this version needs to be kept in sync with
1) the version in the POM for the ITs
2) the version in the POM of the SonarLint.IntelliJ repo -->
<OmniSharpVersion>1.39.0</OmniSharpVersion>
<OmniSharpVersion>1.39.10</OmniSharpVersion>

<OmniSharpLocalDownloadDir>$(MSBuildThisFileDirectory).omnisharp\$(OmniSharpVersion)\</OmniSharpLocalDownloadDir>
<OmniSharpUnzippedDir>$(OmniSharpLocalDownloadDir)\unzipped</OmniSharpUnzippedDir>
Expand Down
2 changes: 1 addition & 1 deletion omnisharp-dotnet/nuget.config
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<packageSources>
<clear />
<add key="slvs_input" value="https://sonarsource.pkgs.visualstudio.com/399fb241-ecc7-4802-8697-dcdd01fbb832/_packaging/slvs_input/nuget/v3/index.json" />

<add key="slvs_input2" value="https://sonarsource.pkgs.visualstudio.com/399fb241-ecc7-4802-8697-dcdd01fbb832/_packaging/slvs_input2/nuget/v3/index.json" />
</packageSources>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -51,9 +52,8 @@ internal static class OmniSharpWorkspaceHelper
public static OmniSharpWorkspace CreateOmnisharpWorkspaceWithDocument(string documentFileName, string documentContent)
{
var projectInfo = CreateProjectInfo();
var textLoader = new InMemoryTextLoader();
var textLoader = new InMemoryTextLoader(documentContent);
var documentInfo = CreateDocumentInfo(projectInfo, textLoader, documentFileName);
textLoader.AddText(documentInfo.Id, documentContent);

var workspace = CreateOmniSharpWorkspace();
workspace.AddProject(projectInfo);
Expand Down Expand Up @@ -89,17 +89,16 @@ private static DocumentInfo CreateDocumentInfo(ProjectInfo projectInfo, TextLoad

private class InMemoryTextLoader : TextLoader
{
private readonly Dictionary<DocumentId, string> documentsText = new();

public void AddText(DocumentId documentInfoId, string someText)
private readonly String _sourceText;
public InMemoryTextLoader(String sourceText)
{
documentsText.Add(documentInfoId, someText);
_sourceText = sourceText;
}

public override async Task<TextAndVersion> LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
public override Task<TextAndVersion> LoadTextAndVersionAsync(LoadTextOptions options, CancellationToken token)
{
var text = documentsText[documentId];
return TextAndVersion.Create(SourceText.From(text), VersionStamp.Default);
return Task.FromResult(TextAndVersion.Create(SourceText.From(_sourceText), VersionStamp.Default));
}
}
}
Expand Down
Loading

0 comments on commit e0622fd

Please sign in to comment.