Skip to content

Commit be0b331

Browse files
authored
Merge pull request fdorg#1946 from Neverbirth/minor
Minor changes
2 parents af2bdc5 + 6f13d93 commit be0b331

File tree

5 files changed

+96
-72
lines changed

5 files changed

+96
-72
lines changed

External/Plugins/ASCompletion/Completion/ASComplete.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,12 +1446,12 @@ static public bool HasCalltip()
14461446
/// </summary>
14471447
/// <param name="Sci">Scintilla control</param>
14481448
/// <param name="paramNumber">Highlight param number</param>
1449-
static private void ShowCalltip(ScintillaControl Sci, int paramNumber)
1449+
static private void ShowCalltip(ScintillaControl sci, int paramNumber)
14501450
{
1451-
ShowCalltip(Sci, paramNumber, false);
1451+
ShowCalltip(sci, paramNumber, false);
14521452
}
14531453

1454-
static private void ShowCalltip(ScintillaControl Sci, int paramIndex, bool forceRedraw)
1454+
static private void ShowCalltip(ScintillaControl sci, int paramIndex, bool forceRedraw)
14551455
{
14561456
// measure highlighting
14571457
int start = calltipDef.IndexOf('(');
@@ -1495,7 +1495,7 @@ static private void ShowCalltip(ScintillaControl Sci, int paramIndex, bool force
14951495
prevParam = paramName;
14961496
calltipDetails = UITools.Manager.ShowDetails;
14971497
string text = calltipDef + ASDocumentation.GetTipDetails(calltipMember, paramName);
1498-
UITools.CallTip.CallTipShow(Sci, calltipPos - calltipOffset, text, forceRedraw);
1498+
UITools.CallTip.CallTipShow(sci, calltipPos - calltipOffset, text, forceRedraw);
14991499
}
15001500

15011501
// highlight
@@ -1730,9 +1730,9 @@ private static bool ResolveFunction(ScintillaControl Sci, int position, bool aut
17301730
return true;
17311731
}
17321732

1733-
public static void FunctionContextResolved(ScintillaControl Sci, ASExpr expr, MemberModel method, ClassModel inClass, bool showTip)
1733+
public static void FunctionContextResolved(ScintillaControl sci, ASExpr expr, MemberModel method, ClassModel inClass, bool showTip)
17341734
{
1735-
if (method == null || string.IsNullOrEmpty(method.Name))
1735+
if (string.IsNullOrEmpty(method?.Name))
17361736
return;
17371737
if (calltipMember != null && calltipMember.Name == method.Name)
17381738
{
@@ -1752,10 +1752,11 @@ public static void FunctionContextResolved(ScintillaControl Sci, ASExpr expr, Me
17521752

17531753
if (showTip)
17541754
{
1755-
position = Sci.CurrentPos - 1;
1756-
int paramIndex = FindParameterIndex(Sci, ref position);
1755+
position = sci.CurrentPos - 1;
1756+
sci.Colourise(0, -1);
1757+
int paramIndex = FindParameterIndex(sci, ref position);
17571758
if (position < 0) return;
1758-
ShowCalltip(Sci, paramIndex, true);
1759+
ShowCalltip(sci, paramIndex, true);
17591760
}
17601761
}
17611762

@@ -1791,7 +1792,6 @@ internal static int FindParameterIndex(ScintillaControl sci, ref int position)
17911792
int comaCount = 0;
17921793
int arrCount = 0;
17931794
var genCount = 0;
1794-
sci.Colourise(0, -1);
17951795
while (position >= 0)
17961796
{
17971797
var style = sci.BaseStyleAt(position);

External/Plugins/ASCompletion/Helpers/ASTCache.cs

Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ internal class ASTCache
1616
{
1717
public event Action FinishedUpdate;
1818

19-
Dictionary<ClassModel, CachedClassModel> cache = new Dictionary<ClassModel, CachedClassModel>(new ClassModelComparer());
19+
Dictionary<ClassModel, CachedClassModel> cache =
20+
new Dictionary<ClassModel, CachedClassModel>(new ClassModelComparer());
21+
2022
readonly List<ClassModel> outdatedModels = new List<ClassModel>();
23+
2124
/// <summary>
2225
/// A list of ClassModels that extend / implement something that does not exist yet
2326
/// </summary>
@@ -79,61 +82,67 @@ public void UpdateOutdatedModels()
7982
{
8083
var action = new Action(() =>
8184
{
82-
var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);
83-
if (context == null || context.Classpath == null)
84-
return;
85-
86-
List<ClassModel> outdated;
87-
lock (outdatedModels)
88-
{
89-
outdated = new List<ClassModel>(outdatedModels);
90-
outdatedModels.Clear();
91-
}
92-
93-
foreach (var cls in outdated)
85+
try
9486
{
95-
cls.ResolveExtends();
87+
var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);
88+
if (context == null || context.Classpath == null)
89+
return;
9690

97-
lock (cache)
91+
List<ClassModel> outdated;
92+
lock (outdatedModels)
9893
{
99-
//get the old CachedClassModel
100-
var cachedClassModel = GetCachedModel(cls);
101-
var connectedClasses = cachedClassModel?.ConnectedClassModels;
94+
outdated = new List<ClassModel>(outdatedModels);
95+
outdatedModels.Clear();
96+
}
97+
98+
foreach (var cls in outdated)
99+
{
100+
cls.ResolveExtends();
101+
102+
lock (cache)
103+
{
104+
//get the old CachedClassModel
105+
var cachedClassModel = GetCachedModel(cls);
106+
var connectedClasses = cachedClassModel?.ConnectedClassModels;
102107

103-
//remove old cls
104-
Remove(cls);
108+
//remove old cls
109+
Remove(cls);
105110

106-
UpdateClass(cls, cache);
111+
UpdateClass(cls, cache);
107112

108-
//also update all classes / interfaces that are connected to cls
109-
if (connectedClasses != null)
110-
foreach (var connection in connectedClasses)
111-
if (GetCachedModel(connection) != null) //only update existing connections, so a removed class is not reintroduced
112-
UpdateClass(connection, cache);
113+
//also update all classes / interfaces that are connected to cls
114+
if (connectedClasses != null)
115+
foreach (var connection in connectedClasses)
116+
if (GetCachedModel(connection) != null)
117+
//only update existing connections, so a removed class is not reintroduced
118+
UpdateClass(connection, cache);
119+
}
113120
}
114-
}
115-
116-
var newModels = outdated.Any(m => GetCachedModel(m) == null);
117-
//for new ClassModels, we need to update everything in the list of classes that extend / implement something that does not exist
118-
if (newModels)
119-
{
120-
HashSet<ClassModel> toUpdate;
121-
lock (unfinishedModels)
122-
toUpdate = new HashSet<ClassModel>(unfinishedModels);
123121

124-
foreach (var model in toUpdate)
122+
var newModels = outdated.Any(m => GetCachedModel(m) == null);
123+
//for new ClassModels, we need to update everything in the list of classes that extend / implement something that does not exist
124+
if (newModels)
125125
{
126+
HashSet<ClassModel> toUpdate;
126127
lock (unfinishedModels)
127-
unfinishedModels.Remove(model); //will be added back by UpdateClass if needed
128+
toUpdate = new HashSet<ClassModel>(unfinishedModels);
128129

129-
lock (cache)
130-
UpdateClass(model, cache);
130+
foreach (var model in toUpdate)
131+
{
132+
lock (unfinishedModels)
133+
unfinishedModels.Remove(model); //will be added back by UpdateClass if needed
134+
135+
lock (cache)
136+
UpdateClass(model, cache);
137+
}
131138
}
132-
}
133-
134-
if (FinishedUpdate != null)
135-
PluginBase.RunAsync(new MethodInvoker(FinishedUpdate));
136139

140+
if (FinishedUpdate != null)
141+
PluginBase.RunAsync(new MethodInvoker(FinishedUpdate));
142+
}
143+
catch (Exception)
144+
{
145+
}
137146
});
138147

139148
action.BeginInvoke(null, null);
@@ -146,29 +155,36 @@ public void UpdateCompleteCache()
146155
{
147156
var action = new Action(() =>
148157
{
149-
var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);
150-
if (context == null || context.Classpath == null || PathExplorer.IsWorking)
158+
try
151159
{
160+
var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);
161+
if (context == null || context.Classpath == null || PathExplorer.IsWorking)
162+
{
163+
if (FinishedUpdate != null)
164+
PluginBase.RunAsync(new MethodInvoker(FinishedUpdate));
165+
return;
166+
}
167+
168+
var c = new Dictionary<ClassModel, CachedClassModel>(cache.Comparer);
169+
170+
foreach (MemberModel memberModel in context.GetAllProjectClasses())
171+
{
172+
if (PluginBase.MainForm.ClosingEntirely)
173+
return; //make sure we leave if the form is closing, so we do not block it
174+
175+
var cls = GetClassModel(memberModel);
176+
UpdateClass(cls, c);
177+
}
178+
179+
lock (cache)
180+
cache = c;
181+
152182
if (FinishedUpdate != null)
153183
PluginBase.RunAsync(new MethodInvoker(FinishedUpdate));
154-
return;
155184
}
156-
157-
var c = new Dictionary<ClassModel, CachedClassModel>(cache.Comparer);
158-
159-
foreach (MemberModel memberModel in context.GetAllProjectClasses())
185+
catch (Exception)
160186
{
161-
if (PluginBase.MainForm.ClosingEntirely)
162-
return; //make sure we leave if the form is closing, so we do not block it
163-
164-
var cls = GetClassModel(memberModel);
165-
UpdateClass(cls, c);
166187
}
167-
168-
lock(cache)
169-
cache = c;
170-
if (FinishedUpdate != null)
171-
PluginBase.RunAsync(new MethodInvoker(FinishedUpdate));
172188
});
173189
action.BeginInvoke(null, null);
174190
}

External/Plugins/ASCompletion/PluginMain.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,14 @@ void OnFileRemove(FileModel obj)
10931093
astCache.MarkAsOutdated(c);
10941094
}
10951095

