Skip to content

Commit 1af61c3

Browse files
committed
! Used another method to keep trigger point of Quick Info
1 parent 5a20da8 commit 1af61c3

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

Codist/Helpers/SymbolFormatter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,6 @@ void NodeLink_Unloaded(object sender, RoutedEventArgs e) {
11481148
}
11491149

11501150
async void NodeLink_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {
1151-
QuickInfo.QuickInfoOverrider.KeepTriggerPoint(this);
1152-
11531151
var s = (await TextEditorHelper.GetMouseOverDocumentView()?.TextBuffer.GetDocument().Project.GetCompilationAsync()).GetSemanticModel(_Node.SyntaxTree)
11541152
.GetSymbol(_Node);
11551153
s?.GoToDefinition();

Codist/Helpers/TextEditorHelper.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,21 @@ public static void ExecuteEditorCommand(string command, string args = "") {
522522
/// <see cref="InternalOpenFile"/>.</para>
523523
/// <para>So <i>Navigate Backward</i> command will restore the caret position to that point.</para>
524524
/// </summary>
525-
/// <param name="position"></param>
526-
public static void KeepViewPosition(int position) {
527-
_ActiveViewPosition = position;
525+
public static void KeepViewPosition(this Microsoft.VisualStudio.Language.Intellisense.IAsyncQuickInfoSession session) {
526+
if (session.TextView is IWpfTextView v) {
527+
_ActiveTextView = v;
528+
_ActiveViewPosition = session.GetTriggerPoint(v.TextSnapshot)?.Position ?? -1;
529+
session.StateChanged += QuickInfoSession_StateChanged;
530+
}
528531
}
532+
533+
static void QuickInfoSession_StateChanged(object sender, Microsoft.VisualStudio.Language.Intellisense.QuickInfoSessionStateChangedEventArgs e) {
534+
if (e.NewState == Microsoft.VisualStudio.Language.Intellisense.QuickInfoSessionState.Dismissed) {
535+
ForgetViewPosition();
536+
((Microsoft.VisualStudio.Language.Intellisense.IAsyncQuickInfoSession)sender).StateChanged -= QuickInfoSession_StateChanged;
537+
}
538+
}
539+
529540
public static void ForgetViewPosition() {
530541
_ActiveViewPosition = -1;
531542
}

Codist/Helpers/WpfHelper.VS.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,13 @@ async void LinkContextMenu(object sender, MouseButtonEventArgs e) {
233233
ContextMenu = m;
234234
m.IsOpen = true;
235235
Highlight(this, e);
236-
QuickInfo.QuickInfoOverrider.KeepTriggerPoint(this);
237236
}
238237
e.Handled = true;
239238
}
240239
}
241240

242241
void DismissQuickInfo(object sender, RoutedEventArgs e) {
243242
(sender as CSharpSymbolContextMenu).Closed -= DismissQuickInfo;
244-
TextEditorHelper.ForgetViewPosition();
245243
QuickInfo.QuickInfoOverrider.HoldQuickInfo(this, false);
246244
QuickInfo.QuickInfoOverrider.DismissQuickInfo(this);
247245
}
@@ -322,7 +320,6 @@ async void LinkContextMenu(object sender, MouseButtonEventArgs e) {
322320
m.Closed += DismissQuickInfo;
323321
ContextMenu = m;
324322
m.IsOpen = true;
325-
QuickInfo.QuickInfoOverrider.KeepTriggerPoint(this);
326323
Highlight(this, e);
327324
}
328325
e.Handled = true;
@@ -331,7 +328,6 @@ async void LinkContextMenu(object sender, MouseButtonEventArgs e) {
331328

332329
void DismissQuickInfo(object sender, RoutedEventArgs e) {
333330
(sender as CSharpSymbolContextMenu).Closed -= DismissQuickInfo;
334-
TextEditorHelper.ForgetViewPosition();
335331
QuickInfo.QuickInfoOverrider.HoldQuickInfo(this, false);
336332
QuickInfo.QuickInfoOverrider.DismissQuickInfo(this);
337333
}
@@ -344,7 +340,6 @@ void Leave(object sender, MouseEventArgs e) {
344340
}
345341

346342
void GotoSymbol(object sender, RoutedEventArgs e) {
347-
QuickInfo.QuickInfoOverrider.KeepTriggerPoint(this);
348343
_Symbol.GoToDefinition();
349344
QuickInfo.QuickInfoOverrider.DismissQuickInfo(this);
350345
e.Handled = true;

Codist/Helpers/WpfHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static partial class WpfHelper
2929
internal static readonly Thickness TopItemMargin = new Thickness(0, 3, 0, 0);
3030
internal static readonly Thickness SmallHorizontalMargin = new Thickness(SmallMarginSize, 0, SmallMarginSize, 0);
3131
internal static readonly Thickness SmallVerticalMargin = new Thickness(0, SmallMarginSize, 0, SmallMarginSize);
32+
internal static readonly Thickness MiddleHorizontalMargin = new Thickness(6, 0, 6, 0);
3233
internal static readonly Thickness MiddleVerticalMargin = new Thickness(0, 6, 0, 6);
3334
internal static readonly Thickness MenuItemMargin = new Thickness(6, 0, 6, 0);
3435

Codist/QuickInfo/CSharpQuickInfo.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ async Task<QuickInfoItem> InternalGetQuickInfoItemAsync(IAsyncQuickInfoSession s
126126
case SyntaxKind.OrderByKeyword:
127127
symbol = semanticModel.GetTypeInfo(unitCompilation.FindNode(token.Span)).ConvertedType;
128128
if (symbol == null) {
129-
if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.Parameter)) {
130-
break;
131-
}
132-
return null;
129+
if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.Parameter)) {
130+
break;
131+
}
132+
return null;
133133
}
134134
break;
135135
case SyntaxKind.AsKeyword:
@@ -141,7 +141,7 @@ async Task<QuickInfoItem> InternalGetQuickInfoItemAsync(IAsyncQuickInfoSession s
141141
break;
142142
case SyntaxKind.ReturnKeyword:
143143
var tb = ShowReturnInfo(unitCompilation.FindNode(token.Span) as ReturnStatementSyntax, semanticModel, cancellationToken);
144-
return tb != null ? new QuickInfoItem(token.Span.CreateSnapshotSpan(currentSnapshot).ToTrackingSpan(), tb) : null;
144+
return tb != null ? CreateQuickInfoItem(session, token, tb) : null;
145145
case SyntaxKind.AwaitKeyword:
146146
node = (unitCompilation.FindNode(token.Span, false, true) as AwaitExpressionSyntax)?.Expression;
147147
goto PROCESS;
@@ -173,7 +173,7 @@ async Task<QuickInfoItem> InternalGetQuickInfoItemAsync(IAsyncQuickInfoSession s
173173
.SetGlyph(ThemeHelper.GetImage(IconIds.Region))
174174
.Append((unitCompilation.FindNode(token.Span, true, false) as EndRegionDirectiveTriviaSyntax).GetRegion()?.GetDeclarationSignature(), true)
175175
);
176-
return new QuickInfoItem(currentSnapshot.CreateTrackingSpan(token.SpanStart, token.Span.Length, SpanTrackingMode.EdgeInclusive), qiContent.ToUI());
176+
return CreateQuickInfoItem(session, token, qiContent.ToUI());
177177
case SyntaxKind.VoidKeyword:
178178
return null;
179179
case SyntaxKind.TypeOfKeyword:
@@ -197,7 +197,7 @@ async Task<QuickInfoItem> InternalGetQuickInfoItemAsync(IAsyncQuickInfoSession s
197197
ShowBlockInfo(qiContent, currentSnapshot, node, semanticModel);
198198
}
199199
if (qiContent.Count > 0) {
200-
return new QuickInfoItem(currentSnapshot.CreateTrackingSpan(token.SpanStart, token.Span.Length, SpanTrackingMode.EdgeInclusive), qiContent.ToUI());
200+
return CreateQuickInfoItem(session, token, qiContent.ToUI());
201201
}
202202
return null;
203203
}
@@ -292,9 +292,14 @@ async Task<QuickInfoItem> InternalGetQuickInfoItemAsync(IAsyncQuickInfoSession s
292292
}
293293
qiWrapper.ApplyClickAndGo(symbol, buffer, session);
294294
}
295-
return new QuickInfoItem((qiContent.Count > 0 || symbol != null && Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.AlternativeStyle)) && session.TextView.TextSnapshot == currentSnapshot
296-
? currentSnapshot.CreateTrackingSpan(token.SpanStart, token.Span.Length, SpanTrackingMode.EdgeExclusive)
297-
: null, qiContent.ToUI());
295+
return CreateQuickInfoItem(session, (qiContent.Count > 0 || symbol != null && Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.AlternativeStyle)) && session.TextView.TextSnapshot == currentSnapshot
296+
? token
297+
: (SyntaxToken?)null, qiContent.ToUI());
298+
}
299+
300+
static QuickInfoItem CreateQuickInfoItem(IAsyncQuickInfoSession session, SyntaxToken? token, object item) {
301+
session.KeepViewPosition();
302+
return new QuickInfoItem(token?.Span.CreateSnapshotSpan(session.TextView.TextSnapshot).ToTrackingSpan(), item);
298303
}
299304

