Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6c2e11a

Browse files
fix #255: Code Completion description tooltip is unformatted
1 parent a2f64d0 commit 6c2e11a

11 files changed

Lines changed: 106 additions & 46 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CompletionData.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,20 @@ object IFancyCompletionItem.Content {
7676
get { return this.DisplayText; }
7777
}
7878

79+
object fancyDescription;
80+
7981
object IFancyCompletionItem.Description {
80-
get { return this.Description; }
82+
get {
83+
if (fancyDescription == null) {
84+
fancyDescription = CreateFancyDescription();
85+
}
86+
return fancyDescription;
87+
}
88+
}
89+
90+
protected virtual object CreateFancyDescription()
91+
{
92+
return null;
8193
}
8294
}
8395
}

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using ICSharpCode.NRefactory.Completion;
77
using ICSharpCode.NRefactory.TypeSystem;
88
using ICSharpCode.SharpDevelop;
9+
using ICSharpCode.SharpDevelop.Editor;
910

1011
namespace CSharpBinding.Completion
1112
{
@@ -23,5 +24,10 @@ public EntityCompletionData(IEntity entity) : base(entity.Name)
2324
this.Description = entity.Documentation;
2425
this.Image = ClassBrowserIconService.GetIcon(entity);
2526
}
27+
28+
protected override object CreateFancyDescription()
29+
{
30+
return XmlDocFormatter.CreateTooltip(entity);
31+
}
2632
}
2733
}

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using ICSharpCode.NRefactory.TypeSystem;
66
using ICSharpCode.SharpDevelop;
7+
using ICSharpCode.SharpDevelop.Editor;
78

89
namespace CSharpBinding.Completion
910
{
@@ -23,5 +24,10 @@ public TypeCompletionData(IType type) : base(type.Name)
2324
this.Description = typeDef.Documentation;
2425
this.Image = ClassBrowserIconService.GetIcon(type);
2526
}
27+
28+
protected override object CreateFancyDescription()
29+
{
30+
return XmlDocFormatter.CreateTooltip(type);
31+
}
2632
}
2733
}

src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
<Compile Include="Src\SyntaxHighlighting\SyntaxModeDoozer.cs" />
119119
<Compile Include="Src\TextMarkerToolTipProvider.cs" />
120120
<Compile Include="Src\Utils.cs" />
121-
<Compile Include="Src\XmlDoc\DocumentationUIBuilder.cs" />
122121
<Compile Include="Src\XmlDoc\XmlDocTooltipProvider.cs" />
123122
<None Include="AvalonEdit.AddIn.addin">
124123
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -156,7 +155,6 @@
156155
<Compile Include="Src\Commands\SurroundWithCommand.cs" />
157156
<Compile Include="Src\CustomCommands.cs" />
158157
<Compile Include="Src\CustomizedHighlightingColor.cs" />
159-
<Compile Include="Src\DocumentPrinter.cs" />
160158
<Compile Include="Src\InlineUIElementGenerator.cs" />
161159
<Compile Include="Src\IconBarManager.cs" />
162160
<Compile Include="Src\IconBarMargin.cs" />

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopTextEditor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Windows.Media;
1818
using System.Windows.Threading;
1919

20+
using ICSharpCode.AvalonEdit.Utils;
2021
using ICSharpCode.AvalonEdit.AddIn.Options;
2122
using ICSharpCode.AvalonEdit.AddIn.Snippets;
2223
using ICSharpCode.AvalonEdit.Editing;

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/XmlDoc/XmlDocTooltipProvider.cs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,46 +70,12 @@ protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
7070

7171
object CreateTooltip(IType type)
7272
{
73-
var ambience = AmbienceService.GetCurrentAmbience();
74-
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType | ConversionFlags.UseFullyQualifiedTypeNames;
75-
string header;
76-
if (type is ITypeDefinition)
77-
header = ambience.ConvertEntity((ITypeDefinition)type);
78-
else
79-
header = ambience.ConvertType(type);
80-
81-
ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList;
82-
DocumentationUIBuilder b = new DocumentationUIBuilder(ambience);
83-
b.AddCodeBlock(header, keepLargeMargin: true);
84-
85-
ITypeDefinition entity = type.GetDefinition();
86-
if (entity != null) {
87-
var documentation = XmlDocumentationElement.Get(entity);
88-
if (documentation != null) {
89-
foreach (var child in documentation.Children) {
90-
b.AddDocumentationElement(child);
91-
}
92-
}
93-
}
94-
return new FlowDocumentTooltip(b.CreateFlowDocument());
73+
return new FlowDocumentTooltip(XmlDocFormatter.CreateTooltip(type));
9574
}
9675

9776
object CreateTooltip(IEntity entity)
9877
{
99-
var ambience = AmbienceService.GetCurrentAmbience();
100-
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType | ConversionFlags.UseFullyQualifiedTypeNames;
101-
string header = ambience.ConvertEntity(entity);
102-
var documentation = XmlDocumentationElement.Get(entity);
103-
104-
ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList;
105-
DocumentationUIBuilder b = new DocumentationUIBuilder(ambience);
106-
b.AddCodeBlock(header, keepLargeMargin: true);
107-
if (documentation != null) {
108-
foreach (var child in documentation.Children) {
109-
b.AddDocumentationElement(child);
110-
}
111-
}
112-
return new FlowDocumentTooltip(b.CreateFlowDocument());
78+
return new FlowDocumentTooltip(XmlDocFormatter.CreateTooltip(entity));
11379
}
11480
}
11581
}

