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

Commit 5885fe4

Browse files
committed
Minor changes
1 parent 556be2d commit 5885fe4

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

SourcepawnCondenser/SourcepawnCondenser/SMDefinition/SMDefinition.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void AppendFiles(IEnumerable<string> paths)
8989
ProduceStringArrays();
9090
}
9191

92-
private void ProduceStringArrays(int caret = -1, string text = "")
92+
private void ProduceStringArrays(int caret = -1, List<SMFunction> currentFunctions = null)
9393
{
9494
FunctionStrings = new string[Functions.Count];
9595
for (var i = 0; i < Functions.Count; ++i) FunctionStrings[i] = Functions[i].Name;
@@ -127,9 +127,11 @@ private void ProduceStringArrays(int caret = -1, string text = "")
127127
constantNames.AddRange(Defines.Select(i => i.Name));
128128
constantNames.AddRange(Variables.Select(v => v.Name));
129129

130-
if (caret != -1)
130+
if (caret != -1 && currentFunctions != null)
131131
{
132-
var currentFunc = Functions.FirstOrDefault(e => e.Index < caret && caret <= e.EndPos && e.File.EndsWith(".sp"));
132+
// TODO: This somewhat works, but somethings when in the end of a function it's buggy and doesnt find
133+
// 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"));
133135
if (currentFunc != null)
134136
{
135137

@@ -203,7 +205,7 @@ public void MergeDefinitions(SMDefinition def)
203205
}
204206
}
205207

206-
public SMDefinition ProduceTemporaryExpandedDefinition(SMDefinition[] definitions, int caret, string text)
208+
public SMDefinition ProduceTemporaryExpandedDefinition(SMDefinition[] definitions, int caret, List<SMFunction> currentFunctions)
207209
{
208210
var def = new SMDefinition();
209211
def.MergeDefinitions(this);
@@ -212,7 +214,7 @@ public SMDefinition ProduceTemporaryExpandedDefinition(SMDefinition[] definition
212214
def.MergeDefinitions(definition);
213215

214216
def.Sort();
215-
def.ProduceStringArrays(caret, text);
217+
def.ProduceStringArrays(caret, currentFunctions);
216218
return def;
217219
}
218220

UI/MainWindowBackgroundParser.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Diagnostics;
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.Threading;
45
using System.Timers;
@@ -65,14 +66,15 @@ private void BackgroundParser_Worker()
6566
while (true)
6667
while (Program.OptionsObject.Program_DynamicISAC)
6768
{
68-
Thread.Sleep(1000);
69+
Thread.Sleep(3000);
6970
var ee = GetAllEditorElements();
7071
var caret = -1;
7172
var text = string.Empty;
7273

7374
if (ee != null)
7475
{
7576
var definitions = new SMDefinition[ee.Length];
77+
List<SMFunction> currentFunctions = null;
7678
for (var i = 0; i < ee.Length; ++i)
7779
{
7880
var fInfo = new FileInfo(ee[i].FullFilePath);
@@ -92,13 +94,14 @@ private void BackgroundParser_Worker()
9294
definitions[i1] =
9395
new Condenser(File.ReadAllText(fInfo.FullName), fInfo.Name)
9496
.Condense();
97+
currentFunctions = definitions[i1].Functions;
9598
}
9699
});
97100
}
98101
}
99102

100103
currentSMDef = Program.Configs[Program.SelectedConfig].GetSMDef()
101-
.ProduceTemporaryExpandedDefinition(definitions, caret, text);
104+
.ProduceTemporaryExpandedDefinition(definitions, caret, currentFunctions);
102105
currentSMFunctions = currentSMDef.Functions.ToArray();
103106
currentACNodes = currentSMDef.ProduceACNodes();
104107
currentISNodes = currentSMDef.ProduceISNodes();

0 commit comments

Comments
 (0)