300305
static async Task<ThemedTipDocument> ShowAvailabilityAsync(Document doc, SyntaxToken token, CancellationToken cancellationToken) {
@@ -343,6 +348,8 @@ static ISymbol GetSymbol(SemanticModel semanticModel, SyntaxNode node, ref Immut
343348
|| node.Parent.IsKind(SyntaxKind.DeclarationPattern)
344349
|| node.Parent.IsKind(SyntaxKind.ParenthesizedVariableDesignation))
345350
? semanticModel.GetDeclaredSymbol(node, cancellationToken)
351+
// : kind == SyntaxKind.ArrowExpressionClause
352+
// ? semanticModel.GetDeclaredSymbol(node.Parent, cancellationToken)
346353
: kind == SyntaxKind.IdentifierName && node.Parent.IsKind(SyntaxKind.NameEquals) && (node = node.Parent.Parent) != null && node.IsKind(SyntaxKind.UsingDirective)
347354
? semanticModel.GetDeclaredSymbol(node, cancellationToken)?.GetAliasTarget()
348355
: semanticModel.GetSymbolExt(node, cancellationToken));

Codist/QuickInfo/QuickInfoOverrider.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public static void DismissQuickInfo(DependencyObject quickInfoItem) {
4848
FindHolder(quickInfoItem)?.DismissAsync();
4949
}
5050

