diff options
author | Kirill Osenkov <KirillOsenkov@users.noreply.github.com> | 2018-02-02 02:09:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-02 02:09:35 +0300 |
commit | ec75ef1b5fa28538b264efeffa1f2e3c9d7a9871 (patch) | |
tree | 0068c1fa123fff787de5992d9a69588f1a281824 | |
parent | 82d657798f3873d1fbb9090a062327059544a8b0 (diff) | |
parent | f62c90e7db7dd6086ac007c1f98fdf57f09cd07b (diff) |
Merge branch 'FirstRelease' into Editor15.6.253
5 files changed, 97 insertions, 2 deletions
diff --git a/src/Core/Impl/ContentType/ContentTypeRegistryServiceImpl.cs b/src/Core/Impl/ContentType/ContentTypeRegistryServiceImpl.cs index a5586a2..943c6c3 100644 --- a/src/Core/Impl/ContentType/ContentTypeRegistryServiceImpl.cs +++ b/src/Core/Impl/ContentType/ContentTypeRegistryServiceImpl.cs @@ -30,9 +30,10 @@ namespace Microsoft.VisualStudio.Utilities.Implementation [Export(typeof(IFileExtensionRegistryService))] [Export(typeof(IFileExtensionRegistryService2))] + [Export(typeof(IFilePathRegistryService))] [Export(typeof(IContentTypeRegistryService))] [Export(typeof(IContentTypeRegistryService2))] - internal sealed partial class ContentTypeRegistryImpl : IContentTypeRegistryService2, IFileExtensionRegistryService, IFileExtensionRegistryService2 + internal sealed partial class ContentTypeRegistryImpl : IContentTypeRegistryService2, IFileExtensionRegistryService, IFileExtensionRegistryService2, IFilePathRegistryService { [ImportMany] internal List<Lazy<ContentTypeDefinition, IContentTypeDefinitionMetadata>> ContentTypeDefinitions { get; set; } @@ -43,6 +44,29 @@ namespace Microsoft.VisualStudio.Utilities.Implementation [ImportMany] internal List<Lazy<FileExtensionToContentTypeDefinition, IFileToContentTypeMetadata>> FileToContentTypeProductions { get; set; } + [ImportMany] + private List<Lazy<IFilePathToContentTypeProvider, IFilePathToContentTypeMetadata>> UnorderedFilePathToContentTypeProductions { get; set; } + + private IList<Lazy<IFilePathToContentTypeProvider, IFilePathToContentTypeMetadata>> _orderedFilePathToContentTypeProductions; + internal IList<Lazy<IFilePathToContentTypeProvider, IFilePathToContentTypeMetadata>> OrderedFilePathToContentTypeProductions + { + get + { + if (_orderedFilePathToContentTypeProductions == null) + { + if (UnorderedFilePathToContentTypeProductions != null) + { + _orderedFilePathToContentTypeProductions = Orderer.Order(UnorderedFilePathToContentTypeProductions); + } + else + { + _orderedFilePathToContentTypeProductions = new List<Lazy<IFilePathToContentTypeProvider, IFilePathToContentTypeMetadata>>(); + } + } + return _orderedFilePathToContentTypeProductions; + } + } + private MapCollection maps; /// <summary> @@ -663,6 +687,34 @@ namespace Microsoft.VisualStudio.Utilities.Implementation } #endregion + #region IFilePathRegistryService Members + public IContentType GetContentTypeForPath(string filePath) + { + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + string fileName = Path.GetFileName(filePath); + string extension = Path.GetExtension(filePath); + var providers = OrderedFilePathToContentTypeProductions.Where(md => + (md.Metadata.FileExtension == null || md.Metadata.FileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase)) && + (md.Metadata.FileName == null || md.Metadata.FileName.Equals(fileName, StringComparison.OrdinalIgnoreCase))); + + IContentType contentType = null; + foreach(var curProvider in providers) + { + if (curProvider.Value.TryGetContentTypeForFilePath(filePath, out IContentType curContentType)) + { + contentType = curContentType; + break; + } + } + + return contentType ?? ContentTypeRegistryImpl.UnknownContentTypeImpl; + } + #endregion + private static string RemoveExtensionDot(string extension) { if (extension.StartsWith(".")) diff --git a/src/Core/Impl/ContentType/IFilePathRegistryService.cs b/src/Core/Impl/ContentType/IFilePathRegistryService.cs new file mode 100644 index 0000000..451d95c --- /dev/null +++ b/src/Core/Impl/ContentType/IFilePathRegistryService.cs @@ -0,0 +1,12 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// + +namespace Microsoft.VisualStudio.Utilities +{ + public interface IFilePathRegistryService + { + IContentType GetContentTypeForPath(string filePath); + } +} diff --git a/src/Core/Impl/ContentType/IFilePathToContentTypeMetadata.cs b/src/Core/Impl/ContentType/IFilePathToContentTypeMetadata.cs new file mode 100644 index 0000000..eb15212 --- /dev/null +++ b/src/Core/Impl/ContentType/IFilePathToContentTypeMetadata.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// This file contain implementations details that are subject to change without notice. +// Use at your own risk. +// + +namespace Microsoft.VisualStudio.Utilities.Implementation +{ + public interface IFilePathToContentTypeMetadata : IOrderable + { + [System.ComponentModel.DefaultValue(null)] + string FileExtension { get; } + + [System.ComponentModel.DefaultValue(null)] + string FileName { get; } + } +} diff --git a/src/Core/Impl/ContentType/IFilePathToContentTypeProvider.cs b/src/Core/Impl/ContentType/IFilePathToContentTypeProvider.cs new file mode 100644 index 0000000..a4c624b --- /dev/null +++ b/src/Core/Impl/ContentType/IFilePathToContentTypeProvider.cs @@ -0,0 +1,12 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// + +namespace Microsoft.VisualStudio.Utilities +{ + public interface IFilePathToContentTypeProvider + { + bool TryGetContentTypeForFilePath(string filePath, out IContentType contentType); + } +} diff --git a/src/Microsoft.VisualStudio.Text.Implementation.csproj b/src/Microsoft.VisualStudio.Text.Implementation.csproj index 4c4478e..7e3a87c 100644 --- a/src/Microsoft.VisualStudio.Text.Implementation.csproj +++ b/src/Microsoft.VisualStudio.Text.Implementation.csproj @@ -5,7 +5,7 @@ <SignAssembly>true</SignAssembly> <AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile> <DelaySign>false</DelaySign> - <Version>15.0.8-pre</Version> + <Version>15.0.9-pre</Version> <AssemblyVersion>15.0.0.0</AssemblyVersion> <NuGetVersionEditor>15.6.253-preview</NuGetVersionEditor> </PropertyGroup> |