Skip to content

Commit

Permalink
- Fixed Quick Info not being dismissed after clicked
Browse files Browse the repository at this point in the history
+ Showed metadata locations for namespaces as well as source code locations
  • Loading branch information
wmjordan committed Jun 3, 2019
1 parent 0891bf4 commit 3abad5d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 32 deletions.
6 changes: 5 additions & 1 deletion Codist/Controls/CSharpSymbolContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,15 @@ internal static void ShowLocations(ISymbol symbol, SemanticContext context) {
var locs = symbol.GetSourceLocations().Sort((x, y) => String.CompareOrdinal(x.SourceTree.FilePath, y.SourceTree.FilePath));
m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
.Append(symbol.ToDisplayString(WpfHelper.MemberNameFormat), true)
.Append(" locations: ")
.Append(" source locations: ")
.Append(locs.Length);
foreach (var loc in locs) {
m.Menu.Add(loc);
}
locs = symbol.Locations.RemoveAll(l => l.IsInMetadata == false).Sort((x, y) => String.CompareOrdinal(x.MetadataModule.Name, y.MetadataModule.Name));
foreach (var loc in locs) {
m.Menu.Add(loc);
}
m.Show();
}
static void ShowSymbolMenuForResult(ISymbol source, SemanticContext context, List<ISymbol> members, string suffix, bool groupByType) {
Expand Down
26 changes: 20 additions & 6 deletions Codist/Controls/SymbolList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,13 @@ async Task<object> CreateItemToolTipAsync(ListBoxItem li) {
return ToolTipFactory.CreateToolTip(item.Symbol, false, SemanticContext.SemanticModel.Compilation);
}
if (item.Location != null) {
return new ThemedToolTip(Path.GetFileName(item.Location.SourceTree.FilePath), $"Folder: {item.Hint}{Environment.NewLine}Line: {item.Location.GetLineSpan().StartLinePosition.Line + 1}");
if (item.Location.IsInSource) {
var p = item.Location.SourceTree.FilePath;
return new ThemedToolTip(Path.GetFileName(p), $"Folder: {Path.GetDirectoryName(p)}{Environment.NewLine}Line: {item.Location.GetLineSpan().StartLinePosition.Line + 1}");
}
else {
return new ThemedToolTip(item.Location.MetadataModule.Name, $"Containing assembly: {item.Location.MetadataModule.ContainingAssembly}");
}
}
return null;
}
Expand Down Expand Up @@ -678,10 +684,18 @@ public SymbolItem(SymbolList list) {
public SymbolItem(Location location, SymbolList list) {
Container = list;
Location = location;
var filePath = location.SourceTree.FilePath;
_Content = new ThemedMenuText(Path.GetFileNameWithoutExtension(filePath)).Append(Path.GetExtension(filePath), ThemeHelper.SystemGrayTextBrush);
_Hint = Path.GetFileName(Path.GetDirectoryName(filePath));
_ImageId = KnownImageIds.CSFile;
if (location.IsInSource) {
var filePath = location.SourceTree.FilePath;
_Content = new ThemedMenuText(Path.GetFileNameWithoutExtension(filePath)).Append(Path.GetExtension(filePath), ThemeHelper.SystemGrayTextBrush);
_Hint = Path.GetFileName(Path.GetDirectoryName(filePath));
_ImageId = KnownImageIds.CSFile;
}
else {
var m = location.MetadataModule;
_Content = new ThemedMenuText(Path.GetFileNameWithoutExtension(m.Name)).Append(Path.GetExtension(m.Name), ThemeHelper.SystemGrayTextBrush);
_Hint = String.Empty;
_ImageId = KnownImageIds.Module;
}
}
public SymbolItem(ISymbol symbol, SymbolList list, ISymbol containerSymbol)
: this (symbol, list, false) {
Expand All @@ -700,7 +714,7 @@ public SymbolItem(SyntaxNode node, SymbolList list) {
}

public void GoToSource() {
if (Location != null) {
if (Location != null && Location.IsInSource) {
Location.GoToSource();
}
else if (Symbol != null) {
Expand Down
2 changes: 1 addition & 1 deletion Codist/QuickInfo/CSharpQuickInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiC
if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.Diagnostics)) {
qiWrapper.SetDiagnostics(semanticModel.GetDiagnostics(token.Span));
}
qiWrapper.ApplyClickAndGo(symbol);
qiWrapper.ApplyClickAndGo(symbol, session);
}
qiWrapper.LimitQuickInfoItemSize(qiContent);
applicableToSpan = qiContent.Count > 0 && session.TextView.TextSnapshot == currentSnapshot
Expand Down
61 changes: 37 additions & 24 deletions Codist/QuickInfo/QuickInfoOverrider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Codist.QuickInfo
interface IQuickInfoOverrider
{
void SetDiagnostics(IList<Diagnostic> diagnostics);
void ApplyClickAndGo(ISymbol symbol);
void ApplyClickAndGo(ISymbol symbol, IQuickInfoSession quickInfoSession);
void LimitQuickInfoItemSize(IList<object> qiContent);
void OverrideDocumentation(UIElement docElement);
void OverrideException(UIElement exceptionDoc);
Expand All @@ -29,10 +29,10 @@ static class QuickInfoOverrider
static readonly SolidColorBrush __HighlightBrush = SystemColors.HighlightBrush.Alpha(0.3);
public static IQuickInfoOverrider CreateOverrider(IList<object> qiContent) {
var o = new Legacy(qiContent);
return o.Panel != null ? o : (IQuickInfoOverrider)new Default(qiContent);
return o.Panel != null ? o : (IQuickInfoOverrider)new Default();
}

static void ApplyClickAndGo(ISymbol symbol, TextBlock description) {
static void ApplyClickAndGo(ISymbol symbol, TextBlock description, IQuickInfoSession quickInfoSession) {
var locs = symbol.GetSourceLocations();
string path;
description.ToolTip = String.Empty;
Expand All @@ -46,36 +46,47 @@ static void ApplyClickAndGo(ISymbol symbol, TextBlock description) {
goto ClickAndGo;
}
}
if (symbol.Kind == SymbolKind.Namespace) {
description.ToolTip = "Locations: " + symbol.Locations.Length;
description.Cursor = Cursors.Hand;
description.MouseEnter += HighlightSymbol;
description.MouseLeave += RemoveSymbolHighlight;
description.MouseLeftButtonUp += ListLocations;
return;
}
var asm = symbol.GetAssemblyModuleName();
if (asm != null) {
path = asm;
description.ToolTipOpening += DescriptionShowToolTip;
description.ToolTipOpening += ShowToolTip;
}
return;
}
ClickAndGo:
path = System.IO.Path.GetFileName(locs[0].SourceTree.FilePath);
description.ToolTipOpening += DescriptionShowToolTip;
description.ToolTipOpening += ShowToolTip;
description.Cursor = Cursors.Hand;
description.MouseEnter += (s, args) => (s as TextBlock).Background = __HighlightBrush;
description.MouseLeave += (s, args) => (s as TextBlock).Background = Brushes.Transparent;
description.MouseEnter += HighlightSymbol;
description.MouseLeave += RemoveSymbolHighlight;
if (locs.Length == 1) {
description.MouseLeftButtonUp += (s, args) => symbol.GoToSource();
return;
}
description.MouseLeftButtonUp += ListMultiLocations;
description.MouseLeftButtonUp += ListLocations;

void ListMultiLocations(object sender, MouseButtonEventArgs e) {
var view = TextEditorHelper.GetMouseOverDocumentView();
if (view == null) {
return;
}
CSharpSymbolContextMenu.ShowLocations(symbol, SemanticContext.GetOrCreateSingetonInstance(view));
void ListLocations(object sender, MouseButtonEventArgs e) {
quickInfoSession.Dismiss();
CSharpSymbolContextMenu.ShowLocations(symbol, SemanticContext.GetOrCreateSingetonInstance(quickInfoSession.TextView as IWpfTextView));
}
void ShowToolTip(object sender, ToolTipEventArgs e) {
var t = sender as TextBlock;
t.ToolTip = ShowSymbolLocation(symbol, path);
t.ToolTipOpening -= ShowToolTip;
}
void HighlightSymbol(object sender, MouseEventArgs e) {
((TextBlock)sender).Background = __HighlightBrush;
}
void DescriptionShowToolTip(object sender, ToolTipEventArgs e) {
var d = sender as TextBlock;
d.ToolTip = ShowSymbolLocation(symbol, path);
d.ToolTipOpening -= DescriptionShowToolTip;
void RemoveSymbolHighlight(object sender, MouseEventArgs e) {
((TextBlock)sender).Background = Brushes.Transparent;
}
}

Expand Down Expand Up @@ -108,12 +119,13 @@ sealed class Default : IQuickInfoOverrider
{
readonly Overrider _Overrider;

public Default(IList<object> qiContent) {
public Default() {
_Overrider = new Overrider();
}

public void ApplyClickAndGo(ISymbol symbol) {
public void ApplyClickAndGo(ISymbol symbol, IQuickInfoSession quickInfoSession) {
_Overrider.ClickAndGoSymbol = symbol;
_Overrider.QuickInfoSession = quickInfoSession;
}

public void LimitQuickInfoItemSize(IList<object> qiContent) {
Expand Down Expand Up @@ -147,6 +159,7 @@ sealed class Overrider : UIElement
public UIElement DocElement;
public UIElement ExceptionDoc;
public IList<Diagnostic> Diagnostics;
public IQuickInfoSession QuickInfoSession;

protected override void OnVisualParentChanged(DependencyObject oldParent) {
base.OnVisualParentChanged(oldParent);
Expand Down Expand Up @@ -288,7 +301,7 @@ void FixQuickInfo(StackPanel infoPanel) {
if (icon != null && signature != null) {
// apply click and go feature
if (ClickAndGoSymbol != null) {
QuickInfoOverrider.ApplyClickAndGo(ClickAndGoSymbol, signature);
QuickInfoOverrider.ApplyClickAndGo(ClickAndGoSymbol, signature, QuickInfoSession);
}
// fix the width of the signature part to prevent it from falling down to the next row
if (Config.Instance.QuickInfoMaxWidth > 0) {
Expand Down Expand Up @@ -442,7 +455,7 @@ public Legacy(IList<object> qiContent) {
public TextBlock Documentation => Panel != null ? __GetDocumentation(Panel) : null;

/// <summary>Hack into the default QuickInfo panel and provides click and go feature for symbols.</summary>
public void ApplyClickAndGo(ISymbol symbol) {
public void ApplyClickAndGo(ISymbol symbol, IQuickInfoSession quickInfoSession) {
if (symbol == null) {
return;
}
Expand All @@ -453,7 +466,7 @@ public void ApplyClickAndGo(ISymbol symbol) {
if (symbol.IsImplicitlyDeclared) {
symbol = symbol.ContainingType;
}
QuickInfoOverrider.ApplyClickAndGo(symbol, description);
QuickInfoOverrider.ApplyClickAndGo(symbol, description, quickInfoSession);
}

/// <summary>
Expand Down Expand Up @@ -502,7 +515,7 @@ public void SetDiagnostics(IList<Diagnostic> diagnostics) {
static StackPanel FindDefaultQuickInfoPanel(IList<object> qiContent) {
foreach (var item in qiContent) {
var o = item as StackPanel;
if (o != null && o.GetType().Name == "QuickInfoDisplayPanel") {
if (o?.GetType().Name == "QuickInfoDisplayPanel") {
return o;
}
}
Expand Down

0 comments on commit 3abad5d

Please sign in to comment.