Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Fix various common exceptions, log on a failed directory load #498

Merged
merged 6 commits into from
Dec 22, 2018
Merged
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
2 changes: 1 addition & 1 deletion src/Analysis/Engine/Impl/Intellisense/AnalysisQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private async Task ConsumerLoop() {
return;
} catch (Exception ex) when (!ex.IsCriticalException()) {
UnhandledException?.Invoke(this, new UnhandledExceptionEventArgs(ex, false));
Dispose();
throw;
}
}
RaiseEventOnThreadPool(AnalysisComplete);
Expand Down
3 changes: 2 additions & 1 deletion src/Analysis/Engine/Impl/Values/BuiltinNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.PythonTools.Analysis.Infrastructure;
using Microsoft.PythonTools.Interpreter;
using Microsoft.PythonTools.Parsing.Ast;
Expand Down Expand Up @@ -101,7 +102,7 @@ public bool TryGetMember(string name, out IAnalysisSet value) {

public virtual ILocatedMember GetLocatedMember() => null;

public override IEnumerable<ILocationInfo> Locations => GetLocatedMember()?.Locations.MaybeEnumerate();
public override IEnumerable<ILocationInfo> Locations => GetLocatedMember()?.Locations ?? Enumerable.Empty<ILocationInfo>();

public override bool Equals(object obj) {
if (obj is BuiltinNamespace<TMemberContainer> bn && GetType() == bn.GetType()) {
Expand Down
6 changes: 3 additions & 3 deletions src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ public override bool IsOfType(IAnalysisSet klass) {
return _original.IsOfType(klass);
}

public override IEnumerable<ILocationInfo> Locations => _original?.Locations.MaybeEnumerate();
public override IEnumerable<ILocationInfo> Locations => _original?.Locations ?? Enumerable.Empty<ILocationInfo>();

public override string Name => _original == null ? base.Name : _original.Name;

public override IEnumerable<OverloadResult> Overloads => _original?.Overloads.MaybeEnumerate();
public override IEnumerable<OverloadResult> Overloads => _original?.Overloads ?? Enumerable.Empty<OverloadResult>();

public override IPythonType PythonType => _original?.PythonType;

internal override IEnumerable<ILocationInfo> References => _original?.References.MaybeEnumerate();
internal override IEnumerable<ILocationInfo> References => _original?.References ?? Enumerable.Empty<ILocationInfo>();

public override PythonMemberType MemberType => _original == null ? PythonMemberType.Unknown : _original.MemberType;

Expand Down
4 changes: 2 additions & 2 deletions src/LanguageServer/Impl/LanguageServer.Lifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public async Task Shutdown() {
// https://microsoft.github.io/language-server-protocol/specification#shutdown
await _server.Shutdown();
_shutdown = true;
_idleTimeTracker.Dispose();
_idleTimeTracker?.Dispose();
}

[JsonRpcMethod("exit")]
public async Task Exit() {
await _server.Exit();
_sessionTokenSource.Cancel();
_idleTimeTracker.Dispose();
_idleTimeTracker?.Dispose();
// Per https://microsoft.github.io/language-server-protocol/specification#exit
Environment.Exit(_shutdown ? 0 : 1);
}
Expand Down
12 changes: 11 additions & 1 deletion src/LanguageServer/Impl/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -168,7 +169,16 @@ public async Task DidChangeConfiguration(JToken token, CancellationToken cancell
await _server.DidChangeConfiguration(new DidChangeConfigurationParams { settings = settings }, cancellationToken);

if (!_filesLoaded) {
await LoadDirectoryFiles();
try {
await LoadDirectoryFiles();
} catch (Exception ex) when (
ex is IOException // FileNotFoundException, DirectoryNotFoundException, PathTooLongException, etc
|| ex is UnauthorizedAccessException
) {
// These exceptions are not caused by the LS, but by invalid/inaccessible user-specified paths.
_server.ShowMessage(MessageType.Error, $"Failed to load files in {_initParams.rootPath} - {ex.GetType().Name}: {ex.Message}");
return;
}
}
_filesLoaded = true;
}
Expand Down