Skip to content

Commit c9b282e

Browse files
committed
Merge branch 'develop'
2 parents 7cdc5ac + 9df8c55 commit c9b282e

File tree

11 files changed

+90
-27
lines changed

11 files changed

+90
-27
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Most features include support for the following languages
7373
* S
7474
* R
7575
* HLSL
76+
* Fortran
7677

7778
# Building
7879
Visual Studio 2017 is needed for building from source.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System;
2+
3+
namespace Winterdom.Viasfora.Contracts {
4+
public interface IVsFeatures {
5+
bool IsSupported(String featureName);
6+
}
7+
}

src/Viasfora.Core/KnownFeatures.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System;
2+
3+
namespace Winterdom.Viasfora {
4+
public static class KnownFeatures {
5+
public const String TooltipApi = nameof(TooltipApi);
6+
}
7+
}

src/Viasfora.Core/Util/VsFeatures.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.VisualStudio.Language.Intellisense;
2+
using System;
3+
using System.ComponentModel.Composition;
4+
using Winterdom.Viasfora.Contracts;
5+
6+
namespace Winterdom.Viasfora.Util {
7+
[Export(typeof(IVsFeatures))]
8+
public class VsFeatures : IVsFeatures {
9+
public bool IsSupported(string featureName) {
10+
switch ( featureName ) {
11+
case KnownFeatures.TooltipApi:
12+
return IsQuickInfoSourceDeprecated();
13+
}
14+
throw new InvalidOperationException("Unknown feature: " + featureName);
15+
}
16+
17+
private bool IsQuickInfoSourceDeprecated() {
18+
return typeof(IQuickInfoSource)
19+
.GetCustomAttributes(typeof(ObsoleteAttribute), false)
20+
.Length > 0;
21+
}
22+
}
23+
}

src/Viasfora.Core/Viasfora.Core.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
<Compile Include="Contracts\ILogger.cs" />
159159
<Compile Include="Contracts\IPackageUserOptions.cs" />
160160
<Compile Include="Contracts\IPresentationModeState.cs" />
161+
<Compile Include="Contracts\IVsFeatures.cs" />
161162
<Compile Include="Contracts\IVsfTelemetry.cs" />
162163
<Compile Include="DefaultNames.cs" />
163164
<Compile Include="Design\NativeMethods.cs" />
@@ -182,6 +183,7 @@
182183
<Compile Include="IUpdatableSettings.cs" />
183184
<Compile Include="IVsfSettings.cs" />
184185
<Compile Include="JsonExtensions.cs" />
186+
<Compile Include="KnownFeatures.cs" />
185187
<Compile Include="LanguageExtensions.cs" />
186188
<Compile Include="Margins\DevMarginProvider.cs" />
187189
<Compile Include="Margins\DevMarginViewModel.cs" />
@@ -263,6 +265,7 @@
263265
<Compile Include="Util\StringChars.cs" />
264266
<Compile Include="Util\StringPart.cs" />
265267
<Compile Include="Util\VsColors.cs" />
268+
<Compile Include="Util\VsFeatures.cs" />
266269
<Compile Include="VsSolution.cs" />
267270
<Compile Include="XLangSupport\FakeContentTypeDefinition.cs" />
268271
<Compile Include="XLangSupport\XLangTextViewCreationListener.cs" />

src/Viasfora.Languages/BraceScanners/CBraceScanner.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ private bool ParseText(ITextChars tc, ref CharPos pos) {
4747
this.status = stString;
4848
tc.Next();
4949
this.ParseString(tc);
50-
} else if ( Char.IsDigit(tc.Char()) && tc.NChar() == '\'' ) {
51-
// this is a C++ 14 digit separator, such as 1'000'000
50+
} else if ( IsHexDigit(tc.Char()) && tc.NChar() == '\'' ) {
51+
// this is a C++ 14 digit separator, such as 1'000'000 or 0xFFFF'0000
5252
tc.Skip(2);
5353
} else if ( tc.Char() == '\'' ) {
5454
this.status = stString;
@@ -106,5 +106,11 @@ private void ParseMultiLineComment(ITextChars tc) {
106106
}
107107
}
108108
}
109+
110+
private static bool IsHexDigit(char c) {
111+
return Char.IsDigit(c)
112+
|| (c >= 'a' && c <= 'f')
113+
|| (c >= 'A' && c <= 'F');
114+
}
109115
}
110116
}

src/Viasfora.Rainbow/RainbowToolTipSource.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qui
5454
if ( IsTooClose(triggerPoint.Value, otherBrace.Value) ) {
5555
return;
5656
}
57+
58+
// IQuickInfoSession.Dismissed is never firing in VS2017 15.6
59+
// so if the tooltip window still exists, kill it
60+
// and hope to god leaving IQuickInfoSession.Dismissed hooked
61+
// up doesn't end up in a memory leak
62+
if ( toolTipWindow != null ) {
63+
toolTipWindow.Dispose();
64+
toolTipWindow = null;
65+
}
66+
5767
session.Dismissed += OnSessionDismissed;
5868

