-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cake support #932
Cake support #932
Changes from 36 commits
a651d6a
d9cd7a6
a1bcaba
054ecf9
3fec513
3635771
ec9af89
e6225ac
c46a223
fa78f27
b4b9b3f
5c6760e
392c2b8
6f66afa
e78d168
063fe25
55b6b27
f207ceb
f616e2e
e7b24c4
3f61d56
7299149
7340b9f
753ebfe
6d99493
a295267
65518ba
cdd109a
e126ff4
54c3bab
e2dd7df
a6194f6
9fecd07
eb02fde
f6afebf
e0cdfa5
50ad596
04825e0
48a2e73
8a59058
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("OmniSharp.Cake.Tests")] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Scripting; | ||
|
||
namespace OmniSharp.Cake | ||
{ | ||
internal class CachingScriptMetadataResolver : MetadataReferenceResolver | ||
{ | ||
private static readonly Dictionary<string, ImmutableArray<PortableExecutableReference>> DirectReferenceCache = new Dictionary<string, ImmutableArray<PortableExecutableReference>>(); | ||
private static readonly Dictionary<string, PortableExecutableReference> MissingReferenceCache = new Dictionary<string, PortableExecutableReference>(); | ||
private static readonly MetadataReferenceResolver DefaultRuntimeResolver = ScriptMetadataResolver.Default; | ||
|
||
public override bool Equals(object other) | ||
{ | ||
return DefaultRuntimeResolver.Equals(other); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return DefaultRuntimeResolver.GetHashCode(); | ||
} | ||
|
||
public override bool ResolveMissingAssemblies => DefaultRuntimeResolver.ResolveMissingAssemblies; | ||
|
||
public override PortableExecutableReference ResolveMissingAssembly(MetadataReference definition, AssemblyIdentity referenceIdentity) | ||
{ | ||
if (MissingReferenceCache.TryGetValue(referenceIdentity.Name, out var result)) | ||
{ | ||
return result; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit: Could this use |
||
|
||
result = DefaultRuntimeResolver.ResolveMissingAssembly(definition, referenceIdentity); | ||
if (result != null) | ||
{ | ||
MissingReferenceCache[referenceIdentity.Name] = result; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public override ImmutableArray<PortableExecutableReference> ResolveReference(string reference, string baseFilePath, MetadataReferenceProperties properties) | ||
{ | ||
var key = $"{reference}-{baseFilePath}"; | ||
if (DirectReferenceCache.TryGetValue(key, out var result)) | ||
{ | ||
return result; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit: Could this use |
||
|
||
result = DefaultRuntimeResolver.ResolveReference(reference, baseFilePath, properties); | ||
if (result.Length > 0) | ||
{ | ||
DirectReferenceCache[key] = result; | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace OmniSharp.Cake | ||
{ | ||
internal class CakeContextModel | ||
{ | ||
public CakeContextModel(string filePath) | ||
{ | ||
Path = filePath; | ||
} | ||
|
||
public string Path { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace OmniSharp.Cake | ||
{ | ||
internal class CakeContextModelCollection | ||
{ | ||
public CakeContextModelCollection(IEnumerable<CakeContextModel> projects) | ||
{ | ||
Projects = projects; | ||
} | ||
|
||
public IEnumerable<CakeContextModel> Projects { get; } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should either of these caches be case-insensitive on the key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno, this was copy-pasted-with-pride from what used to be in OmniSharp.Script. Let’s ask @filipw?