Skip to content

Commit

Permalink
Add workaround for ugly rainbow tooltips in VS2017 15.6 (issue #233)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasr committed Mar 14, 2018
1 parent 874e32c commit 0a6978e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Viasfora.Core/Contracts/IVsFeatures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;

namespace Winterdom.Viasfora.Contracts {
public interface IVsFeatures {
bool IsSupported(String featureName);
}
}
7 changes: 7 additions & 0 deletions src/Viasfora.Core/KnownFeatures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;

namespace Winterdom.Viasfora {
public static class KnownFeatures {
public const String TooltipApi = nameof(TooltipApi);
}
}
23 changes: 23 additions & 0 deletions src/Viasfora.Core/Util/VsFeatures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.VisualStudio.Language.Intellisense;
using System;
using System.ComponentModel.Composition;
using Winterdom.Viasfora.Contracts;

namespace Winterdom.Viasfora.Util {
[Export(typeof(IVsFeatures))]
public class VsFeatures : IVsFeatures {
public bool IsSupported(string featureName) {
switch ( featureName ) {
case KnownFeatures.TooltipApi:
return IsQuickInfoSourceDeprecated();
}
throw new InvalidOperationException("Unknown feature: " + featureName);
}

private bool IsQuickInfoSourceDeprecated() {
return typeof(IQuickInfoSource)
.GetCustomAttributes(typeof(ObsoleteAttribute), false)
.Length > 0;
}
}
}
3 changes: 3 additions & 0 deletions src/Viasfora.Core/Viasfora.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<Compile Include="Contracts\ILogger.cs" />
<Compile Include="Contracts\IPackageUserOptions.cs" />
<Compile Include="Contracts\IPresentationModeState.cs" />
<Compile Include="Contracts\IVsFeatures.cs" />
<Compile Include="Contracts\IVsfTelemetry.cs" />
<Compile Include="DefaultNames.cs" />
<Compile Include="Design\NativeMethods.cs" />
Expand All @@ -182,6 +183,7 @@
<Compile Include="IUpdatableSettings.cs" />
<Compile Include="IVsfSettings.cs" />
<Compile Include="JsonExtensions.cs" />
<Compile Include="KnownFeatures.cs" />
<Compile Include="LanguageExtensions.cs" />
<Compile Include="Margins\DevMarginProvider.cs" />
<Compile Include="Margins\DevMarginViewModel.cs" />
Expand Down Expand Up @@ -263,6 +265,7 @@
<Compile Include="Util\StringChars.cs" />
<Compile Include="Util\StringPart.cs" />
<Compile Include="Util\VsColors.cs" />
<Compile Include="Util\VsFeatures.cs" />
<Compile Include="VsSolution.cs" />
<Compile Include="XLangSupport\FakeContentTypeDefinition.cs" />
<Compile Include="XLangSupport\XLangTextViewCreationListener.cs" />
Expand Down
11 changes: 11 additions & 0 deletions src/Viasfora.Rainbow/Util/ToolTipWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Formatting;
using Microsoft.VisualStudio.Utilities;
using Winterdom.Viasfora.Contracts;
using Winterdom.Viasfora.Rainbow;

namespace Winterdom.Viasfora.Util {
Expand All @@ -15,6 +17,8 @@ public class ToolTipWindowProvider : IToolTipWindowProvider {
public ITextEditorFactoryService EditorFactory { get; set; }
[Import]
public IEditorOptionsFactoryService OptionsFactory { get; set; }
[Import]
public IVsFeatures VsFeatures { get; set; }

public IToolTipWindow CreateToolTip(ITextView textView) {
return new ToolTipWindow(textView, this);
Expand Down Expand Up @@ -139,6 +143,13 @@ private void CreateTipView() {
options.SetOptionValue(ViewOptions.WordWrapStyleId, WordWrapStyles.None);
options.SetOptionValue(ViewOptions.ViewProhibitUserInput, true);

// only for VS2017 15.6 and up, where IIntellisensePresenter is
// not supported anymore (replaced by the tooltip APIs), we
// set the background to transparent so that it looks like regular
// intellisense popup
if ( this.provider.VsFeatures.IsSupported(KnownFeatures.TooltipApi) ) {
this.tipView.Background = Brushes.Transparent;
}
this.tipView.ViewportWidthChanged += OnViewportWidthChanged;

this.tipView.ZoomLevel = GetSourceZoomFactor() * ZoomFactor * 100;
Expand Down

0 comments on commit 0a6978e

Please sign in to comment.