Skip to content

Commit ea47df1

Browse files
[Vsintegration] Resolving a field from a sourcetype can also return a System.Type. Also resolve exception when there are no entities found when finding ExtensionMethods.
1 parent 29546d0 commit ea47df1

File tree

10 files changed

+42
-28
lines changed

10 files changed

+42
-28
lines changed

src/VisualStudio/LanguageService/Generic/DropDownClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class XSharpDropDownClient : IVsDropdownBarClient
6363
readonly List<XDropDownMember> _members = null;
6464
readonly Dictionary<string, int> _membersDict = null; // to speed up the lookup of members
6565
readonly List<XDropDownMember> _types = null;
66-
readonly List<XProject> _projects = null;
66+
readonly List<XProject> _projects = null;
6767
XFile _file = null;
6868
uint _lastHashCode = 0;
6969
private int _lastLine;
@@ -164,7 +164,7 @@ internal void addTextView(ITextView textView, IVsTextView textViewAdapter)
164164
textView.LostAggregateFocus += TextView_LostAggregateFocus;
165165
textView.Closed += TextView_Closed;
166166
StartOnIdleAsync(textViewAdapter).FireAndForget();
167-
167+
168168

169169
}
170170
}
@@ -412,7 +412,7 @@ private IList<XSourceEntity> GetTypeMembers(XSourceTypeSymbol type)
412412
// Load members from all partial type definitions inside this project
413413
var usings = new List<string>();
414414
usings.Add(type.Namespace);
415-
var fullType = _file.Project.Lookup(type.Name, usings);
415+
var fullType = _file.Project.Lookup(type.Name, usings) as XSourceTypeSymbol;
416416
if (fullType != null)
417417
{
418418
members.AddRange(fullType.XMembers);
@@ -472,7 +472,7 @@ private IList<XSourceEntity> GetAllMembers()
472472
// load methods from other files
473473
var usings = new List<string>();
474474
usings.Add(xType.Namespace);
475-
var fullType = _file.Project.Lookup(xType.Name, usings);
475+
var fullType = _file.Project.Lookup(xType.Name, usings) as XSourceTypeSymbol;
476476
if (fullType != null)
477477
{
478478
foreach (var member in fullType.XMembers)
@@ -838,7 +838,7 @@ public int GetEntryImage(int combo, int index, out int imageIndex)
838838
imageIndex = _members[index].Glyph;
839839
break;
840840
case PROJECTINDEX: // projects
841-
imageIndex = projectIcon;
841+
imageIndex = projectIcon;
842842
break;
843843
default:
844844
throw new ArgumentOutOfRangeException();

src/VisualStudio/ProjectPackage/Nodes/XSharpProjectNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ public IXTypeSymbol ResolveExternalType(string name, IList<string> usings)
19141914
public XSourceTypeSymbol ResolveXType(string name, IList<string> usings)
19151915
{
19161916
var model = this.ProjectModel;
1917-
XSourceTypeSymbol result = model.Lookup(name, usings);
1917+
XSourceTypeSymbol result = model.Lookup(name, usings) as XSourceTypeSymbol;
19181918
if (result != null)
19191919
return result;
19201920
return result;

src/VisualStudio/XSharpCodeModelXs/Model/Interfaces.prg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ BEGIN NAMESPACE XSharpModel
6969
PROPERTY TypeParameters AS IList<STRING> GET
7070
PROPERTY DeclaringType AS STRING GET
7171
PROPERTY IsExtension AS LOGIC GET
72+
METHOD Resolve() as VOID
7273
PROPERTY XMLSignature AS STRING GET
7374
PROPERTY OriginalTypeName AS STRING GET
7475
PROPERTY IsGeneric AS LOGIC GET

src/VisualStudio/XSharpCodeModelXs/PE/XPEMemberSymbol.prg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ABSTRACT CLASS XPEMemberSymbol INHERIT XPESymbol IMPLEMENTS IXMemberSymbol
3535

3636
#endregion
3737

38-
PROTECTED INTERNAL VIRTUAL METHOD Resolve() AS VOID
38+
PUBLIC VIRTUAL METHOD Resolve() AS VOID
3939
IF SELF:_custatts != NULL
4040
FOREACH VAR custatt IN SELF:_custatts
4141
SWITCH custatt:AttributeType:FullName

src/VisualStudio/XSharpCodeModelXs/PE/XPEMethodSymbol.prg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CLASS XPEMethodSymbol INHERIT XPEMemberSymbol
8888
SELF:_signature:ReadGenericParameters(def:GenericParameters)
8989
ENDIF
9090
SELF:IsSpecialName := def:IsSpecialName
91-
PROTECTED INTERNAL OVERRIDE METHOD Resolve() AS VOID
91+
PUBLIC OVERRIDE METHOD Resolve() AS VOID
9292
IF ! _resolved .and. _methoddef != NULL
9393
// Add Generic parameters first so have that info when processing the parameters
9494
IF _methoddef:HasGenericParameters

src/VisualStudio/XSharpCodeModelXs/ProjectSystem/XProject.prg

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ BEGIN NAMESPACE XSharpModel
979979
RETURN myusings:ToList()
980980

981981

982-
PRIVATE _lastFound := NULL AS XSourceTypeSymbol
982+
PRIVATE _lastFound := NULL AS IXTypeSymbol
983983
PRIVATE _lastName := NULL AS STRING
984984

985985
METHOD GetTypesLike( startWith AS STRING, usings AS IList<STRING>) AS IList<XSourceTypeSymbol>
@@ -1015,11 +1015,11 @@ BEGIN NAMESPACE XSharpModel
10151015
endif
10161016
RETURN result
10171017

1018-
METHOD Lookup(typeName AS STRING) AS XSourceTypeSymbol
1018+
METHOD Lookup(typeName AS STRING) AS IXTypeSymbol
10191019
VAR usings := List<STRING>{}
10201020
RETURN SELF:Lookup(typeName, usings)
10211021

1022-
METHOD Lookup(typeName AS STRING, usings AS IList<STRING>) AS XSourceTypeSymbol
1022+
METHOD Lookup(typeName AS STRING, usings AS IList<STRING>) AS IXTypeSymbol
10231023
// lookup Type definition in this project and X# projects referenced by this project
10241024
SELF:LogTypeMessage(i"Lookup {typeName}")
10251025
VAR originalName := typeName
@@ -1051,6 +1051,17 @@ BEGIN NAMESPACE XSharpModel
10511051
var elements := originalName:Split(<char>{'.'})
10521052
var first := SELF:Lookup(elements.First(), usings)
10531053
if first != NULL
1054+
if elements.Length > 1
1055+
var mem := elements[1]
1056+
foreach var m in first.Members
1057+
if String.Equals(m.Name, mem, StringComparison.OrdinalIgnoreCase)
1058+
m.Resolve()
1059+
_lastFound := m.ResolvedType
1060+
return _lastFound
1061+
endif
1062+
next
1063+
endif
1064+
10541065
typeName := first:FullName + "." + typeName
10551066
return SELF:Lookup(typeName, usings)
10561067
endif
@@ -1301,11 +1312,13 @@ BEGIN NAMESPACE XSharpModel
13011312
sb:AppendLine("END CLASS")
13021313
VAR walker := SourceWalker{oFile, FALSE}
13031314
walker:Parse(sb:ToString())
1304-
foreach var entity in walker:EntityList
1305-
if entity is XSourceMemberSymbol var sms
1306-
entities:Add(sms)
1307-
endif
1308-
next
1315+
if (walker:EntityList != null)
1316+
foreach var entity in walker:EntityList
1317+
if entity is XSourceMemberSymbol var sms
1318+
entities:Add(sms)
1319+
endif
1320+
next
1321+
endif
13091322
if entities:Count == list:Count
13101323
FOR var i := 0 to entities:Count-1
13111324
var entity := (XSourceMemberSymbol) entities[i]

src/VisualStudio/XSharpCodeModelXs/Source/XSourceEntity.prg

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ CLASS XSourceEntity INHERIT XSourceSymbol IMPLEMENTS IXSymbol, IXSourceSymbol
5454
METHOD ForceComplete() AS VOID
5555
LOCAL ParentName AS STRING
5656
LOCAL thisName AS STRING
57-
LOCAL tmp AS XSourceTypeSymbol
57+
LOCAL tmp AS IXTypeSymbol
5858

5959
IF SELF:Parent == NULL .AND. ! String.IsNullOrEmpty(SELF:ParentName)
6060

@@ -75,7 +75,14 @@ CLASS XSourceEntity INHERIT XSourceSymbol IMPLEMENTS IXSymbol, IXSourceSymbol
7575
ENDIF
7676
ENDIF
7777
ENDIF
78-
78+
METHOD Resolve() AS VOID
79+
IF SELF:ResolvedType == null
80+
var name := SELF:TypeName
81+
SELF:ResolvedType := SELF:File:FindType(name)
82+
if (SELF:ResolvedType != NULL)
83+
SELF:TypeName := SELF:ResolvedType:FullName
84+
endif
85+
ENDIF
7986

8087
#region Complexer properties
8188
// Properties

src/VisualStudio/XSharpCodeModelXs/Source/XSourceParameterSymbol.prg

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,7 @@ CLASS XSourceParameterSymbol INHERIT XSourceVariableSymbol IMPLEMENTS IXParamete
4040
result += ParamTypeDesc+" "+SELF:TypeName
4141
ENDIF
4242
RETURN result
43-
METHOD Resolve() AS VOID
44-
IF SELF:ResolvedType == null
45-
var name := SELF:TypeName
46-
SELF:ResolvedType := SELF:File:FindType(name)
47-
if (SELF:ResolvedType != NULL)
48-
SELF:TypeName := SELF:ResolvedType:FullName
49-
endif
50-
ENDIF
43+
5144
END CLASS
5245
[DebuggerDisplay("{DebuggerDisplay(),nq}")];
5346
CLASS XSourceTypeParameterSymbol INHERIT XSourceParameterSymbol

src/VisualStudio/XSharpCodeModelXs/Source/XSourceTypeSymbol.prg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ BEGIN NAMESPACE XSharpModel
249249
PROPERTY Clone AS XSourceTypeSymbol
250250
GET
251251
IF SELF:IsPartial .AND. SELF:File != NULL
252-
RETURN SUPER:File:Project:Lookup(SELF:FullName, SELF:File:Usings:ToArray())
252+
RETURN SUPER:File:Project:Lookup(SELF:FullName, SELF:File:Usings:ToArray()) astype XSourceTypeSymbol
253253
ENDIF
254254
RETURN SELF
255255
END GET

src/VisualStudio/XSharpVoEditors/XSharp_WED.prg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ CLASS XSharp_VOWindowEditor INHERIT VOWindowEditor
352352
VAR rootNs := oFile:Project:ProjectNode:RootNameSpace
353353
VAR usings := List<STRING>{}
354354
usings:Add(rootNs)
355-
oType := oProject:Lookup(cClass,usings)
355+
oType := oProject:Lookup(cClass,usings) ASTYPE XSharpModel.XSourceTypeSymbol
356356
IF cName:ToUpper() == "CLASSDECLARATION"
357357
IF (oType != NULL_OBJECT)
358358
oType:OpenEditor()

0 commit comments

Comments
 (0)