Skip to content

Commit f1bcfe7

Browse files
committed
Merge pull request #1030 from fdorg/fix/960
When looking up keywords, verify they have spaces around
2 parents e0d4ef2 + c031c58 commit f1bcfe7

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

External/Plugins/ASCompletion/ASCompletion.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<Compile Include="Completion\ArgumentsProcessor.cs" />
7878
<Compile Include="Completion\ASComplete.cs" />
7979
<Compile Include="Completion\ASGenerator.cs" />
80+
<Compile Include="Completion\CodeUtils.cs" />
8081
<Compile Include="Completion\Reformater.cs" />
8182
<Compile Include="Completion\TemplateUtils.cs" />
8283
<Compile Include="Context\ASContext.cs" />

External/Plugins/ASCompletion/Completion/ASComplete.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,13 +1229,13 @@ static private bool HandleDeclarationCompletion(ScintillaControl Sci, string tai
12291229
while (tempLine > 0)
12301230
{
12311231
tempText = Sci.GetLine(tempLine).Trim();
1232-
if (insideClass && IsTypeDecl(tempText, features.typesKeywords))
1232+
if (insideClass && CodeUtils.IsTypeDecl(tempText, features.typesKeywords))
12331233
{
12341234
tempIndent = Sci.GetLineIndentation(tempLine);
12351235
tab = tempIndent + Sci.TabWidth;
12361236
break;
12371237
}
1238-
if (tempText.Length > 0 && (tempText.EndsWith("}") || IsDeclaration(tempText, features)))
1238+
if (tempText.Length > 0 && (tempText.EndsWith("}") || CodeUtils.IsDeclaration(tempText, features)))
12391239
{
12401240
tempIndent = Sci.GetLineIndentation(tempLine);
12411241
tab = tempIndent;
@@ -1260,22 +1260,6 @@ static private bool HandleDeclarationCompletion(ScintillaControl Sci, string tai
12601260
return true;
12611261
}
12621262

1263-
private static bool IsTypeDecl(string line, string[] typesKeywords)
1264-
{
1265-
foreach (string keyword in typesKeywords)
1266-
if (line.IndexOf(keyword) >= 0) return true;
1267-
return false;
1268-
}
1269-
1270-
private static bool IsDeclaration(string line, ContextFeatures features)
1271-
{
1272-
foreach (string keyword in features.accessKeywords)
1273-
if (line.StartsWith(keyword)) return true;
1274-
foreach (string keyword in features.declKeywords)
1275-
if (line.StartsWith(keyword)) return true;
1276-
return false;
1277-
}
1278-
12791263
#endregion
12801264

12811265
#region function_completion
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace ASCompletion.Completion
7+
{
8+
static class CodeUtils
9+
{
10+
/// <summary>
11+
/// Lookup type declaration keywords anywhere in the provided text
12+
/// </summary>
13+
public static bool IsTypeDecl(string line, string[] typesKeywords)
14+
{
15+
var max = line.Length - 1;
16+
foreach (string keyword in typesKeywords)
17+
{
18+
var p = line.IndexOf(keyword);
19+
if (p >= 0) return IsSpaceAt(line, p - 1) && IsSpaceAt(line, p + keyword.Length);
20+
}
21+
return false;
22+
}
23+
24+
/// <summary>
25+
/// Look if the provided text starts with any declaration keyword
26+
/// </summary>
27+
public static bool IsDeclaration(string line, ContextFeatures features)
28+
{
29+
foreach (string keyword in features.accessKeywords)
30+
if (line.StartsWith(keyword) && IsSpaceAt(line, keyword.Length)) return true;
31+
foreach (string keyword in features.declKeywords)
32+
if (line.StartsWith(keyword) && IsSpaceAt(line, keyword.Length)) return true;
33+
return false;
34+
}
35+
36+
/// <summary>
37+
/// Look if character after first word of line is whitespace
38+
/// </summary>
39+
public static bool IsSpaceAt(string line, int index)
40+
{
41+
if (index < 0 || index >= line.Length) return true;
42+
else return line[index] <= 32;
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)