1096-
astCacheTimer.Stop();
1097-
astCacheTimer.Start();
1096+
try
1097+
{
1098+
astCacheTimer.Stop();
1099+
astCacheTimer.Start();
1100+
}
1101+
catch
1102+
{
1103+
}
10981104

10991105
var sci1 = DocumentManager.FindDocument(obj.FileName)?.SplitSci1;
11001106
var sci2 = DocumentManager.FindDocument(obj.FileName)?.SplitSci2;

Tests/External/Plugins/ASCompletion.Tests/Completion/ASCompleteTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ internal static int HaxeImpl(string text, ScintillaControl sci)
10761076
internal static int Common(string text, ScintillaControl sci)
10771077
{
10781078
sci.Text = text;
1079+
sci.Colourise(0, -1);
10791080
SnippetHelper.PostProcessSnippets(sci, 0);
10801081
var pos = sci.CurrentPos - 1;
10811082
var result = ASComplete.FindParameterIndex(sci, ref pos);

Tests/External/Plugins/ASCompletion.Tests/Completion/ASGeneratorTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ internal static string HaxeImpl(string sourceText, GeneratorJobType job, Scintil
10851085
internal static string Common(string sourceText, GeneratorJobType job, ScintillaControl sci)
10861086
{
10871087
SetSrc(sci, sourceText);
1088+
sci.Colourise(0, -1);
10881089
ASGenerator.GenerateJob(job, ASContext.Context.CurrentMember, ASContext.Context.CurrentClass, null, null);
10891090
return sci.Text;
10901091
}

0 commit comments

Comments
 (0)