Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasr committed Mar 19, 2018
2 parents 7cdc5ac + 9df8c55 commit c9b282e
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Most features include support for the following languages
* S
* R
* HLSL
* Fortran

# Building
Visual Studio 2017 is needed for building from source.
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
10 changes: 8 additions & 2 deletions src/Viasfora.Languages/BraceScanners/CBraceScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ private bool ParseText(ITextChars tc, ref CharPos pos) {
this.status = stString;
tc.Next();
this.ParseString(tc);
} else if ( Char.IsDigit(tc.Char()) && tc.NChar() == '\'' ) {
// this is a C++ 14 digit separator, such as 1'000'000
} else if ( IsHexDigit(tc.Char()) && tc.NChar() == '\'' ) {
// this is a C++ 14 digit separator, such as 1'000'000 or 0xFFFF'0000
tc.Skip(2);
} else if ( tc.Char() == '\'' ) {
this.status = stString;
Expand Down Expand Up @@ -106,5 +106,11 @@ private void ParseMultiLineComment(ITextChars tc) {
}
}
}

private static bool IsHexDigit(char c) {
return Char.IsDigit(c)
|| (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F');
}
}
}
10 changes: 10 additions & 0 deletions src/Viasfora.Rainbow/RainbowToolTipSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qui
if ( IsTooClose(triggerPoint.Value, otherBrace.Value) ) {
return;
}

// IQuickInfoSession.Dismissed is never firing in VS2017 15.6
// so if the tooltip window still exists, kill it
// and hope to god leaving IQuickInfoSession.Dismissed hooked
// up doesn't end up in a memory leak
if ( toolTipWindow != null ) {
toolTipWindow.Dispose();
toolTipWindow = null;
}

session.Dismissed += OnSessionDismissed;

if ( toolTipWindow == null ) {
Expand Down
41 changes: 21 additions & 20 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 @@ -85,7 +89,7 @@ private void ScrollIntoView(SnapshotPoint bufferPosition) {
return;
}
this.tipView.DisplayTextLineContainingBufferPosition(
viewPos, this.tipView.LineHeight, ViewRelativePosition.Top
viewPos, 2 * this.tipView.LineHeight, ViewRelativePosition.Top
);
SetViewportLeft();
// it could very well be that after 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 Expand Up @@ -183,29 +194,19 @@ private void ReleaseView() {
// Returning the EditBuffer as the ViewBuffer appears
// to work around this.
class TipTextViewModel : ITextViewModel {
private ITextView sourceView;
private PropertyCollection properties;

public TipTextViewModel(ITextView source) {
this.sourceView = source;
this.properties = new PropertyCollection();
this.DataBuffer = source.TextViewModel.DataBuffer;
this.DataModel = source.TextViewModel.DataModel;
this.EditBuffer = source.TextViewModel.EditBuffer;
this.Properties = new PropertyCollection();
}

public ITextBuffer DataBuffer {
get { return sourceView.TextViewModel.DataBuffer; }
}
public ITextDataModel DataModel {
get { return sourceView.TextViewModel.DataModel; }
}
public ITextBuffer EditBuffer {
get { return sourceView.TextViewModel.EditBuffer; }
}
public ITextBuffer VisualBuffer {
get { return this.EditBuffer; }
}
public PropertyCollection Properties {
get { return this.properties; }
}
public ITextBuffer DataBuffer { get; private set; }
public ITextDataModel DataModel { get; private set; }
public ITextBuffer EditBuffer { get; private set; }
public ITextBuffer VisualBuffer => this.EditBuffer;
public PropertyCollection Properties { get; private set; }

public SnapshotPoint GetNearestPointInVisualBuffer(SnapshotPoint editBufferPoint) {
// editBufferPoint MUST be in the editBuffer according to the docs
Expand Down
6 changes: 2 additions & 4 deletions src/Viasfora.Xml/XmlQuickInfoSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Tagging;
using Winterdom.Viasfora.Util;
using System.Windows.Media;

namespace Winterdom.Viasfora.Xml {
internal class XmlQuickInfoSource : IQuickInfoSource {
Expand Down Expand Up @@ -60,10 +61,7 @@ private UIElement CreateInfoText(String xmlns, String url) {
});
// set styles in order to support other
// visual studio themes on 2012/2013
var brushKey = VsColors.ToolTipBrushKey;
if ( brushKey != null ) {
textBlock.SetResourceReference(TextBlock.BackgroundProperty, brushKey);
}
textBlock.Background = Brushes.Transparent;
textBlock.SetResourceReference(TextBlock.ForegroundProperty, VsColors.ToolTipTextBrushKey);
hl.SetResourceReference(Hyperlink.ForegroundProperty, VsColors.PanelHyperlinkBrushKey);
return textBlock;
Expand Down
2 changes: 1 addition & 1 deletion src/Viasfora/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Winterdom.Viasfora.f7a33795-2b40-4125-856c-89b0bd8cd5ab"
Version="3.8"
Version="3.9"
Language="en-US"
Publisher="Tomas Restrepo" />
<DisplayName>Viasfora</DisplayName>
Expand Down
7 changes: 7 additions & 0 deletions tests/Viasfora.Tests/BraceScanners/CBraceScannerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public void CanExtractBracesFollowingCpp14QuoteInIntLiteral() {
Assert.Equal(4, chars.Count);
}
[Fact]
public void CanExtractBracesFollowingCpp14QuoteInHexLiteral() {
String input = @"if ( x == 0xFF'000 ) { }";
var extractor = new CBraceScanner();
var chars = Extract(extractor, input.Trim(), 0, 0);
Assert.Equal(4, chars.Count);
}
[Fact]
public void CanExtractBracesFollowingCpp14QuoteInIntLiteralHex() {
String input = @"if ( x == 0x80'00 ) { }";
var extractor = new CBraceScanner();
Expand Down

0 comments on commit c9b282e

Please sign in to comment.