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

Commit 36546ce

Browse files
committed
Fix autocomplete for functions with assigment.
#3
1 parent 77d8999 commit 36546ce

File tree

6 files changed

+73
-15
lines changed

6 files changed

+73
-15
lines changed

SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMFunctionConsumer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ public static List<SMVariable> ConsumeSMVariableLocal(Token[] t, string FileName
381381
// Assign var match: "int x = 5"
382382
case TokenKind.Assignment when t[position + 4].Kind == TokenKind.Semicolon &&
383383
(t[position + 3].Kind == TokenKind.Number ||
384-
t[position + 3].Kind == TokenKind.Quote):
384+
t[position + 3].Kind == TokenKind.Quote ||
385+
t[position + 3].Kind == TokenKind.Identifier):
385386
variables.Add(new SMVariable
386387
{
387388
Index = startIndex, Length = t[position + 4].Index - startIndex, File = FileName,

SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMVariableConsumer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ private int ConsumeSMVariable()
8989
// Assign var match: "int x = 5"
9090
case TokenKind.Assignment when t[position + 4].Kind == TokenKind.Semicolon &&
9191
(t[position + 3].Kind == TokenKind.Number ||
92-
t[position + 3].Kind == TokenKind.Quote):
92+
t[position + 3].Kind == TokenKind.Quote ||
93+
t[position + 3].Kind == TokenKind.Identifier ):
9394
def.Variables.Add(new SMVariable
9495
{
9596
Index = startIndex, Length = t[position + 4].Index - startIndex, File = FileName,

SourcepawnCondenser/SourcepawnCondenser/SourcemodDefinition/SMDefinition.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class SMDefinition
1212
public string[]
1313
ConstantsStrings = new string[0]; //ATTENTION: THIS IS NOT THE LIST OF ALL CONSTANTS - IT INCLUDES MUCH MORE
1414

15+
public List<string> currentVariables = new List<string>();
16+
1517
//public string[] EnumStrings = new string[0]; NOT NEEDED
1618
//public string[] StructStrings = new string[0]; NOT NEEDED
1719
//public string[] DefinesStrings = new string[0]; NOT NEEDED
@@ -39,7 +41,6 @@ public string[]
3941
public List<SMTypedef> Typedefs = new List<SMTypedef>();
4042
public string[] TypeStrings = new string[0];
4143
public List<SMVariable> Variables = new List<SMVariable>();
42-
public List<string> currentVariables = new List<string>();
4344

4445
public void Sort()
4546
{
@@ -133,7 +134,7 @@ private void ProduceStringArrays(int caret = -1, List<SMFunction> currentFunctio
133134
// TODO: This somewhat works, but somethings when in the end of a function it's buggy and doesnt find
134135
// the correct function or it finds nothing at all. The addition is a small hack that sometimes works
135136
var currentFunc = currentFunctions.FirstOrDefault(e =>
136-
e.Index < caret && caret <= e.EndPos + 5 && e.File.EndsWith(".sp"));
137+
e.Index < caret && caret <= e.EndPos);
137138
if (currentFunc != null)
138139
{
139140
constantNames.AddRange(currentFunc.FuncVariables.Select(v => v.Name));
@@ -160,7 +161,7 @@ private void ProduceStringArrays(int caret = -1, List<SMFunction> currentFunctio
160161
typeNames.AddRange(Typedefs.Select(i => i.Name));
161162
typeNames.AddRange(EnumStructs.Select(i => i.Name));
162163
typeNames.Sort(string.Compare);
163-
TypeStrings = typeNames.ToArray();
164+
TypeStrings = typeNames.Where(e => !string.IsNullOrWhiteSpace(e)).ToArray();
164165
}
165166

166167
public ACNode[] ProduceACNodes()

UI/Components/EditorElement.xaml.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using System.IO;
45
using System.Linq;
@@ -18,6 +19,7 @@
1819
using ICSharpCode.AvalonEdit.Rendering;
1920
using ICSharpCode.AvalonEdit.Utils;
2021
using MahApps.Metro.Controls.Dialogs;
22+
using SourcepawnCondenser;
2123
using SourcepawnCondenser.SourcemodDefinition;
2224
using Spcode.Utils.SPSyntaxTidy;
2325
using Xceed.Wpf.AvalonDock.Layout;
@@ -631,8 +633,61 @@ private void Caret_PositionChanged(object sender, EventArgs e)
631633
EvaluateIntelliSense();
632634
var result = bracketSearcher.SearchBracket(editor.Document, editor.CaretOffset);
633635
bracketHighlightRenderer.SetHighlight(result);
634-
//TODO: Remove this in release
635-
// StatusLine_Work.Text = editor.CaretOffset.ToString();
636+
637+
638+
if (Program.OptionsObject.Program_DynamicISAC)
639+
{
640+
var ee = Program.MainWindow.GetAllEditorElements();
641+
var ce = Program.MainWindow.GetCurrentEditorElement();
642+
643+
var caret = -1;
644+
645+
if (ee != null)
646+
{
647+
var definitions = new SMDefinition[ee.Length];
648+
List<SMFunction> currentFunctions = null;
649+
for (var i = 0; i < ee.Length; ++i)
650+
{
651+
var el = ee[i];
652+
var fInfo = new FileInfo(el.FullFilePath);
653+
var text = el.editor.Document.Text;
654+
if (fInfo.Extension.Trim('.').ToLowerInvariant() == "inc")
655+
definitions[i] =
656+
new Condenser(text
657+
, fInfo.Name).Condense();
658+
659+
if (fInfo.Extension.Trim('.').ToLowerInvariant() == "sp")
660+
{
661+
if (el.IsLoaded)
662+
{
663+
caret = el.editor.CaretOffset;
664+
definitions[i] =
665+
new Condenser(text, fInfo.Name)
666+
.Condense();
667+
currentFunctions = definitions[i].Functions;
668+
}
669+
}
670+
}
671+
672+
var smDef = Program.Configs[Program.SelectedConfig].GetSMDef()
673+
.ProduceTemporaryExpandedDefinition(definitions, caret, currentFunctions);
674+
var smFunctions = smDef.Functions.ToArray();
675+
var acNodes = smDef.ProduceACNodes();
676+
var isNodes = smDef.ProduceISNodes();
677+
678+
foreach (var el in ee)
679+
{
680+
if (el == ce)
681+
{
682+
Debug.Assert(ce != null, nameof(ce) + " != null");
683+
if (ce.ISAC_Open) continue;
684+
}
685+
686+
el.InterruptLoadAutoCompletes(smDef.FunctionStrings, smFunctions, acNodes,
687+
isNodes, smDef.Methodmaps.ToArray(), smDef.Variables.ToArray());
688+
}
689+
}
690+
}
636691
}
637692

638693
private void TextArea_TextEntered(object sender, TextCompositionEventArgs e)

UI/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public MainWindow(SplashScreen sc)
9090
if (!args[i].EndsWith("exe"))
9191
TryLoadSourceFile(args[i], false, true, i == 0);
9292
sc.Close(TimeSpan.FromMilliseconds(500.0));
93-
StartBackgroundParserThread();
93+
// StartBackgroundParserThread();
9494
FullyInitialized = true;
9595
}
9696

UI/MainWindowBackgroundParser.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ namespace Spcode.UI
1313
public partial class MainWindow
1414
{
1515
private Thread backgroundParserThread;
16-
private ACNode[] currentACNodes;
17-
private ISNode[] currentISNodes;
18-
private SMDefinition currentSMDef;
19-
private ulong currentSMDefUID;
20-
21-
private SMFunction[] currentSMFunctions;
16+
internal ACNode[] currentACNodes;
17+
internal ISNode[] currentISNodes;
18+
internal SMDefinition currentSMDef;
19+
internal ulong currentSMDefUID;
20+
internal SMFunction[] currentSMFunctions;
21+
2222
private Timer parseDistributorTimer;
2323

2424
private void StartBackgroundParserThread()
@@ -63,7 +63,7 @@ private void ParseDistributorTimer_Elapsed(object sender, ElapsedEventArgs args)
6363

6464
private void BackgroundParser_Worker()
6565
{
66-
while (true)
66+
while (false)
6767
while (Program.OptionsObject.Program_DynamicISAC)
6868
{
6969
Thread.Sleep(3000);

0 commit comments

Comments
 (0)