Skip to content

Commit

Permalink
Merge pull request microsoft#2281 from zooba/issue-1953
Browse files Browse the repository at this point in the history
Fixes microsoft#1953 Tests are not shown on VS 2017
  • Loading branch information
zooba authored Mar 15, 2017
2 parents aa43f18 + 5d1a970 commit ad6cfd3
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 179 deletions.
57 changes: 0 additions & 57 deletions Common/Product/SharedProject/VsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,14 @@

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudioTools.Project;
using Microsoft.VisualStudioTools.Project.Automation;
using VsShellUtil = Microsoft.VisualStudio.Shell.VsShellUtilities;

namespace Microsoft.VisualStudioTools {
static class VsExtensions {
#if FALSE
internal static ITrackingSpan CreateTrackingSpan(this IIntellisenseSession session, ITextBuffer buffer) {
var triggerPoint = session.GetTriggerPoint(buffer);
var position = session.GetTriggerPoint(buffer).GetPosition(session.TextView.TextSnapshot);

var snapshot = buffer.CurrentSnapshot;
if (position == snapshot.Length) {
return snapshot.CreateTrackingSpan(position, 0, SpanTrackingMode.EdgeInclusive);
} else {
return snapshot.CreateTrackingSpan(position, 1, SpanTrackingMode.EdgeInclusive);
}
}
#endif
internal static EnvDTE.Project GetProject(this IVsHierarchy hierarchy) {
object project;

Expand Down Expand Up @@ -87,47 +71,6 @@ internal static IClipboardService GetClipboardService(this IServiceProvider serv
return (IClipboardService)serviceProvider.GetService(typeof(IClipboardService));
}

internal static UIThreadBase GetUIThread(this IServiceProvider serviceProvider) {
var uiThread = (UIThreadBase)serviceProvider.GetService(typeof(UIThreadBase));
if (uiThread == null) {
Trace.TraceWarning("Returning NoOpUIThread instance from GetUIThread");
#if DEBUG
var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
object shutdownStarted;
if (shell != null &&
ErrorHandler.Succeeded(shell.GetProperty((int)__VSSPROPID6.VSSPROPID_ShutdownStarted, out shutdownStarted)) &&
!(bool)shutdownStarted) {
Debug.Fail("No UIThread service but shell is not shutting down");
}
#endif
return new NoOpUIThread();
}
return uiThread;
}

[Conditional("DEBUG")]
// Available on serviceProvider so we can avoid the GetUIThread call on release builds
public static void MustBeCalledFromUIThread(this IServiceProvider serviceProvider, string message = "Invalid cross-thread call") {
serviceProvider.GetUIThread().MustBeCalledFromUIThread(message);
}

[Conditional("DEBUG")]
// Available on serviceProvider so we can avoid the GetUIThread call on release builds
public static void MustNotBeCalledFromUIThread(this IServiceProvider serviceProvider, string message = "Invalid cross-thread call") {
serviceProvider.GetUIThread().MustNotBeCalledFromUIThread(message);
}

[Conditional("DEBUG")]
public static void MustBeCalledFromUIThread(this UIThreadBase self, string message = "Invalid cross-thread call") {
Debug.Assert(self is MockUIThreadBase || !self.InvokeRequired, message);
}

[Conditional("DEBUG")]
public static void MustNotBeCalledFromUIThread(this UIThreadBase self, string message = "Invalid cross-thread call") {
Debug.Assert(self is MockUIThreadBase || self.InvokeRequired, message);
}


/// <summary>
/// Use the line ending of the first line for the line endings.
/// If we have no line endings (single line file) just use Environment.NewLine
Expand Down
10 changes: 1 addition & 9 deletions Python/Product/Analysis/Projects/IPythonProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.PythonTools.Projects {
/// <summary>
/// Provides access to an abstract Python project.
/// </summary>
public interface IPythonProjectProvider {
PythonProject Project {
get;
}
PythonProject Project { get; }
}
}
8 changes: 8 additions & 0 deletions Python/Product/Analysis/Projects/PythonProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,13 @@ public abstract ProjectAnalyzer Analyzer {
public abstract string ProjectHome { get; }

public abstract LaunchConfiguration GetLaunchConfigurationOrThrow();

/// <summary>
/// Attempts to retrieve a PythonProject from the provided object, which
/// should implement <see cref="IPythonProjectProvider"/>.
/// </summary>
public static PythonProject FromObject(object source) {
return (source as IPythonProjectProvider)?.Project;
}
}
}
16 changes: 12 additions & 4 deletions Python/Product/Ipc.Json/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public sealed class Connection : IDisposable {
private readonly Func<RequestArgs, Func<Response, Task>, Task> _requestHandler;
private readonly Stream _writer, _reader;
private readonly TextWriter _logFile;
private readonly object _logFileLock;
private int _seq;
private static char[] _headerSeparator = new[] { ':' };

Expand Down Expand Up @@ -65,6 +66,11 @@ public Connection(
_writer = writer;
_reader = reader;
_logFile = OpenLogFile(connectionLogKey);
// FxCop won't let us lock a MarshalByRefObject, so we create
// a plain old object that we can log against.
if (_logFile != null) {
_logFileLock = new object();
}
}

/// <summary>
Expand Down Expand Up @@ -113,19 +119,21 @@ private static TextWriter OpenLogFile(string connectionLogKey) {
}

private void LogToDisk(string message) {
if (_logFile == null) {
if (_logFile == null || _logFileLock == null) {
return;
}
try {
_logFile.WriteLine(message);
_logFile.Flush();
lock (_logFileLock) {
_logFile.WriteLine(message);
_logFile.Flush();
}
} catch (IOException) {
} catch (ObjectDisposedException) {
}
}

private void LogToDisk(Exception ex) {
if (_logFile == null) {
if (_logFile == null || _logFileLock == null) {
return;
}
// Should have immediately logged a message before, so the exception
Expand Down
39 changes: 0 additions & 39 deletions Python/Product/PythonTools/PythonTools/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,37 +189,6 @@ internal static ITrackingSpan GetApplicableSpan(this ITextSnapshot snapshot, int
return null;
}

internal static ITrackingSpan CreateTrackingSpan(this IQuickInfoSession session, ITextBuffer buffer) {
var triggerPoint = session.GetTriggerPoint(buffer);
var position = triggerPoint.GetPosition(buffer.CurrentSnapshot);
if (position == buffer.CurrentSnapshot.Length) {
return ((IIntellisenseSession)session).GetApplicableSpan(buffer);
}

return buffer.CurrentSnapshot.CreateTrackingSpan(position, 1, SpanTrackingMode.EdgeInclusive);
}

#pragma warning disable 0618

// TODO: Switch from smart tags to Light Bulb: http://go.microsoft.com/fwlink/?LinkId=394601
internal static ITrackingSpan CreateTrackingSpan(this ISmartTagSession session, ITextBuffer buffer) {
var triggerPoint = session.GetTriggerPoint(buffer);
var position = triggerPoint.GetPosition(buffer.CurrentSnapshot);
if (position == buffer.CurrentSnapshot.Length) {
return ((IIntellisenseSession)session).GetApplicableSpan(buffer);
}

var triggerChar = triggerPoint.GetCharacter(buffer.CurrentSnapshot);
if (position != 0 && !char.IsLetterOrDigit(triggerChar)) {
// end of line, back up one char as we may have an identifier
return buffer.CurrentSnapshot.CreateTrackingSpan(position - 1, 1, SpanTrackingMode.EdgeInclusive);
}

return buffer.CurrentSnapshot.CreateTrackingSpan(position, 1, SpanTrackingMode.EdgeInclusive);
}

#pragma warning restore 0618

public static IPythonInterpreterFactory GetPythonInterpreterFactory(this IVsHierarchy self) {
var node = (self.GetProject().GetCommonProject() as PythonProjectNode);
if (node != null) {
Expand Down Expand Up @@ -251,14 +220,6 @@ internal static IEnumerable<PythonProjectNode> EnumerateLoadedPythonProjects(thi
.Where(p => p != null);
}

public static IPythonProject AsPythonProject(this IVsProject project) {
return ((IVsHierarchy)project).GetProject().GetCommonProject() as PythonProjectNode;
}

public static IPythonProject AsPythonProject(this EnvDTE.Project project) {
return project.GetCommonProject() as PythonProjectNode;
}


internal static PythonProjectNode GetPythonProject(this IVsProject project) {
return ((IVsHierarchy)project).GetProject().GetCommonProject() as PythonProjectNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ Action<BufferParser> onGet
bpt = _bufferParserTask;
if (cbpt == null) {
_createBufferParserTask = tcs = new TaskCompletionSource<BufferParser>();
if (bpt == null) {
_bufferParserTask = tcs;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,22 @@ internal bool IsOldSnapshot(int bufferId, int version) {

internal ITextSnapshot GetLastSentSnapshot(ITextBuffer buffer) {
lock (this) {
return _bufferInfo[buffer].LastSentSnapshot;
BufferInfo bi;
if (buffer != null && _bufferInfo.TryGetValue(buffer, out bi) && bi != null) {
return bi.LastSentSnapshot;
}
return null;
}
}

internal void SetLastSentSnapshot(ITextSnapshot snapshot) {
lock (this) {
_bufferInfo[snapshot.TextBuffer].LastSentSnapshot = snapshot;
BufferInfo bi;
if (snapshot != null && _bufferInfo.TryGetValue(snapshot.TextBuffer, out bi) && bi != null) {
bi.LastSentSnapshot = snapshot;
} else {
Debug.Fail("Unknown snapshot");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,24 @@ private void ConnectionEventReceived(object sender, EventReceivedEventArgs e) {
}
}

private async void OnAnalysisComplete(EventReceivedEventArgs e) {
private void OnAnalysisComplete(EventReceivedEventArgs e) {
var analysisComplete = (AP.FileAnalysisCompleteEvent)e.Event;
AnalysisEntry entry;
if (_projectFilesById.TryGetValue(analysisComplete.fileId, out entry)) {
try {
var bufferParser = await entry.GetBufferParserAsync();
// Notify buffer parsers without blocking this handler
entry.GetBufferParserAsync().ContinueWith(t => {
if (t.IsCanceled) {
// Silence if we cancelled, else the wait below
// will re-raise any exceptions for us.
return;
}

var bp = t.WaitAndUnwrapExceptions();

foreach (var version in analysisComplete.versions) {
bufferParser.Analyzed(version.bufferId, version.version);
bp.Analyzed(version.bufferId, version.version);
}
} catch (OperationCanceledException) {
}
}).HandleAllExceptions(_serviceProvider, GetType()).DoNotWait();

entry.OnAnalysisComplete();
AnalysisComplete?.Invoke(this, new AnalysisCompleteEventArgs(entry.Path));
Expand Down
Loading

0 comments on commit ad6cfd3

Please sign in to comment.