Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/VisualStudio/LanguageService/Commands/GotoDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ internal static void GotoDefn(ITextView TextView)
var result = TextView.GetSymbolUnderCursor(out var state,out _, out _);
//
ThreadHelper.ThrowIfNotOnUIThread();
if (result.Count > 0)
if (result.Count == 1)
{
Goto(result[0], TextView, state);
return;
}
if (result.Count > 1)
{
var window = new GotoDefinitionResultsWindow(result, TextView, state);
window.Show();
return;
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -148,7 +154,15 @@ private static XSourceEntity FindElementInFile(XFile file, XPETypeSymbol petype,
{
if (entity.Name == element.Name)
{
return entity;
if (entity is IXMemberSymbol m1 && element is IXMemberSymbol m2)
{
if (m1.Prototype == m2.Prototype)
return entity;
}
else if (entity.FullName == element.FullName)
{
return entity;
}
}
}
}
Expand Down
33 changes: 16 additions & 17 deletions src/VisualStudio/LanguageService/Completion/CompletionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using XSharpModel;
Expand All @@ -19,14 +20,12 @@ namespace XSharp.LanguageService
{
internal class CompletionHelpers
{
internal IGlyphService _glyphService = null;
private XDialect _dialect;
private XFile _file;
private bool _settingIgnoreCase;
internal CompletionHelpers(XDialect dialect, IGlyphService glyphService, XFile file, bool ignoreCase)
internal CompletionHelpers(XDialect dialect, XFile file, bool ignoreCase)
{
_dialect = dialect;
_glyphService = glyphService;
_file = file;
_settingIgnoreCase = ignoreCase;
}
Expand Down Expand Up @@ -94,7 +93,7 @@ internal void AddPETypeNamesLike(XCompletionList compList, XSharpSearchLocation
continue;
var typeAnalysis = new XTypeAnalysis(type);

ImageSource icon = _glyphService.GetGlyph(type.getGlyphGroup(), type.getGlyphItem());
ImageSource icon = type.Kind.GetImageMoniker(type.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(displayName, displayName, typeAnalysis.Prototype, icon, null, Kind.Class, "")))
break;
}
Expand All @@ -120,7 +119,7 @@ internal void AddSourceTypeNamesLike(XCompletionList compList, XSharpSearchLocat
continue;
var typeAnalysis = new XTypeAnalysis(type);

ImageSource icon = _glyphService.GetGlyph(type.getGlyphGroup(), type.getGlyphItem());
ImageSource icon = type.Kind.GetImageMoniker(type.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(displayName, displayName, typeAnalysis.Prototype, icon, null, Kind.Class, "")))
break;
}
Expand Down Expand Up @@ -182,7 +181,7 @@ internal void AddXSharpKeywordsLike(XCompletionList compList, string startWith)
{
foreach (var kw in XSharpSyntax.GetKeywords().Where(ti => nameStartsWith(ti.Name, startWith)))
{
ImageSource icon = _glyphService.GetGlyph(kw.getGlyphGroup(), kw.getGlyphItem());
ImageSource icon = kw.Kind.GetImageMoniker(kw.Visibility).GetImageSource();
var item = new XSCompletion(kw.Name, kw.Name, kw.Prototype, icon, null, Kind.Keyword, "");
compList.Add(item);
}
Expand All @@ -192,7 +191,7 @@ internal void AddSnippets(XCompletionList compList, string startWith)
var snippets = SnippetHelpers.FindSnippets(startWith);
foreach (var snippet in snippets)
{
ImageSource icon = _glyphService.GetGlyph(StandardGlyphGroup.GlyphCSharpExpansion, StandardGlyphItem.GlyphItemPublic);
ImageSource icon = KnownMonikers.Snippet.GetImageSource();
var item = new XSCompletion(snippet.title, "", snippet.description, icon, null, Kind.Snippet, snippet.shortcut);
item.Properties.AddProperty(typeof(VsExpansion), snippet);
compList.Add(item,false, true);
Expand All @@ -210,7 +209,7 @@ internal void AddXSharpTypeNamesLike(XCompletionList compList, XSharpSearchLocat
continue;

// Then remove it
ImageSource icon = _glyphService.GetGlyph(typeInfo.getGlyphGroup(), typeInfo.getGlyphItem());
ImageSource icon = typeInfo.Kind.GetImageMoniker(typeInfo.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(typeInfo.Name, typeInfo.Name, typeInfo.FullName, icon, null, typeInfo.Kind, "")))
break;
}
Expand All @@ -237,7 +236,7 @@ internal void AddXSharpKeywordTypeNamesLike(XCompletionList compList, string sta
// Then remove it
if (dotPos > 0)
realTypeName = realTypeName.Substring(0, dotPos);
ImageSource icon = _glyphService.GetGlyph(typeInfo.getGlyphGroup(), typeInfo.getGlyphItem());
ImageSource icon = typeInfo.Kind.GetImageMoniker(typeInfo.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(realTypeName, realTypeName, typeInfo.Prototype, icon, null, Kind.Class, "")))
break;
}
Expand Down Expand Up @@ -334,8 +333,8 @@ internal void AddNamespacesLike(XCompletionList compList, XSharpSearchLocation l
int dotPos = startWith.LastIndexOf('.');
if (dotPos != -1)
startLen = dotPos + 1;
ImageSource icon = _glyphService.GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic);
ImageSource iconClass = _glyphService.GetGlyph(StandardGlyphGroup.GlyphGroupClass, StandardGlyphItem.GlyphItemPublic);
ImageSource icon = KnownMonikers.Namespace.GetImageSource();
ImageSource iconClass = KnownMonikers.ClassPublic.GetImageSource();
foreach (string nameSpace in namespaces.Where(ns => nameStartsWith(ns, startWith)))
{
string displayName = nameSpace;
Expand Down Expand Up @@ -408,15 +407,15 @@ internal void AddGenericLocalsLike(XCompletionList compList, XSharpSearchLocatio
// First, look after Parameters
foreach (var paramVar in location.Member.Parameters.Where(p => nameStartsWith(p.Name, startWith)))
{
ImageSource icon = _glyphService.GetGlyph(paramVar.getGlyphGroup(), paramVar.getGlyphItem());
ImageSource icon = paramVar.Kind.GetImageMoniker(paramVar.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(paramVar.Name, paramVar.Name, paramVar.Prototype, icon, null, Kind.Parameter, "")))
break;
}
// Then, look for Locals
// line numbers in the range are 1 based. currentLine = 0 based !
foreach (var localVar in location.Member.GetLocals(location).Where(l => nameStartsWith(l.Name, startWith) && l.Range.StartLine <= location.LineNumber))
{
ImageSource icon = _glyphService.GetGlyph(localVar.getGlyphGroup(), localVar.getGlyphItem());
ImageSource icon = localVar.Kind.GetImageMoniker(localVar.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(localVar.Name, localVar.Name, localVar.Prototype, icon, null, Kind.Local, "")))
break;

Expand All @@ -440,7 +439,7 @@ internal void AddGenericSelfMembersLike(XCompletionList compList, XSharpSearchLo
return;
foreach (var member in type.GetMembers(startWith))
{
ImageSource icon = _glyphService.GetGlyph(member.getGlyphGroup(), member.getGlyphItem());
ImageSource icon = member.Kind.GetImageMoniker(member.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(member.Name, member.Name, member.Prototype, icon, null, Kind.Field, "")))
break;
}
Expand All @@ -465,7 +464,7 @@ internal void AddGenericInheritedMembersLike(XCompletionList compList, XSharpSea
return;
foreach (var member in baseType.GetMembers(startWith))
{
ImageSource icon = _glyphService.GetGlyph(member.getGlyphGroup(), member.getGlyphItem());
ImageSource icon = member.Kind.GetImageMoniker(member.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(member.Name, member.Name, member.Prototype, icon, null, Kind.Field, "")))
break;
}
Expand Down Expand Up @@ -578,7 +577,7 @@ internal void FillEnumMembers(XSharpSearchLocation location, XCompletionList com
continue;
if (elt is XPESymbol peSym && peSym.IsSpecialName)
continue;
ImageSource icon = _glyphService.GetGlyph(elt.getGlyphGroup(), elt.getGlyphItem());
ImageSource icon = elt.Kind.GetImageMoniker(elt.Visibility).GetImageSource();
if (!compList.Add(new XSCompletion(elt.Name, elt.Name, elt.Prototype, icon, null, elt.Kind, elt.Value)))
break;
}
Expand Down Expand Up @@ -638,7 +637,7 @@ internal void FillMembers(XSharpSearchLocation location, XCompletionList compLis
if (!add)
continue;
//
ImageSource icon = _glyphService.GetGlyph(elt.getGlyphGroup(), elt.getGlyphItem());
ImageSource icon = elt.Kind.GetImageMoniker(elt.Visibility).GetImageSource();
string toAdd = AddOpenParen(elt.Kind);
if (!compList.Add(new XSCompletion(elt.Name, elt.Name + toAdd, elt.Prototype, icon, null, elt.Kind, elt.Value)))
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public XSharpCompletionSource(XSharpCompletionSourceProvider provider, ITextBuff
_file = file;
var prj = _file.Project.ProjectNode;
_dialect = _file.Project.Dialect;
helpers = new CompletionHelpers(_dialect, provider.GlyphService, file, !prj.ParseOptions.CaseSensitive);
helpers = new CompletionHelpers(_dialect, file, !prj.ParseOptions.CaseSensitive);
this._tagAggregator = aggregator.CreateTagAggregator<IClassificationTag>(_buffer);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.VisualStudio.Utilities;
using XSharpModel;
using Microsoft.VisualStudio.Shell;
using System.Windows.Media;
using LanguageService.SyntaxTree;
using LanguageService.CodeAnalysis.XSharp.SyntaxParser;
using Microsoft.VisualStudio;
Expand All @@ -29,9 +28,6 @@ class XSharpCompletionSourceProvider : ICompletionSourceProvider
[Import]
internal SVsServiceProvider ServiceProvider = null;

[Import]
internal IGlyphService GlyphService = null;

[Import]
IBufferTagAggregatorFactoryService aggregator = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
// See License.txt in the project root for license information.
//
using Community.VisualStudio.Toolkit;

using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.Shell;

using System;
using System.Collections.Generic;
using System.Data.Common;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.VisualStudio.TextManager.Interop;
using XSharpModel;

Expand All @@ -33,33 +28,6 @@ sealed partial class DocumentOutlineControl : UserControl
private bool _navigating; // reentrancy guard
private bool _sortByName; // false = sort by document order (default)

// -----------------------------------------------------------------------
// Image source cache: maps glyph index -> ImageSource
// -----------------------------------------------------------------------
private static readonly Dictionary<int, ImageSource> _glyphCache = new Dictionary<int, ImageSource>();
private static System.Windows.Forms.ImageList _imageList;

static DocumentOutlineControl()
{
_imageList = new System.Windows.Forms.ImageList
{
ImageSize = new System.Drawing.Size(16, 16),
TransparentColor = System.Drawing.Color.FromArgb(255, 0, 255)
};
try
{
Stream stream = typeof(Microsoft.VisualStudio.Package.LanguageService)
.Assembly
.GetManifestResourceStream("Resources.completionset.bmp");
if (stream != null)
_imageList.Images.AddStrip(new System.Drawing.Bitmap(stream));
}
catch (Exception)
{
// If images cannot be loaded the tree will still work without icons.
}
}

// -----------------------------------------------------------------------
// Construction
// -----------------------------------------------------------------------
Expand Down Expand Up @@ -155,7 +123,7 @@ private OutlineTreeNode CreateNode(XSourceEntity entity)
string label = entity.ComboPrototype;
if (string.IsNullOrEmpty(label))
label = entity.Name;
return new OutlineTreeNode(entity, label, GetGlyphImage(entity.Glyph));
return new OutlineTreeNode(entity, label, entity.Kind.GetImageMoniker(entity.Visibility));
}

private void AddMemberNodes(OutlineTreeNode parentNode, XSourceTypeSymbol type)
Expand Down Expand Up @@ -209,48 +177,6 @@ private static void FindBestNode(OutlineTreeNode node, int line, ref OutlineTree
FindBestNode(child, line, ref best, ref bestLength);
}

// -----------------------------------------------------------------------
// Glyph -> ImageSource conversion
// -----------------------------------------------------------------------
private static ImageSource GetGlyphImage(int glyphIndex)
{
if (_imageList == null || glyphIndex < 0 || glyphIndex >= _imageList.Images.Count)
return null;

if (_glyphCache.TryGetValue(glyphIndex, out var cached))
return cached;

var bmp = _imageList.Images[glyphIndex] as System.Drawing.Bitmap;
if (bmp == null)
return null;

ImageSource source;
try
{
var handle = bmp.GetHbitmap();
try
{
source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
handle,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
source.Freeze();
}
finally
{
NativeMethods.DeleteObject(handle);
}
}
catch (Exception)
{
return null;
}

_glyphCache[glyphIndex] = source;
return source;
}

// -----------------------------------------------------------------------
// Event handlers
// -----------------------------------------------------------------------
Expand Down Expand Up @@ -376,22 +302,19 @@ internal sealed class OutlineTreeNode : TreeViewItem
{
public XSourceEntity Entity { get; }

public OutlineTreeNode(XSourceEntity entity, string label, ImageSource icon)
public OutlineTreeNode(XSourceEntity entity, string label, ImageMoniker moniker)
{
Entity = entity;

var panel = new StackPanel { Orientation = Orientation.Horizontal };
if (icon != null)
panel.Children.Add(new CrispImage
{
panel.Children.Add(new System.Windows.Controls.Image
{
Source = icon,
Width = 16,
Height = 16,
Margin = new Thickness(0, 0, 4, 0),
VerticalAlignment = VerticalAlignment.Center
});
}
Moniker = moniker,
Width = 16,
Height = 16,
Margin = new Thickness(0, 0, 4, 0),
VerticalAlignment = VerticalAlignment.Center
});
panel.Children.Add(new TextBlock
{
Text = label,
Expand All @@ -401,15 +324,5 @@ public OutlineTreeNode(XSourceEntity entity, string label, ImageSource icon)
Header = panel;
}
}

// ---------------------------------------------------------------------------
// P/Invoke helper for bitmap conversion
// ---------------------------------------------------------------------------
internal static class NativeMethods
{
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
internal static extern bool DeleteObject(IntPtr hObject);
}
}

Loading