Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/15 17:35:50 (10 years ago)
Author:
jkarder
Message:

#2077:

  • added fancy xml documentation
  • fixed configurations and plattforms
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  
    11#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
    43//
    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:
    99//
    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.
    1412//
    15 // You should have received a copy of the GNU General Public License
    16 // 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.
    2119
    2220/* HeuristicLab
    23  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     21 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    2422 *
    2523 * This file is part of HeuristicLab.
     
    4442using System.Windows;
    4543using System.Windows.Controls;
    46 using ICSharpCode.AvalonEdit.Highlighting;
    4744using ICSharpCode.NRefactory.CSharp;
    48 using ICSharpCode.NRefactory.Editor;
    4945using ICSharpCode.NRefactory.TypeSystem;
     46using ICSharpCode.NRefactory.Xml;
    5047
    5148namespace HeuristicLab.CodeEditor {
    52   internal sealed class CSharpInsightItem {
     49  sealed class CSharpInsightItem {
    5350    public readonly IParameterizedMember Method;
    5451
     
    5754    }
    5855
    59     TextBlock header;
     56    FlowDocumentScrollViewer header;
    6057
    6158    public object Header {
    6259      get {
    6360        if (header == null) {
    64           header = new TextBlock();
    65           GenerateHeader();
     61          header = GenerateHeader();
    6662        }
    6763        return header;
     
    7672      this.highlightedParameterIndex = parameterIndex;
    7773      if (header != null)
    78         GenerateHeader();
     74        header = GenerateHeader();
    7975    }
    8076
    81     void GenerateHeader() {
    82       var ambience = new CSharpAmbience { ConversionFlags = ConversionFlags.StandardConversionFlags };
     77    FlowDocumentScrollViewer GenerateHeader() {
     78      var ambience = new CSharpAmbience();
     79      ambience.ConversionFlags = ConversionFlags.StandardConversionFlags;
    8380      var stringBuilder = new StringBuilder();
    8481      var formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex);
    8582      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      };
    91115    }
    92116
     117    FlowDocumentScrollViewer content;
     118
    93119    public object Content {
    94       get { return Documentation; }
    95     }
    96 
    97     private string documentation;
    98     public string Documentation {
    99120      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();
    105123        }
    106         return documentation;
     124        return content;
    107125      }
    108126    }
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CompletionData/CodeCompletionData.cs

    r11700 r11804  
    6464    #region ICSharpCode.AvalonEdit.CodeCompletion.ICompletionData Members
    6565    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
    6777    public virtual ImageSource Image { get; set; }
    6878    public double Priority { get; set; }
     
    7383    }
    7484    #endregion
     85
     86    protected virtual object CreateFancyDescription() {
     87      return Description;
     88    }
    7589  }
    7690}
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CompletionData/EntityCompletionData.cs

    r11802 r11804  
    2121
    2222using System;
    23 using System.IO;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Xml;
     23using System.Windows;
     24using System.Windows.Controls;
    2725using ICSharpCode.AvalonEdit.CodeCompletion;
    2826using ICSharpCode.NRefactory.Completion;
    2927using ICSharpCode.NRefactory.CSharp;
    3028using ICSharpCode.NRefactory.TypeSystem;
     29using ICSharpCode.NRefactory.Xml;
    3130
    3231namespace HeuristicLab.CodeEditor {
     
    4847    }
    4948
    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);
    5861        }
    59         return description;
    6062      }
    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      };
    6271    }
    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 Helpers
    116     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     #endregion
    12672  }
    12773}
Note: See TracChangeset for help on using the changeset viewer.