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

Commit 0b127b3

Browse files
committed
AC support for methodmaps
1 parent 6557a22 commit 0b127b3

File tree

6 files changed

+46
-54
lines changed

6 files changed

+46
-54
lines changed

SourcepawnCondenser/CondenserTest/MainWindow.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
188188
subSubItem.Items.Add(new TreeViewItem() { Header = "Length: " + m.Methods[j].Length, Background = Brushes.LightGray });
189189
subSubItem.Items.Add(new TreeViewItem() { Header = "Comment: >>" + m.Methods[j].CommentString + "<<" });
190190
subSubItem.Items.Add(new TreeViewItem() { Header = "Return: " + m.Methods[j].ReturnType, Background = Brushes.LightGray });
191-
var k = 0;
191+
192+
var k = 0;/*
192193
for (; k < m.Methods[j].MethodKind.Length; ++k)
193194
{
194195
subSubItem.Items.Add(new TreeViewItem() { Header = "MethodKind" + (k + 1) + ": " + m.Methods[j].MethodKind[k], Background = (k % 2 == 0) ? Brushes.LightGray : Brushes.White });
195-
}
196+
}*/
196197
for (var l = 0; l < m.Methods[j].Parameters.Length; ++l)
197198
{
198199
++k;

SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMClasslike.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using SourcepawnCondenser.SourcemodDefinition;
35

46
namespace SourcepawnCondenser;
@@ -9,15 +11,27 @@ namespace SourcepawnCondenser;
911
/// </summary>
1012
public abstract class SMClasslike : SMBaseDefinition
1113
{
12-
public List<SMObjectField> Fields = new();
13-
public List<SMObjectMethod> Methods = new();
14+
public readonly List<SMObjectField> Fields = new();
15+
public readonly List<SMObjectMethod> Methods = new();
16+
17+
public List<ACNode> ProduceNodes()
18+
{
19+
var nodes = new List<ACNode>();
20+
nodes.AddRange(ACNode.ConvertFromStringList(Methods.Select(e => e.Name), true, "▲ "));
21+
nodes.AddRange(ACNode.ConvertFromStringList(Fields.Select(e => e.Name), false, "• "));
22+
23+
nodes.Sort((a, b) => string.CompareOrdinal(a.EntryName, b.EntryName));
24+
25+
return nodes;
26+
}
1427
}
1528

1629
public abstract class SMObjectMethod : SMBaseDefinition
1730
{
1831
public string ClassName = string.Empty;
1932
public string FullName = string.Empty;
2033
public string ReturnType = string.Empty;
34+
public string[] Parameters = Array.Empty<string>();
2135
}
2236

2337
public abstract class SMObjectField : SMBaseDefinition

SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMEnumStructConsumer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ private int ConsumeSMEnumStruct()
203203
Index = mStartIndex,
204204
Name = methodName,
205205
ReturnType = methodReturnValue,
206-
MethodKind = functionIndicators.ToArray(),
206+
// MethodKind = functionIndicators.ToArray(),
207207
Parameters = parameters.ToArray(),
208208
FullName = TrimFullname(source.Substring(mStartIndex, mEndIndex - mStartIndex + 1)),
209209
Length = mEndIndex - mStartIndex + 1,
210210
CommentString = TrimComments(functionCommentString),
211-
MethodmapName = enumStructName,
211+
// MethodmapName = enumStructName,
212212
File = FileName
213213
});
214214
}

SourcepawnCondenser/SourcepawnCondenser/SourcemodDefinition/SMEnumStruct.cs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,17 @@
33

44
namespace SourcepawnCondenser.SourcemodDefinition
55
{
6-
public class SMEnumStruct : SMBaseDefinition
6+
public class SMEnumStruct : SMClasslike
77
{
8-
public readonly List<SMEnumStructField> Fields = new();
9-
public readonly List<SMEnumStructMethod> Methods = new();
10-
11-
12-
public List<ACNode> ProduceNodes()
13-
{
14-
var nodes = new List<ACNode>();
15-
nodes.AddRange(ACNode.ConvertFromStringList(Methods.Select(e => e.Name), true, "▲ "));
16-
nodes.AddRange(ACNode.ConvertFromStringList(Fields.Select(e => e.Name), false, "• "));
17-
18-
nodes.Sort((a, b) => string.CompareOrdinal(a.EntryName, b.EntryName));
19-
20-
return nodes;
21-
}
228
}
239

24-
public class SMEnumStructField : SMBaseDefinition
10+
public class SMEnumStructField : SMObjectField
2511
{
2612
public string MethodmapName = string.Empty;
27-
public string FullName = string.Empty;
2813
//public string Type = string.Empty; not needed yet
2914
}
3015

31-
public class SMEnumStructMethod : SMBaseDefinition
16+
public class SMEnumStructMethod : SMObjectMethod
3217
{
33-
public string MethodmapName = string.Empty;
34-
public string FullName = string.Empty;
35-
public string ReturnType = string.Empty;
36-
public string[] Parameters = new string[0];
37-
public string[] MethodKind = new string[0];
3818
}
3919
}

SourcepawnCondenser/SourcepawnCondenser/SourcemodDefinition/SMMethodmap.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ namespace SourcepawnCondenser.SourcemodDefinition
66
public class SMMethodmap : SMClasslike
77
{
88
public string InheritedType = string.Empty;
9-
10-
11-
public List<ACNode> ProduceNodes()
12-
{
13-
var nodes = new List<ACNode>();
14-
nodes.AddRange(ACNode.ConvertFromStringList(Methods.Select(e => e.Name), true, "▲ "));
15-
nodes.AddRange(ACNode.ConvertFromStringList(Fields.Select(e => e.Name), false, "• "));
16-
17-
nodes.Sort((a, b) => string.CompareOrdinal(a.EntryName, b.EntryName));
18-
19-
return nodes;
20-
}
219
}
2210