5969
if ( toolTipWindow == null ) {

src/Viasfora.Rainbow/Util/ToolTipWindow.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
using System.ComponentModel.Composition;
33
using System.Windows;
44
using System.Windows.Controls;
5+
using System.Windows.Media;
56
using Microsoft.VisualStudio.Text;
67
using Microsoft.VisualStudio.Text.Editor;
78
using Microsoft.VisualStudio.Text.Formatting;
89
using Microsoft.VisualStudio.Utilities;
10+
using Winterdom.Viasfora.Contracts;
911
using Winterdom.Viasfora.Rainbow;
1012

1113
namespace Winterdom.Viasfora.Util {
@@ -15,6 +17,8 @@ public class ToolTipWindowProvider : IToolTipWindowProvider {
1517
public ITextEditorFactoryService EditorFactory { get; set; }
1618
[Import]
1719
public IEditorOptionsFactoryService OptionsFactory { get; set; }
20+
[Import]
21+
public IVsFeatures VsFeatures { get; set; }
1822

1923
public IToolTipWindow CreateToolTip(ITextView textView) {
2024
return new ToolTipWindow(textView, this);
@@ -85,7 +89,7 @@ private void ScrollIntoView(SnapshotPoint bufferPosition) {
8589
return;
8690
}
8791
this.tipView.DisplayTextLineContainingBufferPosition(
88-
viewPos, this.tipView.LineHeight, ViewRelativePosition.Top
92+
viewPos, 2 * this.tipView.LineHeight, ViewRelativePosition.Top
8993
);
9094
SetViewportLeft();
9195
// it could very well be that after this
@@ -139,6 +143,13 @@ private void CreateTipView() {
139143
options.SetOptionValue(ViewOptions.WordWrapStyleId, WordWrapStyles.None);
140144
options.SetOptionValue(ViewOptions.ViewProhibitUserInput, true);
141145

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

144155
this.tipView.ZoomLevel = GetSourceZoomFactor() * ZoomFactor * 100;
@@ -183,29 +194,19 @@ private void ReleaseView() {
183194
// Returning the EditBuffer as the ViewBuffer appears
184195
// to work around this.
185196
class TipTextViewModel : ITextViewModel {
186-
private ITextView sourceView;
187-
private PropertyCollection properties;
188197

189198
public TipTextViewModel(ITextView source) {
190-
this.sourceView = source;
191-
this.properties = new PropertyCollection();
199+
this.DataBuffer = source.TextViewModel.DataBuffer;
200+
this.DataModel = source.TextViewModel.DataModel;
201+
this.EditBuffer = source.TextViewModel.EditBuffer;
202+
this.Properties = new PropertyCollection();
192203
}
193204

194-
public ITextBuffer DataBuffer {
195-
get { return sourceView.TextViewModel.DataBuffer; }
196-
}
197-
public ITextDataModel DataModel {
198-
get { return sourceView.TextViewModel.DataModel; }
199-
}
200-
public ITextBuffer EditBuffer {
201-
get { return sourceView.TextViewModel.EditBuffer; }
202-
}
203-
public ITextBuffer VisualBuffer {
204-
get { return this.EditBuffer; }
205-
}
206-
public PropertyCollection Properties {
207-
get { return this.properties; }
208-
}
205+
public ITextBuffer DataBuffer { get; private set; }
206+
public ITextDataModel DataModel { get; private set; }
207+
public ITextBuffer EditBuffer { get; private set; }
208+
public ITextBuffer VisualBuffer => this.EditBuffer;
209+
public PropertyCollection Properties { get; private set; }
209210

210211
public SnapshotPoint GetNearestPointInVisualBuffer(SnapshotPoint editBufferPoint) {
211212
// editBufferPoint MUST be in the editBuffer according to the docs

src/Viasfora.Xml/XmlQuickInfoSource.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.VisualStudio.Text.Operations;
1212
using Microsoft.VisualStudio.Text.Tagging;
1313
using Winterdom.Viasfora.Util;
14+
using System.Windows.Media;
1415

1516
namespace Winterdom.Viasfora.Xml {
1617
internal class XmlQuickInfoSource : IQuickInfoSource {
@@ -60,10 +61,7 @@ private UIElement CreateInfoText(String xmlns, String url) {
6061
});
6162
// set styles in order to support other
6263
// visual studio themes on 2012/2013
63-
var brushKey = VsColors.ToolTipBrushKey;
64-
if ( brushKey != null ) {
65-
textBlock.SetResourceReference(TextBlock.BackgroundProperty, brushKey);
66-
}
64+
textBlock.Background = Brushes.Transparent;
6765
textBlock.SetResourceReference(TextBlock.ForegroundProperty, VsColors.ToolTipTextBrushKey);
6866
hl.SetResourceReference(Hyperlink.ForegroundProperty, VsColors.PanelHyperlinkBrushKey);
6967
return textBlock;

src/Viasfora/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
55
<Metadata>
66
<Identity Id="Winterdom.Viasfora.f7a33795-2b40-4125-856c-89b0bd8cd5ab"
7-
Version="3.8"
7+
Version="3.9"
88
Language="en-US"
99
Publisher="Tomas Restrepo" />
1010
<DisplayName>Viasfora</DisplayName>

tests/Viasfora.Tests/BraceScanners/CBraceScannerTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public void CanExtractBracesFollowingCpp14QuoteInIntLiteral() {
3434
Assert.Equal(4, chars.Count);
3535
}
3636
[Fact]
37+
public void CanExtractBracesFollowingCpp14QuoteInHexLiteral() {
38+
String input = @"if ( x == 0xFF'000 ) { }";
39+
var extractor = new CBraceScanner();
40+
var chars = Extract(extractor, input.Trim(), 0, 0);
41+
Assert.Equal(4, chars.Count);
42+
}
43+
[Fact]
3744
public void CanExtractBracesFollowingCpp14QuoteInIntLiteralHex() {
3845
String input = @"if ( x == 0x80'00 ) { }";
3946
var extractor = new CBraceScanner();

0 commit comments

Comments
 (0)