- Timestamp:
- 01/20/15 17:35:50 (10 years ago)
- Location:
- branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpInsightItem.cs
r11700 r11804 1 1 #region License Information 2 // CShell, A Simple C# Scripting IDE 3 // Copyright (C) 2013 Arnova Asset Management Ltd., Lukas Buhler 2 // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 4 3 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 4 // Permission is hereby granted, free of charge, to any person obtaining a copy of this 5 // software and associated documentation files (the "Software"), to deal in the Software 6 // without restriction, including without limitation the rights to use, copy, modify, merge, 7 // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 8 // to whom the Software is furnished to do so, subject to the following conditions: 9 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 10 // The above copyright notice and this permission notice shall be included in all copies or 11 // substantial portions of the Software. 14 12 // 15 // You should have received a copy of the GNU General Public License16 // along with this program. If not, see <http://www.gnu.org/licenses/>.17 18 // This file is based on code from the SharpDevelop project:19 // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \Doc\sharpdevelop-copyright.txt)20 // This code is distributed under the GNU LGPL (for details please see \Doc\COPYING.LESSER.txt)13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 15 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 16 // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 17 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 // DEALINGS IN THE SOFTWARE. 21 19 22 20 /* HeuristicLab 23 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)21 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 24 22 * 25 23 * This file is part of HeuristicLab. … … 44 42 using System.Windows; 45 43 using System.Windows.Controls; 46 using ICSharpCode.AvalonEdit.Highlighting;47 44 using ICSharpCode.NRefactory.CSharp; 48 using ICSharpCode.NRefactory.Editor;49 45 using ICSharpCode.NRefactory.TypeSystem; 46 using ICSharpCode.NRefactory.Xml; 50 47 51 48 namespace HeuristicLab.CodeEditor { 52 internalsealed class CSharpInsightItem {49 sealed class CSharpInsightItem { 53 50 public readonly IParameterizedMember Method; 54 51 … … 57 54 } 58 55 59 TextBlockheader;56 FlowDocumentScrollViewer header; 60 57 61 58 public object Header { 62 59 get { 63 60 if (header == null) { 64 header = new TextBlock(); 65 GenerateHeader(); 61 header = GenerateHeader(); 66 62 } 67 63 return header; … … 76 72 this.highlightedParameterIndex = parameterIndex; 77 73 if (header != null) 78 GenerateHeader();74 header = GenerateHeader(); 79 75 } 80 76 81 void GenerateHeader() { 82 var ambience = new CSharpAmbience { ConversionFlags = ConversionFlags.StandardConversionFlags }; 77 FlowDocumentScrollViewer GenerateHeader() { 78 var ambience = new CSharpAmbience(); 79 ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; 83 80 var stringBuilder = new StringBuilder(); 84 81 var formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex); 85 82 ambience.ConvertSymbol(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop()); 86 var textSource = new StringTextSource(stringBuilder.ToString()); 87 var richTextModel = new RichTextModel(); 88 richTextModel.SetFontWeight(formatter.parameterStartOffset, formatter.parameterLength, FontWeights.Bold); 89 header.Inlines.Clear(); 90 header.Inlines.AddRange(richTextModel.CreateRuns(textSource)); 83 84 var documentation = XmlDocumentationElement.Get(Method); 85 ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; 86 87 var b = new CSharpDocumentationBuilder(ambience); 88 string parameterName = null; 89 if (Method.Parameters.Count > highlightedParameterIndex) 90 parameterName = Method.Parameters[highlightedParameterIndex].Name; 91 b.AddSignatureBlock(stringBuilder.ToString(), formatter.parameterStartOffset, formatter.parameterLength, parameterName); 92 93 var b2 = new CSharpDocumentationBuilder(ambience); 94 b2.ParameterName = parameterName; 95 b2.ShowAllParameters = false; 96 97 if (documentation != null) { 98 foreach (var child in documentation.Children) { 99 b2.AddDocumentationElement(child); 100 } 101 } 102 103 content = new FlowDocumentScrollViewer { 104 Document = b2.CreateFlowDocument(), 105 VerticalScrollBarVisibility = ScrollBarVisibility.Auto 106 }; 107 108 var flowDocument = b.CreateFlowDocument(); 109 flowDocument.PagePadding = new Thickness(0); // default is NOT Thickness(0), but Thickness(Auto), which adds unnecessary space 110 111 return new FlowDocumentScrollViewer { 112 Document = flowDocument, 113 VerticalScrollBarVisibility = ScrollBarVisibility.Auto 114 }; 91 115 } 92 116 117 FlowDocumentScrollViewer content; 118 93 119 public object Content { 94 get { return Documentation; }95 }96 97 private string documentation;98 public string Documentation {99 120 get { 100 if (documentation == null) { 101 if (Method.Documentation == null) 102 documentation = string.Empty; 103 else 104 documentation = EntityCompletionData.XmlDocumentationToText(Method.Documentation); 121 if (content == null) { 122 GenerateHeader(); 105 123 } 106 return documentation;124 return content; 107 125 } 108 126 } -
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CompletionData/CodeCompletionData.cs
r11700 r11804 64 64 #region ICSharpCode.AvalonEdit.CodeCompletion.ICompletionData Members 65 65 public object Content { get { return DisplayText; } } 66 object ACC.ICompletionData.Description { get { return Description; } } 66 67 object fancyDescription; 68 object ACC.ICompletionData.Description { 69 get { 70 if (fancyDescription == null) { 71 fancyDescription = CreateFancyDescription(); 72 } 73 return fancyDescription; 74 } 75 } 76 67 77 public virtual ImageSource Image { get; set; } 68 78 public double Priority { get; set; } … … 73 83 } 74 84 #endregion 85 86 protected virtual object CreateFancyDescription() { 87 return Description; 88 } 75 89 } 76 90 } -
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CompletionData/EntityCompletionData.cs
r11802 r11804 21 21 22 22 using System; 23 using System.IO; 24 using System.Linq; 25 using System.Text; 26 using System.Xml; 23 using System.Windows; 24 using System.Windows.Controls; 27 25 using ICSharpCode.AvalonEdit.CodeCompletion; 28 26 using ICSharpCode.NRefactory.Completion; 29 27 using ICSharpCode.NRefactory.CSharp; 30 28 using ICSharpCode.NRefactory.TypeSystem; 29 using ICSharpCode.NRefactory.Xml; 31 30 32 31 namespace HeuristicLab.CodeEditor { … … 48 47 } 49 48 50 private string description; 51 public override string Description { 52 get { 53 if (string.IsNullOrEmpty(description)) { 54 description = GetText(Entity); 55 if (HasOverloads) 56 description += string.Format(" (+{0} overloads)", OverloadedData.Count()); 57 description += Environment.NewLine + XmlDocumentationToText(Entity.Documentation); 49 protected override object CreateFancyDescription() { 50 var ambience = new CSharpAmbience(); 51 ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType; 52 string header = ambience.ConvertSymbol(Entity); 53 var documentation = XmlDocumentationElement.Get(Entity); 54 55 ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; 56 var b = new CSharpDocumentationBuilder(ambience); 57 b.AddCodeBlock(header, keepLargeMargin: true); 58 if (documentation != null) { 59 foreach (var child in documentation.Children) { 60 b.AddDocumentationElement(child); 58 61 } 59 return description;60 62 } 61 set { description = value; } 63 64 var flowDocument = b.CreateFlowDocument(); 65 flowDocument.PagePadding = new Thickness(0); // default is NOT Thickness(0), but Thickness(Auto), which adds unnecessary space 66 67 return new FlowDocumentScrollViewer { 68 Document = flowDocument, 69 VerticalScrollBarVisibility = ScrollBarVisibility.Auto 70 }; 62 71 } 63 64 public static string XmlDocumentationToText(string xmlDoc) {65 System.Diagnostics.Debug.WriteLine(xmlDoc);66 var b = new StringBuilder();67 try {68 using (var reader = new XmlTextReader(new StringReader("<root>" + xmlDoc + "</root>"))) {69 reader.XmlResolver = null;70 while (reader.Read()) {71 switch (reader.NodeType) {72 case XmlNodeType.Text:73 b.Append(reader.Value);74 break;75 case XmlNodeType.Element:76 switch (reader.Name) {77 case "filterpriority":78 reader.Skip();79 break;80 case "returns":81 b.AppendLine();82 b.Append("Returns: ");83 break;84 case "param":85 b.AppendLine();86 b.Append(reader.GetAttribute("name") + ": ");87 break;88 case "remarks":89 b.AppendLine();90 b.Append("Remarks: ");91 break;92 case "see":93 if (reader.IsEmptyElement) {94 b.Append(reader.GetAttribute("cref"));95 } else {96 reader.MoveToContent();97 if (reader.HasValue) {98 b.Append(reader.Value);99 } else {100 b.Append(reader.GetAttribute("cref"));101 }102 }103 break;104 }105 break;106 }107 }108 }109 return b.ToString();110 } catch (XmlException) {111 return xmlDoc;112 }113 }114 115 #region Helpers116 private static string GetText(IEntity entity) {117 Ambience.ConversionFlags = ConversionFlags.StandardConversionFlags;118 if (entity is ITypeDefinition) Ambience.ConversionFlags |= ConversionFlags.UseFullyQualifiedEntityNames;119 if (entity is IMethod) {120 var reducedForm = ((IMethod)entity).ReducedFrom;121 if (reducedForm != null) entity = reducedForm;122 }123 return Ambience.ConvertSymbol(entity);124 }125 #endregion126 72 } 127 73 }
Note: See TracChangeset
for help on using the changeset viewer.