You've already forked com.unity.ide.cursor
mirror of
https://github.com/boxqkrtm/com.unity.ide.cursor.git
synced 2026-05-14 22:30:10 +00:00
com.unity.ide.visualstudio@2.0.7
## [2.0.7] - 2021-02-02 Integration: Remove com.unity.nuget.newtonsoft-json dependency in favor of the built-in JsonUtility for the VS Test Runner. ## [2.0.6] - 2021-01-20 Project generation: - Improved language version detection. Integration: - Added support for the VS Test Runner. - Added initial support for displaying asset usage. - Fixed remaining issues with special characters in file/path.
This commit is contained in:
@@ -5,9 +5,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Microsoft.Unity.VisualStudio.Editor.Messaging;
|
||||
using Microsoft.Unity.VisualStudio.Editor.Testing;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using MessageType = Microsoft.Unity.VisualStudio.Editor.Messaging.MessageType;
|
||||
@@ -17,10 +19,18 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
[InitializeOnLoad]
|
||||
internal class VisualStudioIntegration
|
||||
{
|
||||
class Client
|
||||
{
|
||||
public IPEndPoint EndPoint { get; set; }
|
||||
public DateTime LastMessage { get; set; }
|
||||
}
|
||||
|
||||
private static Messager _messager;
|
||||
|
||||
private static readonly Queue<Message> Incoming = new Queue<Message>();
|
||||
private static readonly object IncomingLock = new object();
|
||||
private static readonly Queue<Message> _incoming = new Queue<Message>();
|
||||
private static readonly Dictionary<IPEndPoint, Client> _clients = new Dictionary<IPEndPoint, Client>();
|
||||
private static readonly object _incomingLock = new object();
|
||||
private static readonly object _clientsLock = new object();
|
||||
|
||||
static VisualStudioIntegration()
|
||||
{
|
||||
@@ -90,25 +100,39 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
|
||||
private static void OnUpdate()
|
||||
{
|
||||
lock (IncomingLock)
|
||||
lock (_incomingLock)
|
||||
{
|
||||
while (Incoming.Count > 0)
|
||||
while (_incoming.Count > 0)
|
||||
{
|
||||
ProcessIncoming(Incoming.Dequeue());
|
||||
ProcessIncoming(_incoming.Dequeue());
|
||||
}
|
||||
}
|
||||
|
||||
lock (_clientsLock)
|
||||
{
|
||||
foreach (var client in _clients.Values.ToArray())
|
||||
{
|
||||
if (DateTime.Now.Subtract(client.LastMessage) > TimeSpan.FromMilliseconds(4000))
|
||||
_clients.Remove(client.EndPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddMessage(Message message)
|
||||
{
|
||||
lock (IncomingLock)
|
||||
lock (_incomingLock)
|
||||
{
|
||||
Incoming.Enqueue(message);
|
||||
_incoming.Enqueue(message);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessIncoming(Message message)
|
||||
{
|
||||
lock (_clientsLock)
|
||||
{
|
||||
CheckClient(message);
|
||||
}
|
||||
|
||||
switch (message.Type)
|
||||
{
|
||||
case MessageType.Ping:
|
||||
@@ -142,6 +166,36 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
case MessageType.ProjectPath:
|
||||
Answer(message, MessageType.ProjectPath, Path.GetFullPath(Path.Combine(Application.dataPath, "..")));
|
||||
break;
|
||||
case MessageType.ExecuteTests:
|
||||
TestRunnerApiListener.ExecuteTests(message.Value);
|
||||
break;
|
||||
case MessageType.RetrieveTestList:
|
||||
TestRunnerApiListener.RetrieveTestList(message.Value);
|
||||
break;
|
||||
case MessageType.ShowUsage:
|
||||
UsageUtility.ShowUsage(message.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckClient(Message message)
|
||||
{
|
||||
Client client;
|
||||
var endPoint = message.Origin;
|
||||
|
||||
if (!_clients.TryGetValue(endPoint, out client))
|
||||
{
|
||||
client = new Client
|
||||
{
|
||||
EndPoint = endPoint,
|
||||
LastMessage = DateTime.Now
|
||||
};
|
||||
|
||||
_clients.Add(endPoint, client);
|
||||
}
|
||||
else
|
||||
{
|
||||
client.LastMessage = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +219,11 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
AddMessage(message);
|
||||
}
|
||||
|
||||
private static void Answer(Client client, MessageType answerType, string answerValue)
|
||||
{
|
||||
Answer(client.EndPoint, answerType, answerValue);
|
||||
}
|
||||
|
||||
private static void Answer(Message message, MessageType answerType, string answerValue = "")
|
||||
{
|
||||
var targetEndPoint = message.Origin;
|
||||
@@ -189,5 +248,16 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
_messager.Dispose();
|
||||
_messager = null;
|
||||
}
|
||||
|
||||
internal static void BroadcastMessage(MessageType type, string value)
|
||||
{
|
||||
lock (_clientsLock)
|
||||
{
|
||||
foreach (var client in _clients.Values.ToArray())
|
||||
{
|
||||
Answer(client, type, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user