2311
public class SMMethodmapField : SMObjectField

UI/Components/EditorElement/EditorElementIntellisenseController.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using ICSharpCode.AvalonEdit;
1111
using ICSharpCode.AvalonEdit.Editing;
1212
using ICSharpCode.AvalonEdit.Rendering;
13+
using SourcepawnCondenser;
1314
using SourcepawnCondenser.SourcemodDefinition;
1415

1516
// ReSharper disable once CheckNamespace
@@ -21,7 +22,7 @@ enum ACType
2122
/// Top level objects, such as Functions, Variables, Types.
2223
/// </summary>
2324
Toplevel,
24-
25+
2526
/// <summary>
2627
/// Class Methods and Fields. Also used for MethodMap list.
2728
/// </summary>
@@ -84,7 +85,6 @@ public partial class EditorElement
8485
RegexOptions.Compiled | RegexOptions.ExplicitCapture);
8586

8687
static private readonly Regex NewRegex = new(@"(?:(\w+)\s+\w+\s+=\s+)?new\s+(\w+)?$", RegexOptions.Compiled);
87-
// TODO Add EnumStructs
8888

8989
static private readonly Regex MultilineCommentRegex = new(@"/\*.*?\*/",
9090
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline);
@@ -254,7 +254,6 @@ private void EvaluateIntelliSense()
254254
/// <returns>True if a the IntelliSense matched a symbol false otherwise</returns>
255255
bool ComputeIntelliSense(string text, int lineOffset)
256256
{
257-
//TODO: Add support for EnumStructs
258257
var isMatches = ISFindRegex.Matches(text);
259258
var scopeLevel = 0;
260259

@@ -293,7 +292,7 @@ bool ComputeIntelliSense(string text, int lineOffset)
293292

294293
if (classString.Length > 0)
295294
{
296-
var methodMap = FindMethodMap(classString);
295+
var methodMap = FindClass(classString);
297296

298297
var method = methodMap?.Methods.FirstOrDefault(e => e.Name == methodString);
299298

@@ -321,31 +320,39 @@ bool ComputeIntelliSense(string text, int lineOffset)
321320
}
322321

323322

324-
SMMethodmap? FindMethodMap(string classStr)
323+
SMClasslike? FindClass(string classStr)
325324
{
326325
// Match for static methods. Like MyClass.StaticMethod(). Look for a MethodMap that is named as our classStr.
327-
var methodMap = _smDef.Methodmaps.FirstOrDefault(e => e.Name == classStr);
326+
var classElement = _smDef.Methodmaps.FirstOrDefault(e => e.Name == classStr);
328327

329328
// If the staticMethod is found show it.
330-
if (methodMap != null)
329+
if (classElement != null)
331330
{
332-
return methodMap;
331+
return classElement;
333332
}
334333

335334
// Find variable declaration to see of what type it is -->
336335
// Try to match it in the local variables (of the current function).
337336
var varDecl =
338337
_smDef?.CurrentFunction?.FuncVariables.FirstOrDefault(e => e.Name == classStr);
339338

339+
340340
//TODO: Add FunctionParameters matching.
341341
/*varDecl ??= _smDef?.CurrentFunction?.Parameters.FirstOrDefault(e =>
342342
MatchTypeRegex.Match(e).Groups[0].Value == classString);*/
343343

344344
// Try to match it in the current file.
345345
varDecl ??= _smDef.Variables.FirstOrDefault(e => e.Name == classStr);
346346

347+
if (varDecl == null)
348+
{
349+
return null;
350+
}
351+
347352
// If we found the declaration get the Variable Type and look for a method-map matching its type.
348-
return varDecl == null ? null : _smDef.Methodmaps.FirstOrDefault(e => e.Name == varDecl.Type);
353+
354+
return (SMClasslike)_smDef.Methodmaps.FirstOrDefault(e => e.Name == varDecl.Type) ??
355+
_smDef.EnumStructs.FirstOrDefault(e => e.Name == varDecl.Type);
349356
}
350357

351358
/// <summary>
@@ -411,7 +418,7 @@ bool ComputeAutoComplete(string text, int lineOffset, int quoteCount)
411418

412419
if (text.Length == 0 || editor.SelectionLength > 0)
413420
return false;
414-
421+
415422
if (!IsValidFunctionChar(text[lineOffset - 1]) &&
416423
text[lineOffset - 1] != '.' && text[lineOffset - 1] != ' ' && text[lineOffset - 1] != '\t')
417424
return false;
@@ -481,7 +488,7 @@ bool ComputeAutoComplete(string text, int lineOffset, int quoteCount)
481488
}
482489

483490
var classString = text.Substring(classOffset, len);
484-
var mm = FindMethodMap(classString);
491+
var mm = FindClass(classString);
485492
if (mm == null)
486493
{
487494
return false;
@@ -1031,11 +1038,13 @@ public static class ACNodeExt
10311038
return i;
10321039
}
10331040

1034-
var index = nodes.FindIndex(node => node.EntryName.StartsWith(query, StringComparison.InvariantCultureIgnoreCase));
1041+
var index = nodes.FindIndex(node =>
1042+
node.EntryName.StartsWith(query, StringComparison.InvariantCultureIgnoreCase));
10351043
if (index == -1)
10361044
{
10371045
index = nodes.FindIndex(node => node.EntryName.Contains(query));
10381046
}
1047+
10391048
return index == -1 ? null : index;
10401049
}
10411050
}

0 commit comments

Comments
 (0)