Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ScipDotnet/IndexCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ private static List<FileInfo> FindSolutionOrProjectFile(FileInfo workingDirector
string.Equals(Path.GetExtension(file), ".slnx", StringComparison.OrdinalIgnoreCase) ||
string.Equals(Path.GetExtension(file), ".csproj", StringComparison.OrdinalIgnoreCase) ||
string.Equals(Path.GetExtension(file), ".vbproj", StringComparison.OrdinalIgnoreCase)
).ToList();
)
// Solutions (.sln/.slnx) before project files, each in name order. Directory.GetFiles returns
// the order of the file system, and a project file must come after the solution that loads it.
.OrderBy(file => Path.GetExtension(file).StartsWith(".sln", StringComparison.OrdinalIgnoreCase) ? 0 : 1)
.ThenBy(file => file, StringComparer.Ordinal)
.ToList();

if (paths.Count != 0)
{
Expand Down
30 changes: 19 additions & 11 deletions ScipDotnet/ScipProjectIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,29 @@ private void Restore(IndexCommandOptions options, FileInfo project)
FileInfo rootProject,
HashSet<ProjectId> indexedProjects)
{
if (!options.SkipDotnetRestore)
{
Restore(options, rootProject);
}

var workspace = host.Services.GetRequiredService<MSBuildWorkspace>();
var isProjectFile = string.Equals(rootProject.Extension, ".csproj", StringComparison.OrdinalIgnoreCase)
|| string.Equals(rootProject.Extension, ".vbproj", StringComparison.OrdinalIgnoreCase);
var projects = (isProjectFile
? new[]

// A solution in the same directory may have loaded this project file already. Opening it a second time
// throws "'<name>' is already part of the workspace", so the loaded project is used instead, and
// indexedProjects skips it because the solution indexed it.
var projects = isProjectFile
? workspace.CurrentSolution.Projects
.Where(project => string.Equals(project.FilePath, rootProject.FullName, StringComparison.OrdinalIgnoreCase))
.ToList()
: new List<Project>();
if (projects.Count == 0)
{
if (!options.SkipDotnetRestore)
{
await host.Services.GetRequiredService<MSBuildWorkspace>()
.OpenProjectAsync(rootProject.FullName)
Restore(options, rootProject);
}
: (await host.Services.GetRequiredService<MSBuildWorkspace>()
.OpenSolutionAsync(rootProject.FullName)).Projects).ToList();

projects = (isProjectFile
? new[] { await workspace.OpenProjectAsync(rootProject.FullName) }
: (await workspace.OpenSolutionAsync(rootProject.FullName)).Projects).ToList();
}


options.Logger.LogDebug($"Found {projects.Count()} projects");
Expand Down
7 changes: 6 additions & 1 deletion ScipDotnet/ScipVisualBasicSyntaxWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public override void VisitEnumStatement(EnumStatementSyntax node)

public override void VisitCatchStatement(CatchStatementSyntax node)
{
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.IdentifierName.Identifier.GetLocation(), true);
// `Catch` and `Catch When condition` declare no exception variable, so IdentifierName is null.
if (node.IdentifierName != null)
{
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.IdentifierName.Identifier.GetLocation(), true);
}

base.VisitCatchStatement(node);
}

Expand Down
9 changes: 9 additions & 0 deletions snapshots/input/project-beside-solution/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ProjectBesideSolution;