src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
<RequiredTargetFramework>3.5</RequiredTargetFramework>
6565
</Reference>
6666
<Reference Include="System.Drawing" />
67+
<Reference Include="System.Printing">
68+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
69+
</Reference>
6770
<Reference Include="System.Windows.Forms" />
6871
<Reference Include="System.Xaml">
6972
<RequiredTargetFramework>4.0</RequiredTargetFramework>
@@ -356,6 +359,7 @@
356359
<Compile Include="Utils\Constants.cs" />
357360
<Compile Include="Utils\DelayedEvents.cs" />
358361
<Compile Include="Utils\Deque.cs" />
362+
<Compile Include="Utils\DocumentPrinter.cs" />
359363
<Compile Include="Utils\Empty.cs" />
360364
<Compile Include="Utils\ExtensionMethods.cs" />
361365
<Compile Include="Utils\FileReader.cs" />

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DocumentPrinter.cs renamed to src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/DocumentPrinter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
using System.Windows.Controls;
1010
using System.Windows.Documents;
1111
using System.Windows.Xps;
12-
using System.Windows.Xps.Packaging;
1312

1413
using ICSharpCode.AvalonEdit.Document;
1514
using ICSharpCode.AvalonEdit.Highlighting;
1615
using ICSharpCode.NRefactory.Editor;
1716

18-
namespace ICSharpCode.AvalonEdit.AddIn
17+
namespace ICSharpCode.AvalonEdit.Utils
1918
{
2019
/// <summary>
2120
/// Helps printing documents.

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/XmlDoc/DocumentationUIBuilder.cs renamed to src/Main/Base/Project/Editor/DocumentationUIBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.IO;
76
using System.Linq;
87
using System.Text;
98
using System.Windows;
109
using System.Windows.Documents;
1110
using System.Windows.Media;
12-
using ICSharpCode.AvalonEdit.AddIn.Options;
1311
using ICSharpCode.AvalonEdit.Highlighting;
12+
using ICSharpCode.AvalonEdit.Utils;
1413
using ICSharpCode.NRefactory.Editor;
1514
using ICSharpCode.NRefactory.TypeSystem;
1615
using ICSharpCode.NRefactory.Xml;
17-
using ICSharpCode.SharpDevelop;
1816

19-
namespace ICSharpCode.AvalonEdit.AddIn.XmlDoc
17+
namespace ICSharpCode.SharpDevelop.Editor
2018
{
2119
/// <summary>
2220
/// Builds a FlowDocument for XML documentation.
@@ -247,7 +245,7 @@ void AddThreadSafety(bool? staticThreadSafe, bool? instanceThreadSafe, IEnumerab
247245

248246
FontFamily GetCodeFont()
249247
{
250-
return new FontFamily(CodeEditorOptions.Instance.FontFamily);
248+
return new FontFamily(SD.EditorControlService.GlobalOptions.FontFamily);
251249
}
252250

253251
void AddException(IEntity referencedEntity, IList<XmlDocumentationElement> children)
@@ -489,3 +487,5 @@ void FlushAddedText(bool trim)
489487
}
490488
}
491489
}
490+
491+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2+
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
3+
4+
using System;
5+
using System.Windows.Documents;
6+
using ICSharpCode.NRefactory.TypeSystem;
7+
using ICSharpCode.NRefactory.Xml;
8+
9+
namespace ICSharpCode.SharpDevelop.Editor
10+
{
11+
/// <summary>
12+
/// Provides helper methods to create nicely formatted FlowDocuments from NRefactory XmlDoc.
13+
/// </summary>
14+
public static class XmlDocFormatter
15+
{
16+
public static FlowDocument CreateTooltip(IType type)
17+
{
18+
var ambience = AmbienceService.GetCurrentAmbience();
19+
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType | ConversionFlags.UseFullyQualifiedTypeNames;
20+
string header;
21+
if (type is ITypeDefinition)
22+
header = ambience.ConvertEntity((ITypeDefinition)type);
23+
else
24+
header = ambience.ConvertType(type);
25+
26+
ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList;
27+
DocumentationUIBuilder b = new DocumentationUIBuilder(ambience);
28+
b.AddCodeBlock(header, keepLargeMargin: true);
29+
30+
ITypeDefinition entity = type.GetDefinition();
31+
if (entity != null) {
32+
var documentation = XmlDocumentationElement.Get(entity);
33+
if (documentation != null) {
34+
foreach (var child in documentation.Children) {
35+
b.AddDocumentationElement(child);
36+
}
37+
}
38+
}
39+
return b.CreateFlowDocument();
40+
}
41+
42+
public static FlowDocument CreateTooltip(IEntity entity)
43+
{
44+
var ambience = AmbienceService.GetCurrentAmbience();
45+
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType | ConversionFlags.UseFullyQualifiedTypeNames;
46+
string header = ambience.ConvertEntity(entity);
47+
var documentation = XmlDocumentationElement.Get(entity);
48+
49+
ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList;
50+
DocumentationUIBuilder b = new DocumentationUIBuilder(ambience);
51+
b.AddCodeBlock(header, keepLargeMargin: true);
52+
if (documentation != null) {
53+
foreach (var child in documentation.Children) {
54+
b.AddDocumentationElement(child);
55+
}
56+
}
57+
return b.CreateFlowDocument();
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)