Skip to content

Commit cd2a9d9

Browse files
authored
Make dotnet restore timeout configurable (#31)
1 parent 0b7d9ca commit cd2a9d9

File tree

6 files changed

+32
-26
lines changed

6 files changed

+32
-26
lines changed

ScipDotnet/IndexCommandHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ScipDotnet;
1212
public static class IndexCommandHandler
1313
{
1414
public static async Task<int> Process(IHost host, List<FileInfo> projects, string output, FileInfo workingDirectory,
15-
List<string> include, List<string> exclude, bool allowGlobalSymbolDefinitions)
15+
List<string> include, List<string> exclude, bool allowGlobalSymbolDefinitions, int dotnetRestoreTimeout)
1616
{
1717
var logger = host.Services.GetRequiredService<ILogger<IndexCommandOptions>>();
1818
var matcher = new Matcher();
@@ -33,7 +33,8 @@ public static async Task<int> Process(IHost host, List<FileInfo> projects, strin
3333
projectFiles,
3434
logger,
3535
matcher,
36-
allowGlobalSymbolDefinitions
36+
allowGlobalSymbolDefinitions,
37+
dotnetRestoreTimeout
3738
);
3839
await ScipIndex(host, options);
3940
return 0;

ScipDotnet/IndexCommandOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public record IndexCommandOptions(
99
List<FileInfo> ProjectsFile,
1010
ILogger<IndexCommandOptions> Logger,
1111
Matcher Matcher,
12-
bool AllowGlobalSymbolDefinitions
12+
bool AllowGlobalSymbolDefinitions,
13+
int DotnetRestoreTimeout
1314
);

ScipDotnet/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace ScipDotnet;
1515

1616
public static class Program
1717
{
18+
private const int DotnetRestoreTimeout = 300000;
19+
1820
public static async Task<int> Main(string[] args)
1921
{
2022
var indexCommand = new Command("index", "Index a solution file")
@@ -38,7 +40,9 @@ public static async Task<int> Main(string[] args)
3840
},
3941
new Option<bool>("--allow-global-symbol-definitions", () => false,
4042
"If enabled, allow public symbol definitions to be accessible from other SCIP indexes. " +
41-
"If disabled, then public symbols will only be visible within the index.")
43+
"If disabled, then public symbols will only be visible within the index."),
44+
new Option<int>("--dotnet-restore-timeout", () => DotnetRestoreTimeout,
45+
@"The timeout (in ms) for the ""dotnet restore"" command")
4246
};
4347
indexCommand.Handler = CommandHandler.Create(IndexCommandHandler.Process);
4448
var rootCommand =

ScipDotnet/ScipCSharpSyntaxWalker.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@ public override void VisitStructDeclaration(StructDeclarationSyntax node)
9494
base.VisitStructDeclaration(node);
9595
}
9696

97-
9897
public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
9998
{
10099
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
101100
base.VisitVariableDeclarator(node);
102101
}
103102

104-
105103
public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
106104
{
107105
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);

ScipDotnet/ScipDocumentIndexer.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ private ScipSymbol CreateScipSymbol(ISymbol? sym)
104104
return result;
105105
}
106106

107-
108107
private ScipSymbol CreateLocalScipSymbol(ISymbol sym)
109108
{
110109
var local = _locals.GetValueOrDefault(sym, ScipSymbol.Empty);
@@ -202,19 +201,17 @@ private static string MethodDisambiguator(ISymbol sym)
202201

203202
private readonly string[] _isIgnoredRelationshipSymbol =
204203
{
205-
" System/Object#",
206-
" System/Enum#",
207-
" System/ValueType#",
208-
};
204+
" System/Object#",
205+
" System/Enum#",
206+
" System/ValueType#",
207+
};
209208

210209
// Returns true if this symbol should not be emitted as a SymbolInformation relationship symbol.
211210
// The reason we ignore these symbols is because they appear automatically for a large number of
212211
// symbols putting pressure on our backend to index the inverted index. It's not particularly useful anyways
213212
// to query all the implementations of something like System/Object#.
214-
private bool IsIgnoredRelationshipSymbol(string symbol)
215-
{
216-
return _isIgnoredRelationshipSymbol.Any(symbol.EndsWith);
217-
}
213+
private bool IsIgnoredRelationshipSymbol(string symbol) =>
214+
_isIgnoredRelationshipSymbol.Any(symbol.EndsWith);
218215

219216
public void VisitOccurrence(ISymbol? symbol, Location location, bool isDefinition)
220217
{
@@ -326,7 +323,6 @@ public void VisitOccurrence(ISymbol? symbol, Location location, bool isDefinitio
326323
}
327324
}
328325

329-
330326
// Returns explicitly and implicitly implemented interface methods by the given symbol method.
331327
// The Roslyn API has a `ExplicitInterfaceImplementations` that does not return implicitly implemented
332328
// methods.
@@ -345,22 +341,27 @@ private static IEnumerable<ISymbol> InterfaceImplementations(IMethodSymbol symbo
345341
}
346342
}
347343

348-
349344
// Converts a Roslyn location into a SCIP range.
350345
private static IEnumerable<int> LocationToRange(Location location)
351346
{
352347
var span = location.GetMappedLineSpan();
353348
if (span.StartLinePosition.Line == span.EndLinePosition.Line)
354349
{
355350
return new[]
356-
{ span.StartLinePosition.Line, span.StartLinePosition.Character, span.EndLinePosition.Character };
351+
{
352+
span.StartLinePosition.Line,
353+
span.StartLinePosition.Character,
354+
span.EndLinePosition.Character
355+
};
357356
}
358357

359358
return new[]
360-
{
361-
span.StartLinePosition.Line, span.StartLinePosition.Character, span.EndLinePosition.Line,
362-
span.EndLinePosition.Character
363-
};
359+
{
360+
span.StartLinePosition.Line,
361+
span.StartLinePosition.Character,
362+
span.EndLinePosition.Line,
363+
span.EndLinePosition.Character
364+
};
364365
}
365366

366367
private static bool IsLocalSymbol(ISymbol sym)

ScipDotnet/ScipProjectIndexer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ namespace ScipDotnet;
1313
/// </summary>
1414
public class ScipProjectIndexer
1515
{
16-
private const int DotnetRestoreTimeout = 3000;
17-
1816
public ScipProjectIndexer(ILogger<ScipProjectIndexer> logger) =>
1917
Logger = logger;
2018

2119
private ILogger<ScipProjectIndexer> Logger { get; }
2220

23-
private static void Restore(IndexCommandOptions options, FileInfo project)
21+
private void Restore(IndexCommandOptions options, FileInfo project)
2422
{
2523
var arguments = project.Extension.Equals(".sln") ? $"restore {project.FullName}" : "restore";
2624
var process = new Process()
@@ -34,7 +32,10 @@ private static void Restore(IndexCommandOptions options, FileInfo project)
3432
};
3533
options.Logger.LogInformation("$ dotnet {Arguments}", arguments);
3634
process.Start();
37-
process.WaitForExit(DotnetRestoreTimeout);
35+
if (!process.WaitForExit(options.DotnetRestoreTimeout))
36+
{
37+
Logger.LogWarning("Dotnet restore did not finish in {Time} milliseconds, the results of the indexing might be incorrect.", options.DotnetRestoreTimeout);
38+
}
3839
}
3940

4041
public async IAsyncEnumerable<Scip.Document> IndexDocuments(IHost host, IndexCommandOptions options)

0 commit comments

Comments
 (0)