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

Commit aa73bb9

Browse files
committed
Start implementing types
1 parent a9ccfbf commit aa73bb9

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

SourcepawnCondenser/SourcepawnCondenser/SMDefinition/SMDefinition.cs

+19-9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public string[]
3939
public List<SMTypedef> Typedefs = new List<SMTypedef>();
4040
public string[] TypeStrings = new string[0];
4141
public List<SMVariable> Variables = new List<SMVariable>();
42+
public List<string> currentVariables = new List<string>();
4243

4344
public void Sort()
4445
{
@@ -131,11 +132,19 @@ private void ProduceStringArrays(int caret = -1, List<SMFunction> currentFunctio
131132
{
132133
// TODO: This somewhat works, but somethings when in the end of a function it's buggy and doesnt find
133134
// the correct function or it finds nothing at all. The addition is a small hack that sometimes works
134-
var currentFunc = currentFunctions.FirstOrDefault(e => e.Index < caret && caret <= e.EndPos+5 && e.File.EndsWith(".sp"));
135+
var currentFunc = currentFunctions.FirstOrDefault(e =>
136+
e.Index < caret && caret <= e.EndPos + 5 && e.File.EndsWith(".sp"));
135137
if (currentFunc != null)
136138
{
137-
138139
constantNames.AddRange(currentFunc.FuncVariables.Select(v => v.Name));
140+
var stringParams = currentFunc.Parameters.Select(e => e.Split('=').First().Trim())
141+
.Select(e => e.Split(' ').Last()).Where(e => !string.IsNullOrWhiteSpace(e)).ToList();
142+
constantNames.AddRange(stringParams);
143+
currentVariables.AddRange(stringParams);
144+
}
145+
else
146+
{
147+
currentVariables.Clear();
139148
}
140149
}
141150

@@ -205,16 +214,17 @@ public void MergeDefinitions(SMDefinition def)
205214
}
206215
}
207216

208-
public SMDefinition ProduceTemporaryExpandedDefinition(SMDefinition[] definitions, int caret, List<SMFunction> currentFunctions)
217+
public SMDefinition ProduceTemporaryExpandedDefinition(SMDefinition[] definitions, int caret,
218+
List<SMFunction> currentFunctions)
209219
{
210220
var def = new SMDefinition();
211-
def.MergeDefinitions(this);
212-
foreach (var definition in definitions)
213-
if (definition != null)
214-
def.MergeDefinitions(definition);
221+
def.MergeDefinitions(this);
222+
foreach (var definition in definitions)
223+
if (definition != null)
224+
def.MergeDefinitions(definition);
215225

216-
def.Sort();
217-
def.ProduceStringArrays(caret, currentFunctions);
226+
def.Sort();
227+
def.ProduceStringArrays(caret, currentFunctions);
218228
return def;
219229
}
220230

UI/Components/IntelliSenseController.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ public partial class EditorElement
4242

4343
public ulong LastSMDefUpdateUID = 0;
4444

45+
// TODO Add EnumStructs
4546
private SMMethodmap[] methodMaps;
46-
47+
private SMVariable[] smVariables;
48+
4749
private readonly Regex multilineCommentRegex = new Regex(@"/\*.*?\*/",
4850
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline);
4951

@@ -70,12 +72,13 @@ public void LoadAutoCompletes()
7072
acEntrys = def.ProduceACNodes();
7173
isEntrys = def.ProduceISNodes();
7274
methodMaps = def.Methodmaps.ToArray();
75+
smVariables = def.Variables.ToArray();
7376
AutoCompleteBox.ItemsSource = acEntrys;
7477
MethodAutoCompleteBox.ItemsSource = isEntrys;
7578
}
7679

7780
public void InterruptLoadAutoCompletes(string[] FunctionStrings, SMFunction[] FunctionArray, ACNode[] acNodes,
78-
ISNode[] isNodes)
81+
ISNode[] isNodes, SMMethodmap[] newMethodMaps, SMVariable[] newVariables)
7982
{
8083
Dispatcher?.Invoke(() =>
8184
{
@@ -85,6 +88,8 @@ public void InterruptLoadAutoCompletes(string[] FunctionStrings, SMFunction[] Fu
8588
isEntrys = isNodes;
8689
AutoCompleteBox.ItemsSource = acEntrys;
8790
MethodAutoCompleteBox.ItemsSource = isEntrys;
91+
methodMaps = newMethodMaps;
92+
smVariables = newVariables;
8893
});
8994
}
9095

@@ -210,6 +215,7 @@ private void EvaluateIntelliSense()
210215
var classMatch = match.Groups["class"].Value;
211216
if (classMatch.Length > 0)
212217
{
218+
213219
var methodMap = methodMaps.FirstOrDefault(e => e.Name == classMatch);
214220
var method =
215221
methodMap?.Methods.FirstOrDefault(e => e.Name == methodString);

UI/MainWindowBackgroundParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void ParseDistributorTimer_Elapsed(object sender, ElapsedEventArgs args)
5656
}
5757

5858
e.InterruptLoadAutoCompletes(currentSMDef.FunctionStrings, currentSMFunctions, currentACNodes,
59-
currentISNodes);
59+
currentISNodes, currentSMDef.Methodmaps.ToArray(), currentSMDef.Variables.ToArray());
6060
e.LastSMDefUpdateUID = currentSMDefUID;
6161
}
6262
}

0 commit comments

Comments
 (0)