Skip to content

Commit 6e44e4e

Browse files
authored
Fix for missing default settings at startup. (#8172)
* Fix for missing default settings at startup. guard against no context elements on shutdown. A context is created for the project or for each workspace or for each repl. * adding try/catch * use FirstOrDefault * fix race condition where repl context has no InterpreterConfiguration set yet.
1 parent a912e3f commit 6e44e4e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Python/Product/PythonTools/PythonTools/LanguageServerClient/PythonLanguageClient.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,20 +367,30 @@ private async Task NotifyWithParametersAsync(string request, object parameters)
367367
}
368368

369369
private LanguageServerSettings.PythonSettings GetSettings(Uri scopeUri = null) {
370+
// guard on shutdown
371+
if (_clientContexts.Count() == 0) {
372+
return null;
373+
}
370374
IPythonLanguageClientContext context = null;
371375
if (scopeUri == null) {
372-
// REPL context has null RootPath
376+
// REPL context has null RootPath
373377
context = _clientContexts.Find(c => c.RootPath == null);
374378
if (context == null) {
375-
return null;
379+
// use first clientcontext as default
380+
try {
381+
context = _clientContexts.FirstOrDefault();
382+
} catch (InvalidOperationException) {
383+
// no client context
384+
return null;
385+
}
376386
}
377387
} else {
378388
var pathFromScopeUri = CommonUtils.NormalizeDirectoryPath(scopeUri.LocalPath).ToLower().TrimStart('\\');
379389
// Find the matching context for the item, but ignore interactive window where "RootPath" is null.
380390
context = _clientContexts.Find(c => scopeUri != null && c.RootPath != null && PathUtils.IsSamePath(c.RootPath.ToLower(), pathFromScopeUri));
381391
}
382392

383-
if (context == null) {
393+
if (context == null || context.InterpreterConfiguration == null) {
384394
Debug.WriteLine(String.Format("GetSettings() scopeUri not found: {0}", scopeUri));
385395
return null;
386396
}

0 commit comments

Comments
 (0)