51-
public static void KeepTriggerPoint(DependencyObject quickInfoItem) {
52-
FindHolder(quickInfoItem)?.KeepTriggerPoint();
53-
}
54-
5551
static IQuickInfoHolder FindHolder(DependencyObject quickInfoItem) {
5652
var items = quickInfoItem.GetParent<ItemsControl>(i => i.GetType().Name == "WpfToolTipItemsControl");
5753
// version 16.1 or above
@@ -192,7 +188,6 @@ void RemoveSymbolHighlight(object sender, MouseEventArgs e) {
192188
}
193189

194190
async void GoToSource(object sender, MouseButtonEventArgs e) {
195-
FindHolder(e.Source as DependencyObject)?.KeepTriggerPoint();
196191
var s = _symbol;
197192
await _quickInfoSession.DismissAsync();
198193
s.GoToDefinition();
@@ -262,7 +257,6 @@ void QuickInfoSession_StateChanged(object sender, QuickInfoSessionStateChangedEv
262257

263258
interface IQuickInfoHolder
264259
{
265-
void KeepTriggerPoint();
266260
void Hold(bool hold);
267261
System.Threading.Tasks.Task DismissAsync();
268262
}
@@ -328,9 +322,6 @@ sealed class OverriderControl : StackPanel, IInteractiveQuickInfoContent, IQuick
328322
public bool KeepQuickInfoOpen { get; set; }
329323
public bool IsMouseOverAggregated { get; set; }
330324

331-
public void KeepTriggerPoint() {
332-
TextEditorHelper.KeepViewPosition(QuickInfoSession.ApplicableToSpan.GetStartPoint(QuickInfoSession.TextView.TextSnapshot));
333-
}
334325
public void Hold(bool hold) {
335326
IsMouseOverAggregated = hold;
336327
}

0 commit comments

Comments
 (0)