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@1.0.9
## [1.0.9] - 2019-03-05 Updated MonoDevelop support, to pass correct arguments, and not import VSTU plugin Use release build of COMIntegration for Visual Studio ## [1.0.7] - 2019-04-30 Ensure asset database is refreshed when generating csproj and solution files. ## [1.0.6] - 2019-04-27 Add support for generating all csproj files. ## [1.0.5] - 2019-04-18 Fix relative package paths. Fix opening editor on mac.
This commit is contained in:
@@ -22,6 +22,7 @@ namespace VisualStudioEditor
|
||||
bool HasSolutionBeenGenerated();
|
||||
string SolutionFile();
|
||||
string ProjectDirectory { get; }
|
||||
void GenerateAll(bool generateAll);
|
||||
}
|
||||
|
||||
public interface IAssemblyNameProvider
|
||||
@@ -29,6 +30,12 @@ namespace VisualStudioEditor
|
||||
string GetAssemblyNameFromScriptPath(string path);
|
||||
IEnumerable<Assembly> GetAllAssemblies(Func<string, bool> shouldFileBePartOfSolution);
|
||||
IEnumerable<string> GetAllAssetPaths();
|
||||
UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath);
|
||||
}
|
||||
|
||||
public struct TestSettings {
|
||||
public bool ShouldSync;
|
||||
public Dictionary<string, string> SyncPath;
|
||||
}
|
||||
|
||||
class AssemblyNameProvider : IAssemblyNameProvider
|
||||
@@ -47,6 +54,11 @@ namespace VisualStudioEditor
|
||||
{
|
||||
return AssetDatabase.GetAllAssetPaths();
|
||||
}
|
||||
|
||||
public UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath)
|
||||
{
|
||||
return UnityEditor.PackageManager.PackageInfo.FindForAssetPath(assetPath);
|
||||
}
|
||||
}
|
||||
|
||||
public class ProjectGeneration : IGenerator
|
||||
@@ -94,26 +106,32 @@ namespace VisualStudioEditor
|
||||
|
||||
string[] m_ProjectSupportedExtensions = new string[0];
|
||||
public string ProjectDirectory { get; }
|
||||
|
||||
public TestSettings Settings { get; set; }
|
||||
|
||||
readonly string m_ProjectName;
|
||||
readonly IAssemblyNameProvider m_AssemblyNameProvider;
|
||||
bool m_ShouldGenerateAll;
|
||||
|
||||
public ProjectGeneration()
|
||||
public ProjectGeneration() : this(Directory.GetParent(Application.dataPath).FullName, new AssemblyNameProvider())
|
||||
{
|
||||
var projectDirectory = Directory.GetParent(Application.dataPath).FullName;
|
||||
ProjectDirectory = projectDirectory.Replace('\\', '/');
|
||||
m_ProjectName = Path.GetFileName(ProjectDirectory);
|
||||
m_AssemblyNameProvider = new AssemblyNameProvider();
|
||||
}
|
||||
|
||||
public ProjectGeneration(string tempDirectory) : this(tempDirectory, new AssemblyNameProvider()) {
|
||||
}
|
||||
|
||||
public ProjectGeneration(string tempDirectory, IAssemblyNameProvider assemblyNameProvider) {
|
||||
Settings = new TestSettings { ShouldSync = true };
|
||||
ProjectDirectory = tempDirectory.Replace('\\', '/');
|
||||
m_ProjectName = Path.GetFileName(ProjectDirectory);
|
||||
m_AssemblyNameProvider = assemblyNameProvider;
|
||||
}
|
||||
|
||||
public void GenerateAll(bool generateAll)
|
||||
{
|
||||
m_ShouldGenerateAll = generateAll;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Syncs the scripting solution if any affected files are relevant.
|
||||
/// </summary>
|
||||
@@ -176,7 +194,7 @@ namespace VisualStudioEditor
|
||||
string extension = Path.GetExtension(file);
|
||||
|
||||
// Exclude files coming from packages except if they are internalized.
|
||||
if (IsInternalizedPackagePath(file))
|
||||
if (!m_ShouldGenerateAll && IsInternalizedPackagePath(file))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -296,7 +314,7 @@ namespace VisualStudioEditor
|
||||
foreach (string asset in m_AssemblyNameProvider.GetAllAssetPaths())
|
||||
{
|
||||
// Exclude files coming from packages except if they are internalized.
|
||||
if (IsInternalizedPackagePath(asset))
|
||||
if (!m_ShouldGenerateAll && IsInternalizedPackagePath(asset))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -306,8 +324,6 @@ namespace VisualStudioEditor
|
||||
{
|
||||
// Find assembly the asset belongs to by adding script extension and using compilation pipeline.
|
||||
var assemblyName = m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset + ".cs");
|
||||
assemblyName = assemblyName ?? m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset + ".js");
|
||||
assemblyName = assemblyName ?? m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset + ".boo");
|
||||
|
||||
if (string.IsNullOrEmpty(assemblyName))
|
||||
{
|
||||
@@ -334,14 +350,14 @@ namespace VisualStudioEditor
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool IsInternalizedPackagePath(string file)
|
||||
bool IsInternalizedPackagePath(string file)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(file))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(file);
|
||||
var packageInfo = m_AssemblyNameProvider.FindForAssetPath(file);
|
||||
if (packageInfo == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -358,7 +374,7 @@ namespace VisualStudioEditor
|
||||
SyncProjectFileIfNotChanged(ProjectFile(island), ProjectText(island, allAssetsProjectParts, responseFilesData, allProjectIslands));
|
||||
}
|
||||
|
||||
static void SyncProjectFileIfNotChanged(string path, string newContents)
|
||||
void SyncProjectFileIfNotChanged(string path, string newContents)
|
||||
{
|
||||
if (Path.GetExtension(path) == ".csproj")
|
||||
{
|
||||
@@ -368,7 +384,7 @@ namespace VisualStudioEditor
|
||||
SyncFileIfNotChanged(path, newContents);
|
||||
}
|
||||
|
||||
static void SyncSolutionFileIfNotChanged(string path, string newContents)
|
||||
void SyncSolutionFileIfNotChanged(string path, string newContents)
|
||||
{
|
||||
newContents = OnGeneratedSlnSolution(path, newContents);
|
||||
|
||||
@@ -455,7 +471,7 @@ namespace VisualStudioEditor
|
||||
return content;
|
||||
}
|
||||
|
||||
static void SyncFileIfNotChanged(string filename, string newContents)
|
||||
void SyncFileIfNotChanged(string filename, string newContents)
|
||||
{
|
||||
if (File.Exists(filename) &&
|
||||
newContents == File.ReadAllText(filename))
|
||||
@@ -463,7 +479,16 @@ namespace VisualStudioEditor
|
||||
return;
|
||||
}
|
||||
|
||||
File.WriteAllText(filename, newContents, Encoding.UTF8);
|
||||
if (Settings.ShouldSync)
|
||||
{
|
||||
File.WriteAllText(filename, newContents, Encoding.UTF8);
|
||||
}
|
||||
else
|
||||
{
|
||||
var utf8 = Encoding.UTF8;
|
||||
byte[] utfBytes = utf8.GetBytes(newContents);
|
||||
Settings.SyncPath[filename] = utf8.GetString(utfBytes, 0, utfBytes.Length);
|
||||
}
|
||||
}
|
||||
|
||||
string ProjectText(Assembly assembly,
|
||||
@@ -779,7 +804,7 @@ namespace VisualStudioEditor
|
||||
file = file.Replace('/', '\\');
|
||||
var path = SkipPathPrefix(file, projectDir);
|
||||
|
||||
var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(path.Replace('\\', '/'));
|
||||
var packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.Replace('\\', '/'));
|
||||
if (packageInfo != null) {
|
||||
// We have to normalize the path, because the PackageManagerRemapper assumes
|
||||
// dir seperators will be os specific.
|
||||
@@ -792,7 +817,7 @@ namespace VisualStudioEditor
|
||||
|
||||
static string SkipPathPrefix(string path, string prefix)
|
||||
{
|
||||
if (path.StartsWith(prefix))
|
||||
if (path.Replace("\\","/").StartsWith($"{prefix}/"))
|
||||
return path.Substring(prefix.Length + 1);
|
||||
return path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user