diff options
author | Mikayla Hutchinson <m.j.hutchinson@gmail.com> | 2019-01-19 13:32:42 +0300 |
---|---|---|
committer | Mikayla Hutchinson <m.j.hutchinson@gmail.com> | 2019-01-19 13:36:06 +0300 |
commit | 7d99dbf29f04d037c9877d53928ae2b8816759eb (patch) | |
tree | f76977984135fd61e7b7bde462358caadb9acd75 /main/src/core/MonoDevelop.Ide | |
parent | fd97c718944fd978b5526a4708705dc47b107657 (diff) |
Replace IMimeToContentTypeRegistryService usage with MimeTypeCatalog
Diffstat (limited to 'main/src/core/MonoDevelop.Ide')
4 files changed, 36 insertions, 167 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/PlatformCatalog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/PlatformCatalog.cs index 80b307cd7b..c4b938643d 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/PlatformCatalog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/PlatformCatalog.cs @@ -30,7 +30,8 @@ using Microsoft.VisualStudio.Utilities; namespace Microsoft.VisualStudio.Platform
{
[Export]
- public class PlatformCatalog
+ // TODO: editor obsolete
+ internal class PlatformCatalog
{
static PlatformCatalog instance;
public static PlatformCatalog Instance {
@@ -52,9 +53,6 @@ namespace Microsoft.VisualStudio.Platform internal ITextDocumentFactoryService TextDocumentFactoryService { get; private set; }
[Import]
- internal IMimeToContentTypeRegistryService MimeToContentTypeRegistryService { get; private set; }
-
- [Import]
internal IContentTypeRegistryService ContentTypeRegistryService { get; private set; }
[Import]
@@ -67,82 +65,9 @@ namespace Microsoft.VisualStudio.Platform internal IViewClassifierAggregatorService ViewClassifierAggregatorService { get; private set; }
}
- public interface IMimeToContentTypeRegistryService
- {
- string GetMimeType(IContentType type);
- IContentType GetContentType(string type);
-
- void LinkTypes(string mimeType, IContentType contentType);
- }
-
- [Export(typeof(IMimeToContentTypeRegistryService))]
- public class MimeToContentTypeRegistryService : IMimeToContentTypeRegistryService, IPartImportsSatisfiedNotification
- {
- [Import]
- IContentTypeRegistryService ContentTypeRegistryService { get; set; }
-
- [Export]
- [Name ("csharp")]
- [BaseDefinition ("code")]
- public ContentTypeDefinition codeContentType;
-
- public string GetMimeType(IContentType type)
- {
- string mimeType;
- if (this.maps.Item2.TryGetValue(type, out mimeType))
- {
- return mimeType;
- }
-
- return (ContentTypeRegistryService as IContentTypeRegistryService2).GetMimeType (type);
- }
-
- public IContentType GetContentType(string type)
- {
- IContentType contentType;
- if (this.maps.Item1.TryGetValue(type, out contentType))
- {
- return contentType;
- }
-
- return (ContentTypeRegistryService as IContentTypeRegistryService2).GetContentTypeForMimeType (type);
- }
-
- public void LinkTypes(string mimeType, IContentType contentType)
- {
- var oldMap = Volatile.Read(ref this.maps);
- while (true)
- {
- if (oldMap.Item1.ContainsKey(mimeType) || oldMap.Item2.ContainsKey(contentType))
- break;
-
- var newMap = Tuple.Create(oldMap.Item1.Add(mimeType, contentType), oldMap.Item2.Add(contentType, mimeType));
- var result = Interlocked.CompareExchange(ref this.maps, newMap, oldMap);
- if (result == oldMap)
- {
- break;
- }
-
- oldMap = result;
- }
- }
-
- void LinkTypes (string mimeType, string contentType)
- {
- LinkTypes (mimeType, ContentTypeRegistryService.GetContentType (contentType));
- }
-
- void IPartImportsSatisfiedNotification.OnImportsSatisfied ()
- {
- LinkTypes ("text/plain", "text");
- LinkTypes ("text/x-csharp", "csharp");
- }
-
- Tuple<ImmutableDictionary<string, IContentType>, ImmutableDictionary<IContentType, string>> maps = Tuple.Create(ImmutableDictionary<string, IContentType>.Empty, ImmutableDictionary<IContentType, string>.Empty);
- }
-
// Fold back into Text.Def.TextData.TextSnapshotToTextReader
- public sealed class NewTextSnapshotToTextReader : TextReader
+ // TODO: editor obsolete
+ internal sealed class NewTextSnapshotToTextReader : TextReader
{
#region TextReader methods
/// <summary>
@@ -324,69 +249,4 @@ namespace Microsoft.VisualStudio.Platform int _end;
}
-
-#if false
- [Export(typeof(ITaggerProvider))]
- [ContentType("text")]
- [TagType(typeof(IClassificationTag))]
- public class TestClassifierProvider : ITaggerProvider
- {
- [Import]
- internal IClassificationTypeRegistryService ClassificationTypeRegistryService { get; private set; }
-
- [Export]
- [Name("keyword")]
- public ClassificationTypeDefinition textClassificationType;
-
- public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
- {
- return buffer.Properties.GetOrCreateSingletonProperty(typeof(TestClassifier), () => new TestClassifier(this)) as ITagger<T>;
- }
- }
-
- public class TestClassifier : ITagger<IClassificationTag>
- {
- private ClassificationTag _keyword { get; }
-
- public TestClassifier(TestClassifierProvider provider)
- {
- _keyword = new ClassificationTag(provider.ClassificationTypeRegistryService.GetClassificationType("keyword"));
- }
-
- public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans)
- {
- foreach (var span in spans)
- {
- int start = -1;
- for (int i = span.Start; (i < span.End); ++i)
- {
- var c = span.Snapshot[i];
- if ((c == 'a') || (c == 'A'))
- {
- if (start == -1)
- {
- start = i;
- }
- }
- else if (start != -1)
- {
- yield return new TagSpan<ClassificationTag>(
- new SnapshotSpan(span.Snapshot, start, i - start),
- _keyword);
- start = -1;
- }
- }
-
- if (start != -1)
- {
- yield return new TagSpan<ClassificationTag>(
- new SnapshotSpan(span.Snapshot, start, span.End - start),
- _keyword);
- }
- }
- }
-
- public event EventHandler<SnapshotSpanEventArgs> TagsChanged;
- }
-#endif
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj index 6269e01745..2125705f3f 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj @@ -4281,6 +4281,7 @@ <InternalsVisibleTo Include="MonoDevelop.Refactoring.Tests" /> <InternalsVisibleTo Include="MonoDevelop.SourceEditor" /> <InternalsVisibleTo Include="MonoDevelop.SourceEditor2" /> + <InternalsVisibleTo Include="MonoDevelop.TextEditor" /> <InternalsVisibleTo Include="MonoDevelop.TextEditor.Tests" /> <InternalsVisibleTo Include="MonoDevelop.UnitTesting" /> <InternalsVisibleTo Include="MonoDevelop.VBNetBinding" /> diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs index e1ffc4319a..ddf38b4be9 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs @@ -26,14 +26,15 @@ using System; using System.Collections.Generic; -using Mono.Addins; -using MonoDevelop.Ide.Desktop; -using MonoDevelop.Core; using System.IO; +using System.Threading.Tasks; +using Microsoft.VisualStudio.Utilities;
+using Mono.Addins; using MonoDevelop.Components; using MonoDevelop.Components.MainToolbar; +using MonoDevelop.Core; +using MonoDevelop.Ide.Desktop; using MonoDevelop.Ide.Fonts; -using System.Threading.Tasks; namespace MonoDevelop.Ide { @@ -163,13 +164,13 @@ namespace MonoDevelop.Ide public static string GetRoslynLanguageForMimeType (string mimeType) => MimeTypeCatalog.Instance.GetRoslynLanguageForMimeType (mimeType); - public static string GetMimeTypeForContentType (string contentType) + public static string GetMimeTypeForContentType (IContentType contentType) => MimeTypeCatalog.Instance.GetMimeTypeForContentType (contentType); - public static IEnumerable<string> GetMimeTypeInheritanceChainForContentType (string contentType) + public static IEnumerable<string> GetMimeTypeInheritanceChainForContentType (IContentType contentType) => MimeTypeCatalog.Instance.GetMimeTypeInheritanceChainForContentType (contentType); - public static string GetContentTypeForMimeType (string mimeType) + public static IContentType GetContentTypeForMimeType (string mimeType) => MimeTypeCatalog.Instance.GetContentTypeForMimeType (mimeType); public static string GetMimeTypeForUri (string uri) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/MimeTypeCatalog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/MimeTypeCatalog.cs index 8359fc833d..f788ad6a8a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/MimeTypeCatalog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/MimeTypeCatalog.cs @@ -24,6 +24,8 @@ using System;
using System.Collections.Generic; +using Microsoft.VisualStudio.Platform;
+using Microsoft.VisualStudio.Utilities;
using Mono.Addins; using MonoDevelop.Core;
using MonoDevelop.Ide.Extensions; @@ -34,9 +36,8 @@ namespace MonoDevelop.Ide {
public static MimeTypeCatalog Instance { get; } = new MimeTypeCatalog ();
- readonly MimeTypeNode textPlainNode = new MimeTypeNode ("text/plain", null, GettextCatalog.GetString ("Text document"), null, true, "text");
- readonly MimeTypeNode xmlNode = new MimeTypeNode ("application/xml", null, GettextCatalog.GetString ("XML document"), null, true, null);
-
+ readonly MimeTypeNode textPlainNode = new MimeTypeNode (TextPlain, null, GettextCatalog.GetString ("Text document"), null, true, "text");
+ readonly MimeTypeNode xmlNode = new MimeTypeNode (ApplicationXml, null, GettextCatalog.GetString ("XML document"), null, true, null);
List<MimeTypeNode> mimeTypeNodes = new List<MimeTypeNode> ();
MimeTypeCatalog ()
@@ -60,6 +61,10 @@ namespace MonoDevelop.Ide }
}
+ public const string TextPlain = "text/plain";
+ public const string ApplicationXml = "application/xml";
+ public const string OctetStream = "application/octet-stream";
+
public MimeTypeNode FindMimeType (string type)
{
foreach (MimeTypeNode mt in mimeTypeNodes) {
@@ -95,15 +100,15 @@ namespace MonoDevelop.Ide { yield return mimeType; - while (mimeType != null && mimeType != "text/plain" && mimeType != "application/octet-stream") { + while (mimeType != null && mimeType != TextPlain && mimeType != OctetStream) { MimeTypeNode mt = FindMimeType (mimeType); if (mt != null && !string.IsNullOrEmpty (mt.BaseType)) mimeType = mt.BaseType; else { if (mimeType.EndsWith ("+xml", StringComparison.Ordinal)) - mimeType = "application/xml"; + mimeType = ApplicationXml; else if (mimeType.StartsWith ("text/", StringComparison.Ordinal)) - mimeType = "text/plain"; + mimeType = TextPlain; else break; } @@ -126,7 +131,7 @@ namespace MonoDevelop.Ide while (node != null) {
yield return node; - if (node.Id == "application/octet-stream" || node.Id == "text/plain") {
+ if (node.Id == OctetStream || node.Id == TextPlain) {
yield break;
} @@ -180,18 +185,20 @@ namespace MonoDevelop.Ide return null;
}
- public string GetMimeTypeForContentType (string contentType)
- => GetMimeTypeNodeForContentType (contentType)?.Id;
+ public string GetMimeTypeForContentType (IContentType contentType)
+ => GetMimeTypeNodeForContentType (contentType.TypeName)?.Id;
- public IEnumerable<string> GetMimeTypeInheritanceChainForContentType (string contentType)
- => GetMimeTypeInheritanceChain (GetMimeTypeNodeForContentType (contentType));
+ public IEnumerable<string> GetMimeTypeInheritanceChainForContentType (IContentType contentType)
+ => GetMimeTypeInheritanceChain (GetMimeTypeNodeForContentType (contentType.TypeName));
- public string GetContentTypeForMimeType (string mimeType)
+ public IContentType GetContentTypeForMimeType (string mimeType)
{
- var node = FindMimeType (mimeType);
- foreach (var mt in GetMimeTypeNodeInheritanceChain (node)) {
- if (node.ContentType != null) {
- return node.ContentType;
+ if (mimeType != null) {
+ var node = FindMimeType (mimeType);
+ foreach (var mt in GetMimeTypeNodeInheritanceChain (node)) {
+ if (node.ContentType != null) {
+ return PlatformCatalog.Instance.ContentTypeRegistryService.GetContentType (node.ContentType);
+ }
}
}
return null;
|