Skip to content
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

Don't lock Cake host object assembly. #1044

Merged

Conversation

bjorkstromm
Copy link
Member

Don't lock Cake host object assembly (Cake.Core) when loading host object type. We'd like to avoid locking file in workspace.

…ject type. This avoids locking file in workspace.

namespace OmniSharp.Services
{
internal class AssemblyLoader : IAssemblyLoader
{
private static readonly ConcurrentDictionary<string, Assembly> AssemblyCache = new ConcurrentDictionary<string, Assembly>(
PlatformHelper.IsWindows ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that OSX is also case-insensitive. Honestly, I'm not sure the platform check is worth it. In general, we usually just compare file paths case-insensitively in OmniSharp -- even on Linux. The number of collisions we've had with this in practice is zero. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll update it to a StringComparer.OrdinalIgnoreCase then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, wan't the cache to cover all methods and not only when loading from byte[]?

{
_logger.LogError(ex, $"Failed to load assembly from path: {assemblyPath}");
}
if (assembly != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: I'd put a line break before to visually separate the if statement from the catch handler.

@@ -77,5 +81,31 @@ public Assembly LoadFrom(string assemblyPath)
_logger.LogTrace($"Assembly loaded from path: {assemblyPath}");
return assembly;
}

public Assembly LoadFrom(string assemblyPath, bool lockAssembly)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the two LoadFrom overloads be merged with lockAssembly becoming an optional parameter? Also, from an API perspective, I'd sort of prefer to see dontLockAssemblyOnDisk since the goal in calling this method is to avoid locking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could merge if you like. And yeah, the naming dontLockAssemblyOnDisk sounds better, with a default to false.

- Rename optional parameter to dontLockAssemblyOnDisk
Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me. @DustinCampbell ?

@filipw filipw added the cake label Dec 12, 2017
@filipw filipw merged commit cb42989 into OmniSharp:master Dec 12, 2017
@bjorkstromm bjorkstromm deleted the feature/load-cake-core-from-bytes branch December 12, 2017 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants