diff options
author | José Medrano <jose.medrano@xamarin.com> | 2016-05-17 09:57:49 +0300 |
---|---|---|
committer | José Medrano <jose.medrano@xamarin.com> | 2016-05-17 09:57:49 +0300 |
commit | f7a35fc9d63c6e23fe4f9bd314a5c2817a06277c (patch) | |
tree | 4f657c5879c2dacbd4c422a1029bd58830c195e9 | |
parent | 02b27fb8f6ae51091c6d1174bb33d8a7c73cdf7a (diff) |
[Prototype] Adds MethodInfoMarker to Extensions with some logic implementedfeature_methodinfo
Please do not merge this is only for learning purposes
8 files changed, 185 insertions, 0 deletions
diff --git a/main/src/addins/CSharpBinding/CSharpBinding.addin.xml b/main/src/addins/CSharpBinding/CSharpBinding.addin.xml index 15e1d2e01d..f6490fd479 100644 --- a/main/src/addins/CSharpBinding/CSharpBinding.addin.xml +++ b/main/src/addins/CSharpBinding/CSharpBinding.addin.xml @@ -157,6 +157,7 @@ <Class fileExtensions = ".cs" class = "MonoDevelop.CSharp.UnitTestTextEditorExtension" /> <Class fileExtensions = ".cs" class = "MonoDevelop.CSharp.ClassOutline.CSharpOutlineTextEditorExtension" /> <Class fileExtensions = ".cs" class = "MonoDevelop.CSharp.CSharpNavigationTextEditorExtension" /> + <Class fileExtensions = ".cs" class = "MonoDevelop.CSharp.MethodInfoExtension" /> <Class fileExtensions = ".json" class = "MonoDevelop.JSon.JSonTextEditorExtension" /> <Class class = "MonoDevelop.CSharp.Refactoring.CSharpFeaturesTextEditorExtension" /> </Extension> diff --git a/main/src/addins/CSharpBinding/CSharpBinding.csproj b/main/src/addins/CSharpBinding/CSharpBinding.csproj index 7e33495d05..fcba327beb 100644 --- a/main/src/addins/CSharpBinding/CSharpBinding.csproj +++ b/main/src/addins/CSharpBinding/CSharpBinding.csproj @@ -829,6 +829,7 @@ <Compile Include="MonoDevelop.CSharp.Navigation\FindBaseSymbolsHandler.cs" /> <Compile Include="MonoDevelop.CSharp.Navigation\FindImplementingMembersHandler.cs" /> <Compile Include="MonoDevelop.CSharp.Refactoring\ConstructFixer.cs" /> + <Compile Include="MonoDevelop.CSharp\MethodInfoExtension.cs" /> </ItemGroup> <ItemGroup> <None Include="Makefile.am" /> diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/MethodInfoExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/MethodInfoExtension.cs new file mode 100644 index 0000000000..c839aac555 --- /dev/null +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/MethodInfoExtension.cs @@ -0,0 +1,119 @@ +/* + +MethodInfoExtension.cs + +Author: + Jose Medrano <jose.medrano@xamarin.com> + +Copyright (c) 2016 Jose Medrano + +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.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CSharp; +using Mono.Addins; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Ide.Editor.Extension; + +namespace MonoDevelop.CSharp +{ + public class MethodInfoExtension : TextEditorExtension + { + public MethodInfoExtension () + { + } + CancellationTokenSource src = new CancellationTokenSource (); + protected override void Initialize () + { + base.Initialize (); + DocumentContext.DocumentParsed += HandleDocumentParsed; + } + + public override void Dispose () + { + src.Cancel (); + DocumentContext.DocumentParsed -= HandleDocumentParsed; + base.Dispose (); + } + + void HandleDocumentParsed (object sender, EventArgs e) + { + src.Cancel (); + src = new CancellationTokenSource (); + var token = src.Token; + //var unitTestMarker = TextMarkerFactory.CreateUnitTestMarker (Editor, new UnitTestMarkerHostImpl (this), foundTest); + //newMarkers.Add (unitTestMarker); + //var line = Editor.GetLineByOffset (foundTest.Offset); + //if (line != null) { + + //var unitTestMarkers = AddinManager.GetExtensionNodes (TestMarkersPath).OfType<IUnitTestMarkers> ().ToArray (); + foreach (var item in new int[] { 1, 2 }) { + var line = Editor.GetLine (item); + if (line != null) { + + var bubble = TextMarkerFactory.CreateCurrentMethodInfoMarker (Editor); + Editor.AddMarker (line, bubble); + } + } + + //}; + //ThreadPool.QueueUserWorkItem (delegate { + // if (token.IsCancellationRequested || DocumentContext == null) + // return; + // try { + // GatherUnitTests (unitTestMarkers, token).ContinueWith (task => { + // var foundTests = task.Result; + // if (foundTests == null || DocumentContext == null) + // return; + // Application.Invoke (delegate { + // if (token.IsCancellationRequested || DocumentContext == null) + // return; + // foreach (var oldMarker in currentMarker) + // Editor.RemoveMarker (oldMarker); + // var newMarkers = new List<IUnitTestMarker> (); + // foreach (var foundTest in foundTests) { + // if (foundTest == null) + // continue; + // var unitTestMarker = TextMarkerFactory.CreateUnitTestMarker (Editor, new UnitTestMarkerHostImpl (this), foundTest); + // newMarkers.Add (unitTestMarker); + // var line = Editor.GetLineByOffset (foundTest.Offset); + // if (line != null) { + // Editor.AddMarker (line, unitTestMarker); + // } + // } + // currentMarker = newMarkers; + // }); + + // }, TaskContinuationOptions.ExecuteSynchronously | + // TaskContinuationOptions.NotOnCanceled | + // TaskContinuationOptions.NotOnFaulted); + // } catch (OperationCanceledException) { + // } + //}); + } + + class NUnitVisitor : CSharpSyntaxWalker + { + + } + } +} + diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj index c300831fcc..8ead5199d5 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj @@ -218,6 +218,7 @@ <Compile Include="MonoDevelop.SourceEditor.Wrappers\ImmutableTextTextSource.cs" /> <Compile Include="MonoDevelop.SourceEditor\SearchInSelectionMarker.cs" /> <Compile Include="MonoDevelop.SourceEditor\DefaultAutoInsertBracketHandler.cs" /> + <Compile Include="MonoDevelop.SourceEditor\TextMarker\MethodInfoMarker.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="gtk-gui\gui.stetic"> diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs index 847a1824bf..8f78439809 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs @@ -3399,6 +3399,11 @@ namespace MonoDevelop.SourceEditor return new CurrentDebugLineTextMarker (TextEditor, offset, length); } + ITextLineMarker ITextMarkerFactory.CreateCurrentMethodInfoMarker () + { + return new MethodInfoMarker (); + } + ITextLineMarker ITextMarkerFactory.CreateAsmLineMarker (MonoDevelop.Ide.Editor.TextEditor editor) { return new AsmLineMarker (); diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/TextMarker/MethodInfoMarker.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/TextMarker/MethodInfoMarker.cs new file mode 100644 index 0000000000..507b9a892b --- /dev/null +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/TextMarker/MethodInfoMarker.cs @@ -0,0 +1,53 @@ +/* + +CurrentMethodInfoMarker.cs + +Author: + Jose Medrano <jose.medrano@xamarin.com> + +Copyright (c) 2016 Jose Medrano + +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 MonoDevelop.Ide.Editor; +using Mono.TextEditor; +using MonoDevelop.Core; +using Mono.TextEditor.Highlighting; +using MonoDevelop.SourceEditor.Wrappers; + +namespace MonoDevelop.SourceEditor +{ + class MethodInfoMarker : TextLineMarker, MonoDevelop.Ide.Editor.ITextLineMarker + { + public override ChunkStyle GetStyle (ChunkStyle baseStyle) + { + var st = new ChunkStyle (baseStyle); + st.Foreground = new Cairo.Color (.54, 0, 0); + return st; + } + + MonoDevelop.Ide.Editor.IDocumentLine MonoDevelop.Ide.Editor.ITextLineMarker.Line { + get { + return new DocumentLineWrapper (LineSegment); + } + } + } +} + diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextMarkerFactory.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextMarkerFactory.cs index 68f0ac8651..b68ad06b93 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextMarkerFactory.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextMarkerFactory.cs @@ -41,6 +41,7 @@ namespace MonoDevelop.Ide.Editor #region Line marker IUrlTextLineMarker CreateUrlTextMarker (TextEditor editor, IDocumentLine line, string value, UrlType url, string syntax, int startCol, int endCol); ICurrentDebugLineTextMarker CreateCurrentDebugLineTextMarker (TextEditor editor, int offset, int length); + ITextLineMarker CreateCurrentMethodInfoMarker (); ITextLineMarker CreateAsmLineMarker (TextEditor editor); IUnitTestMarker CreateUnitTestMarker (TextEditor editor, UnitTestMarkerHost host, UnitTestLocation unitTestLocation); IMessageBubbleLineMarker CreateMessageBubbleLineMarker (TextEditor editor); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextMarkerFactory.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextMarkerFactory.cs index 0a1530f5a1..9da2dd662c 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextMarkerFactory.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextMarkerFactory.cs @@ -62,6 +62,10 @@ namespace MonoDevelop.Ide.Editor return editor.TextMarkerFactory.CreateMessageBubbleLineMarker (editor); } + public static ITextLineMarker CreateCurrentMethodInfoMarker (TextEditor editor) + { + return editor.TextMarkerFactory.CreateCurrentMethodInfoMarker (); + } #endregion |