Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorSandy Armstrong <sandy@xamarin.com>2019-06-26 05:32:24 +0300
committerSandy Armstrong <sandy@xamarin.com>2019-06-26 05:50:44 +0300
commit254a5ebb82bbc90847bfa6558b674c8d460bcfe1 (patch)
tree6de243841a9a0a6dda692b364ef69c3e78279bdc /main
parentb9a4bf42378bb04d6661e5547afcfc8c9edab0c7 (diff)
roz wip
Diffstat (limited to 'main')
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpFormatter.cs90
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.OptionProvider/CSharpDocumentOptionsProvider.cs28
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TextPolicyDocumentOptionsProvider.cs2
3 files changed, 64 insertions, 56 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpFormatter.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpFormatter.cs
index 9b3b4ca8e4..bf0d3cbef8 100644
--- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpFormatter.cs
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpFormatter.cs
@@ -1,29 +1,29 @@
-//
-// CSharpFormatter.cs
-//
-// Author:
-// Mike Krüger <mkrueger@novell.com>
-//
-// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
+//
+// CSharpFormatter.cs
+//
+// Author:
+// Mike Krüger <mkrueger@novell.com>
+//
+// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
using System;
using System.Collections.Generic;
using System.Threading;
@@ -50,6 +50,7 @@ using MonoDevelop.CSharp.OptionProvider;
using Microsoft.VisualStudio.CodingConventions;
using System.Linq;
using System.Collections.Immutable;
+using System.Runtime.CompilerServices;
namespace MonoDevelop.CSharp.Formatting
{
@@ -81,7 +82,7 @@ namespace MonoDevelop.CSharp.Formatting
var endSegment = startLine != endLine ? editor.GetLine (endLine) : startSegment;
if (endSegment == null)
return;
-
+
try {
var document = context.AnalysisDocument;
@@ -93,15 +94,15 @@ namespace MonoDevelop.CSharp.Formatting
formattingRules.Add (ContainedDocumentPreserveFormattingRule.Instance);
formattingRules.AddRange (Formatter.GetDefaultFormattingRules (document));
- var workspace = document.Project.Solution.Workspace;
+ var workspace = document.Project.Solution.Workspace;
var root = await document.GetSyntaxRootAsync (cancellationToken).ConfigureAwait (false);
- var options = await document.GetOptionsAsync (cancellationToken).ConfigureAwait (false);
+ var options = await document.GetOptionsAsync (cancellationToken).ConfigureAwait (false);
var changes = Formatter.GetFormattedTextChanges (
root, new TextSpan [] { new TextSpan (startSegment.Offset, endSegment.EndOffset - startSegment.Offset) },
workspace, options, formattingRules, cancellationToken);
if (changes == null)
- return;
+ return;
await Runtime.RunInMainThread (delegate {
editor.ApplyTextChanges (changes);
editor.FixVirtualIndentation ();
@@ -159,6 +160,9 @@ namespace MonoDevelop.CSharp.Formatting
{
readonly OptionSet optionSet;
readonly ICodingConventionsSnapshot codingConventionsSnapshot;
+ private static readonly ConditionalWeakTable<IReadOnlyDictionary<string, object>, IReadOnlyDictionary<string, string>> s_convertedDictionaryCache =
+ new ConditionalWeakTable<IReadOnlyDictionary<string, object>, IReadOnlyDictionary<string, string>> ();
+
public DocumentOptions (OptionSet optionSet, ICodingConventionsSnapshot codingConventionsSnapshot)
{
@@ -166,20 +170,24 @@ namespace MonoDevelop.CSharp.Formatting
this.codingConventionsSnapshot = codingConventionsSnapshot;
}
- public bool TryGetDocumentOption (OptionKey option, OptionSet underlyingOptions, out object value)
+ public bool TryGetDocumentOption (OptionKey option, out object value)
{
if (codingConventionsSnapshot != null) {
var editorConfigPersistence = option.Option.StorageLocations.OfType<IEditorConfigStorageLocation> ().SingleOrDefault ();
if (editorConfigPersistence != null) {
-
- var tempRawConventions = codingConventionsSnapshot.AllRawConventions;
- // HACK: temporarly map our old Dictionary<string, object> to a Dictionary<string, string>. This will go away in a future commit.
- // see https://github.com/dotnet/roslyn/commit/6a5be42f026f8d0432cfe8ee7770ff8f6be01bd6#diff-626aa9dd2f6e07eafa8eac7ddb0eb291R34
- var allRawConventions = ImmutableDictionary.CreateRange (tempRawConventions.Select (c => Roslyn.Utilities.KeyValuePairUtil.Create (c.Key, c.Value.ToString ())));
+ // Temporarly map our old Dictionary<string, object> to a Dictionary<string, string>. This can go away once we either
+ // eliminate the legacy editorconfig support, or we change IEditorConfigStorageLocation.TryGetOption to take
+ // some interface that lets us pass both the Dictionary<string, string> we get from the new system, and the
+ // Dictionary<string, object> from the old system.
+ //
+ // We cache this with a conditional weak table so we're able to maintain the assumptions in EditorConfigNamingStyleParser
+ // that the instance doesn't regularly change and thus can be used for further caching
+ var allRawConventions = s_convertedDictionaryCache.GetValue (
+ codingConventionsSnapshot.AllRawConventions,
+ d => ImmutableDictionary.CreateRange (d.Select (c => KeyValuePairUtil.Create (c.Key, c.Value.ToString ()))));
try {
- var underlyingOption = underlyingOptions.GetOption (option);
- if (editorConfigPersistence.TryGetOption (underlyingOption, allRawConventions, option.Option.Type, out value))
+ if (editorConfigPersistence.TryGetOption (allRawConventions, option.Option.Type, out value))
return true;
} catch (Exception ex) {
LoggingService.LogError ("Error while getting editor config preferences.", ex);
@@ -188,10 +196,6 @@ namespace MonoDevelop.CSharp.Formatting
}
var result = optionSet.GetOption (option);
- if (result == underlyingOptions.GetOption (option)) {
- value = null;
- return false;
- }
value = result;
return true;
}
@@ -210,7 +214,7 @@ namespace MonoDevelop.CSharp.Formatting
public override object GetOption (OptionKey optionKey)
{
- if (optionsProvider.TryGetDocumentOption (optionKey, fallbackOptionSet, out object value))
+ if (optionsProvider.TryGetDocumentOption (optionKey, out object value))
return value;
return fallbackOptionSet.GetOption (optionKey);
}
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.OptionProvider/CSharpDocumentOptionsProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.OptionProvider/CSharpDocumentOptionsProvider.cs
index 0ff4f59c7f..b48aca4ce4 100644
--- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.OptionProvider/CSharpDocumentOptionsProvider.cs
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.OptionProvider/CSharpDocumentOptionsProvider.cs
@@ -29,6 +29,7 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Options;
+using Roslyn.Utilities;
using MonoDevelop.CSharp.Formatting;
using MonoDevelop.Ide.Gui.Content;
using MonoDevelop.Ide.TypeSystem;
@@ -40,6 +41,7 @@ using System.Linq;
using MonoDevelop.Ide.Editor;
using System.Collections.Generic;
using System.Collections.Immutable;
+using System.Runtime.CompilerServices;
namespace MonoDevelop.CSharp.OptionProvider
{
@@ -87,6 +89,8 @@ namespace MonoDevelop.CSharp.OptionProvider
TextStylePolicy TextPolicy => textpolicy ?? (textpolicy = policyBag?.Get<TextStylePolicy> (types) ?? PolicyService.InvariantPolicies?.Get<TextStylePolicy> (types));
readonly ICodingConventionsSnapshot codingConventionsSnapshot;
+ private static readonly ConditionalWeakTable<IReadOnlyDictionary<string, object>, IReadOnlyDictionary<string, string>> s_convertedDictionaryCache =
+ new ConditionalWeakTable<IReadOnlyDictionary<string, object>, IReadOnlyDictionary<string, string>> ();
public DocumentOptions (PolicyBag policyBag, ICodingConventionsSnapshot codingConventionsSnapshot)
{
@@ -94,20 +98,24 @@ namespace MonoDevelop.CSharp.OptionProvider
this.codingConventionsSnapshot = codingConventionsSnapshot;
}
- public bool TryGetDocumentOption (OptionKey option, OptionSet underlyingOptions, out object value)
+ public bool TryGetDocumentOption (OptionKey option, out object value)
{
if (codingConventionsSnapshot != null) {
var editorConfigPersistence = option.Option.StorageLocations.OfType<IEditorConfigStorageLocation> ().SingleOrDefault ();
if (editorConfigPersistence != null) {
-
- var tempRawConventions = codingConventionsSnapshot.AllRawConventions;
- // HACK: temporarly map our old Dictionary<string, object> to a Dictionary<string, string>. This will go away in a future commit.
- // see https://github.com/dotnet/roslyn/commit/6a5be42f026f8d0432cfe8ee7770ff8f6be01bd6#diff-626aa9dd2f6e07eafa8eac7ddb0eb291R34
- var allRawConventions = ImmutableDictionary.CreateRange (tempRawConventions.Select (c => Roslyn.Utilities.KeyValuePairUtil.Create (c.Key, c.Value.ToString ())));
+ // Temporarly map our old Dictionary<string, object> to a Dictionary<string, string>. This can go away once we either
+ // eliminate the legacy editorconfig support, or we change IEditorConfigStorageLocation.TryGetOption to take
+ // some interface that lets us pass both the Dictionary<string, string> we get from the new system, and the
+ // Dictionary<string, object> from the old system.
+ //
+ // We cache this with a conditional weak table so we're able to maintain the assumptions in EditorConfigNamingStyleParser
+ // that the instance doesn't regularly change and thus can be used for further caching
+ var allRawConventions = s_convertedDictionaryCache.GetValue (
+ codingConventionsSnapshot.AllRawConventions,
+ d => ImmutableDictionary.CreateRange (d.Select (c => KeyValuePairUtil.Create (c.Key, c.Value.ToString ()))));
try {
- var underlyingOption = Policy.OptionSet.GetOption (option);
- if (editorConfigPersistence.TryGetOption (underlyingOption, allRawConventions, option.Option.Type, out value))
+ if (editorConfigPersistence.TryGetOption (allRawConventions, option.Option.Type, out value))
return true;
} catch (Exception ex) {
LoggingService.LogError ("Error while getting editor config preferences.", ex);
@@ -141,10 +149,6 @@ namespace MonoDevelop.CSharp.OptionProvider
}
var result = Policy.OptionSet.GetOption (option);
- if (result == underlyingOptions.GetOption (option)) {
- value = null;
- return false;
- }
value = result;
return true;
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TextPolicyDocumentOptionsProvider.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TextPolicyDocumentOptionsProvider.cs
index 1b05fd4fe9..5bc70be2cf 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TextPolicyDocumentOptionsProvider.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TextPolicyDocumentOptionsProvider.cs
@@ -68,7 +68,7 @@ namespace MonoDevelop.Ide.TypeSystem
this.policy = policy;
}
- public bool TryGetDocumentOption (OptionKey option, OptionSet underlyingOptions, out object value)
+ public bool TryGetDocumentOption (OptionKey option, out object value)
{
if (option.Option == FormattingOptions.UseTabs) {
value = !policy.TabsToSpaces;