public static class Program
{
public static void Main()
{
Console.WriteLine("Hello, World!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
22 changes: 22 additions & 0 deletions snapshots/input/project-beside-solution/ProjectBesideSolution.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectBesideSolution", "ProjectBesideSolution.csproj", "{96877E88-1D0A-45D0-9C35-E5A0B07783A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{96877E88-1D0A-45D0-9C35-E5A0B07783A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96877E88-1D0A-45D0-9C35-E5A0B07783A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96877E88-1D0A-45D0-9C35-E5A0B07783A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96877E88-1D0A-45D0-9C35-E5A0B07783A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions snapshots/input/syntax/VBMain/Statements.vb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ Namespace VBMain
End Try
End Sub

Private Sub TryWithoutExceptionVariable(fileName As String)
Try
File.ReadLines(fileName)
Catch When fileName.Length = 0
Console.WriteLine("empty file name")
Catch
Console.WriteLine("failed")
End Try
End Sub

Private Function [Default]() As (A As String, B As Boolean)
Dim C As (A As String, B As Boolean) = ("42", 42)
Return C
Expand Down
16 changes: 16 additions & 0 deletions snapshots/output-net10.0/project-beside-solution/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ProjectBesideSolution;
// ^^^^^^^^^^^^^^^^^^^^^ reference scip-dotnet nuget . . ProjectBesideSolution/

public static class Program
// ^^^^^^^ definition scip-dotnet nuget . . ProjectBesideSolution/Program#
// documentation ```cs\nclass Program\n```
{
public static void Main()
// ^^^^ definition scip-dotnet nuget . . ProjectBesideSolution/Program#Main().
// documentation ```cs\npublic static void Program.Main()\n```
{
Console.WriteLine("Hello, World!");
// ^^^^^^^ reference scip-dotnet nuget System.Console 10.0.0.0 System/Console#
// ^^^^^^^^^ reference scip-dotnet nuget System.Console 10.0.0.0 System/Console#WriteLine(+11).
}
}
23 changes: 23 additions & 0 deletions snapshots/output-net10.0/syntax/VBMain/Statements.vb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@
End Try
End Sub

Private Sub TryWithoutExceptionVariable(fileName As String)
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().
' documentation ```vb\nPrivate Sub Statements.TryWithoutExceptionVariable(fileName As String)\n```
' ^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
' documentation ```vb\nfileName As String\n```
Try
File.ReadLines(fileName)
' ^^^^ reference scip-dotnet nuget System.Runtime 10.0.0.0 IO/File#
' ^^^^^^^^^ reference scip-dotnet nuget System.Runtime 10.0.0.0 IO/File#ReadLines().
' ^^^^^^^^ reference scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
Catch When fileName.Length = 0
' ^^^^^^^^ reference scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
' ^^^^^^ reference scip-dotnet nuget System.Runtime 10.0.0.0 System/String#Length.
Console.WriteLine("empty file name")
' ^^^^^^^ reference scip-dotnet nuget System.Console 10.0.0.0 System/Console#
' ^^^^^^^^^ reference scip-dotnet nuget System.Console 10.0.0.0 System/Console#WriteLine(+11).
Catch
Console.WriteLine("failed")
' ^^^^^^^ reference scip-dotnet nuget System.Console 10.0.0.0 System/Console#
' ^^^^^^^^^ reference scip-dotnet nuget System.Console 10.0.0.0 System/Console#WriteLine(+11).
End Try
End Sub

Private Function [Default]() As (A As String, B As Boolean)
' ^^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#Default().
' documentation ```vb\nPrivate Function Statements.Default() As (A As String, B As Boolean)\n```
Expand Down
16 changes: 16 additions & 0 deletions snapshots/output-net8.0/project-beside-solution/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ProjectBesideSolution;
// ^^^^^^^^^^^^^^^^^^^^^ reference scip-dotnet nuget . . ProjectBesideSolution/

public static class Program
// ^^^^^^^ definition scip-dotnet nuget . . ProjectBesideSolution/Program#
// documentation ```cs\nclass Program\n```
{
public static void Main()
// ^^^^ definition scip-dotnet nuget . . ProjectBesideSolution/Program#Main().
// documentation ```cs\npublic static void Program.Main()\n```
{
Console.WriteLine("Hello, World!");
// ^^^^^^^ reference scip-dotnet nuget System.Console 8.0.0.0 System/Console#
// ^^^^^^^^^ reference scip-dotnet nuget System.Console 8.0.0.0 System/Console#WriteLine(+11).
}
}
23 changes: 23 additions & 0 deletions snapshots/output-net8.0/syntax/VBMain/Statements.vb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@
End Try
End Sub

Private Sub TryWithoutExceptionVariable(fileName As String)
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().
' documentation ```vb\nPrivate Sub Statements.TryWithoutExceptionVariable(fileName As String)\n```
' ^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
' documentation ```vb\nfileName As String\n```
Try
File.ReadLines(fileName)
' ^^^^ reference scip-dotnet nuget System.Runtime 8.0.0.0 IO/File#
' ^^^^^^^^^ reference scip-dotnet nuget System.Runtime 8.0.0.0 IO/File#ReadLines().
' ^^^^^^^^ reference scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
Catch When fileName.Length = 0
' ^^^^^^^^ reference scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
' ^^^^^^ reference scip-dotnet nuget System.Runtime 8.0.0.0 System/String#Length.
Console.WriteLine("empty file name")
' ^^^^^^^ reference scip-dotnet nuget System.Console 8.0.0.0 System/Console#
' ^^^^^^^^^ reference scip-dotnet nuget System.Console 8.0.0.0 System/Console#WriteLine(+11).
Catch
Console.WriteLine("failed")
' ^^^^^^^ reference scip-dotnet nuget System.Console 8.0.0.0 System/Console#
' ^^^^^^^^^ reference scip-dotnet nuget System.Console 8.0.0.0 System/Console#WriteLine(+11).
End Try
End Sub

Private Function [Default]() As (A As String, B As Boolean)
' ^^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#Default().
' documentation ```vb\nPrivate Function Statements.Default() As (A As String, B As Boolean)\n```
Expand Down
16 changes: 16 additions & 0 deletions snapshots/output-net9.0/project-beside-solution/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ProjectBesideSolution;
// ^^^^^^^^^^^^^^^^^^^^^ reference scip-dotnet nuget . . ProjectBesideSolution/

public static class Program
// ^^^^^^^ definition scip-dotnet nuget . . ProjectBesideSolution/Program#
// documentation ```cs\nclass Program\n```
{
public static void Main()
// ^^^^ definition scip-dotnet nuget . . ProjectBesideSolution/Program#Main().
// documentation ```cs\npublic static void Program.Main()\n```
{
Console.WriteLine("Hello, World!");
// ^^^^^^^ reference scip-dotnet nuget System.Console 9.0.0.0 System/Console#
// ^^^^^^^^^ reference scip-dotnet nuget System.Console 9.0.0.0 System/Console#WriteLine(+11).
}
}
23 changes: 23 additions & 0 deletions snapshots/output-net9.0/syntax/VBMain/Statements.vb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@
End Try
End Sub

Private Sub TryWithoutExceptionVariable(fileName As String)
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().
' documentation ```vb\nPrivate Sub Statements.TryWithoutExceptionVariable(fileName As String)\n```
' ^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
' documentation ```vb\nfileName As String\n```
Try
File.ReadLines(fileName)
' ^^^^ reference scip-dotnet nuget System.Runtime 9.0.0.0 IO/File#
' ^^^^^^^^^ reference scip-dotnet nuget System.Runtime 9.0.0.0 IO/File#ReadLines().
' ^^^^^^^^ reference scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
Catch When fileName.Length = 0
' ^^^^^^^^ reference scip-dotnet nuget . . VBMain/Statements#TryWithoutExceptionVariable().(fileName)
' ^^^^^^ reference scip-dotnet nuget System.Runtime 9.0.0.0 System/String#Length.
Console.WriteLine("empty file name")
' ^^^^^^^ reference scip-dotnet nuget System.Console 9.0.0.0 System/Console#
' ^^^^^^^^^ reference scip-dotnet nuget System.Console 9.0.0.0 System/Console#WriteLine(+11).
Catch
Console.WriteLine("failed")
' ^^^^^^^ reference scip-dotnet nuget System.Console 9.0.0.0 System/Console#
' ^^^^^^^^^ reference scip-dotnet nuget System.Console 9.0.0.0 System/Console#WriteLine(+11).
End Try
End Sub

Private Function [Default]() As (A As String, B As Boolean)
' ^^^^^^^^^ definition scip-dotnet nuget . . VBMain/Statements#Default().
' documentation ```vb\nPrivate Function Statements.Default() As (A As String, B As Boolean)\n```
Expand Down