Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 6dbf7b4

Browse files
committed
Add Doc for inherited methods in methodmaps
1 parent 995a27f commit 6dbf7b4

File tree

8 files changed

+74
-34
lines changed

8 files changed

+74
-34
lines changed

SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMClasslike.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class SMClasslike : SMBaseDefinition
1414
public readonly List<SMObjectField> Fields = new();
1515
public readonly List<SMObjectMethod> Methods = new();
1616

17-
public List<ACNode> ProduceNodes()
17+
public virtual List<ACNode> ProduceNodes(SMDefinition smDef)
1818
{
1919
var nodes = new List<ACNode>();
2020
nodes.AddRange(ACNode.ConvertFromStringList(Methods.Select(e => e.Name), true, "▲ "));
@@ -26,15 +26,15 @@ public List<ACNode> ProduceNodes()
2626
}
2727
}
2828

29-
public abstract class SMObjectMethod : SMBaseDefinition
29+
public class SMObjectMethod : SMBaseDefinition
3030
{
3131
public string ClassName = string.Empty;
3232
public string FullName = string.Empty;
3333
public string ReturnType = string.Empty;
3434
public string[] Parameters = Array.Empty<string>();
3535
}
3636

37-
public abstract class SMObjectField : SMBaseDefinition
37+
public class SMObjectField : SMBaseDefinition
3838
{
3939
public string ClassName = string.Empty;
4040
public string FullName = string.Empty;

SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMEnumStructConsumer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ private int ConsumeSMEnumStruct()
1515
if (position + 4 < length)
1616
{
1717
var enumStructName = string.Empty;
18-
var methods = new List<SMEnumStructMethod>();
19-
var fields = new List<SMEnumStructField>();
18+
var methods = new List<SMObjectMethod>();
19+
var fields = new List<SMObjectField>();
2020
if (t[iteratePosition].Kind == TokenKind.Identifier)
2121
{
2222
enumStructName = t[iteratePosition++].Value;
@@ -198,7 +198,7 @@ private int ConsumeSMEnumStruct()
198198

199199
if (mStartIndex < mEndIndex)
200200
{
201-
methods.Add(new SMEnumStructMethod
201+
methods.Add(new SMObjectMethod
202202
{
203203
Index = mStartIndex,
204204
Name = methodName,
@@ -286,13 +286,13 @@ private int ConsumeSMEnumStruct()
286286

287287
if (fStartIndex < fEndIndex)
288288
{
289-
fields.Add(new SMEnumStructField
289+
fields.Add(new SMObjectField()
290290
{
291291
Index = fStartIndex,
292292
Length = fEndIndex - fStartIndex + 1,
293293
Name = fieldName,
294294
File = FileName,
295-
MethodmapName = enumStructName,
295+
// MethodmapName = enumStructName,
296296
FullName = source.Substring(fStartIndex, fEndIndex - fStartIndex + 1)
297297
});
298298
}

SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMMethodmapConsumer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ private int ConsumeSMMethodmap()
1515
if ((position + 4) < length)
1616
{
1717
var methodMapName = string.Empty;
18-
var methods = new List<SMMethodmapMethod>();
19-
var fields = new List<SMMethodmapField>();
18+
var methods = new List<SMObjectMethod>();
19+
var fields = new List<SMObjectField>();
2020
if (t[iteratePosition].Kind == TokenKind.Identifier)
2121
{
2222
methodMapName = t[iteratePosition].Value;
@@ -202,7 +202,7 @@ private int ConsumeSMMethodmap()
202202
}
203203
if (mStartIndex < mEndIndex)
204204
{
205-
methods.Add(new SMMethodmapMethod()
205+
methods.Add(new SMObjectMethod()
206206
{
207207
Index = mStartIndex,
208208
Name = methodName,
@@ -283,7 +283,7 @@ private int ConsumeSMMethodmap()
283283
}
284284
if (fStartIndex < fEndIndex)
285285
{
286-
fields.Add(new SMMethodmapField
286+
fields.Add(new SMObjectField
287287
{
288288
Index = fStartIndex,
289289
Length = fEndIndex - fStartIndex + 1,

SourcepawnCondenser/SourcepawnCondenser/SourcemodDefinition/SMDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public SMDefinition()
1717
Name = "Handle",
1818
Methods =
1919
{
20-
new SMMethodmapMethod()
20+
new SMObjectMethod()
2121
{
2222
FullName = "(external) void Close()",
2323
ClassName = "Name",

SourcepawnCondenser/SourcepawnCondenser/SourcemodDefinition/SMEnumStruct.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,4 @@ namespace SourcepawnCondenser.SourcemodDefinition
66
public class SMEnumStruct : SMClasslike
77
{
88
}
9-
10-
public class SMEnumStructField : SMObjectField
11-
{
12-
public string MethodmapName = string.Empty;
13-
//public string Type = string.Empty; not needed yet
14-
}
15-
16-
public class SMEnumStructMethod : SMObjectMethod
17-
{
18-
}
199
}

SourcepawnCondenser/SourcepawnCondenser/SourcemodDefinition/SMMethodmap.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,33 @@ namespace SourcepawnCondenser.SourcemodDefinition
66
public class SMMethodmap : SMClasslike
77
{
88
public string InheritedType = string.Empty;
9-
}
109

11-
public class SMMethodmapField : SMObjectField
12-
{
13-
}
10+
public override List<ACNode> ProduceNodes(SMDefinition smDef)
11+
{
12+
var nodes = new List<ACNode>();
13+
nodes.AddRange(ACNode.ConvertFromStringList(Methods.Select(e => e.Name), true, "▲ "));
14+
nodes.AddRange(ACNode.ConvertFromStringList(Fields.Select(e => e.Name), false, "• "));
1415

15-
public class SMMethodmapMethod : SMObjectMethod
16-
{
16+
// Find Fields and Methods inherited from the "super-class".
17+
var inheritedType = InheritedType;
18+
for (;;)
19+
{
20+
if (inheritedType.Length == 0)
21+
break;
22+
23+
var mm = smDef.Methodmaps.Find(e => e.Name == InheritedType);
24+
if (mm == null)
25+
break;
26+
27+
nodes.AddRange(ACNode.ConvertFromStringList(mm.Methods.Select(e => e.Name), true, "▲ "));
28+
nodes.AddRange(ACNode.ConvertFromStringList(mm.Fields.Select(e => e.Name), false, "• "));
29+
30+
inheritedType = mm.InheritedType;
31+
}
32+
33+
nodes.Sort((a, b) => string.CompareOrdinal(a.EntryName, b.EntryName));
34+
35+
return nodes;
36+
}
1737
}
1838
}

UI/Components/EditorElement/EditorElementIntellisenseController.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,20 @@ bool ComputeIntelliSense(string text, int lineOffset)
292292

293293
if (classString.Length > 0)
294294
{
295-
var methodMap = FindClass(classString);
295+
var classObj = FindClass(classString);
296+
297+
SMObjectMethod? method = null;
298+
299+
switch (classObj)
300+
{
301+
case SMEnumStruct:
302+
method = classObj?.Methods.Find(e => e.Name == methodString);
303+
break;
304+
case SMMethodmap obj:
305+
method = FindMethod(methodString, obj, _smDef);
306+
break;
307+
}
296308

297-
var method = methodMap?.Methods.FirstOrDefault(e => e.Name == methodString);
298309

299310
if (method == null)
300311
continue;
@@ -355,6 +366,24 @@ bool ComputeIntelliSense(string text, int lineOffset)
355366
_smDef.EnumStructs.FirstOrDefault(e => e.Name == varDecl.Type);
356367
}
357368

369+
SMObjectMethod? FindMethod(string methodName, SMMethodmap methodMap, SMDefinition smDef)
370+
{
371+
var mm = methodMap;
372+
while (mm != null)
373+
{
374+
var method = mm.Methods.Find(e => e.Name == methodName);
375+
if (method != null)
376+
return method;
377+
378+
if (mm.InheritedType.Length == 0)
379+
return null;
380+
381+
mm = smDef.Methodmaps.Find(e => e.Name == mm.InheritedType);
382+
}
383+
384+
return null;
385+
}
386+
358387
/// <summary>
359388
/// Triggers the AutoComplete tooltip to be shown if a suggestion is found.
360389
/// </summary>
@@ -494,7 +523,7 @@ bool ComputeAutoComplete(string text, int lineOffset, int quoteCount)
494523
return false;
495524
}
496525

497-
var isNodes = mm.ProduceNodes();
526+
var isNodes = mm.ProduceNodes(_smDef);
498527

499528
if (!isNodes.SequenceEqual(_methodACEntries, ISEqualityComparer))
500529
{

UI/Windows/SPDefinitionWindow.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Windows.Media;
1010
using MahApps.Metro;
1111
using MahApps.Metro.Controls;
12+
using SourcepawnCondenser;
1213
using SourcepawnCondenser.SourcemodDefinition;
1314
using static SPCode.Interop.TranslationProvider;
1415

@@ -191,7 +192,7 @@ private void SPFunctionsListBox_SelectionChanged(object sender, SelectionChanged
191192
return;
192193
}
193194

194-
if (TagValue is SMMethodmapMethod method)
195+
if (TagValue is SMObjectMethod method)
195196
{
196197
SPNameBlock.Text = method.Name;
197198
SPFullNameBlock.Text = method.FullName;
@@ -202,7 +203,7 @@ private void SPFunctionsListBox_SelectionChanged(object sender, SelectionChanged
202203
return;
203204
}
204205

205-
if (TagValue is SMMethodmapField field)
206+
if (TagValue is SMObjectField field)
206207
{
207208
SPNameBlock.Text = field.Name;
208209
SPFullNameBlock.Text = field.FullName;

0 commit comments

Comments
 (0)