Skip to content

Commit 5c70747

Browse files
committed
When looking up keywords, verify they have spaces around (eg. classList isn't a class declaration)
1 parent f8f0483 commit 5c70747

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

External/Plugins/ASCompletion/Completion/ASComplete.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,22 +1257,45 @@ static private bool HandleDeclarationCompletion(ScintillaControl Sci, string tai
12571257
return true;
12581258
}
12591259

1260+
/// <summary>
1261+
/// Lookup type declaration keywords anywhere in the provided text
1262+
/// </summary>
12601263
private static bool IsTypeDecl(string line, string[] typesKeywords)
12611264
{
1265+
var max = line.Length - 1;
12621266
foreach (string keyword in typesKeywords)
1263-
if (line.IndexOf(keyword) >= 0) return true;
1267+
{
1268+
var p = line.IndexOf(keyword);
1269+
if (p >= 0)
1270+
{
1271+
// verify keyword between spaces
1272+
var end = p + keyword.Length;
1273+
if ((p == 0 || line[p-1] <= 32)
1274+
&& end < max && line[end] <= 32) return true;
1275+
}
1276+
}
12641277
return false;
12651278
}
12661279

1280+
/// <summary>
1281+
/// Look if the provided text starts with any declaration keyword
1282+
/// </summary>
12671283
private static bool IsDeclaration(string line, ContextFeatures features)
12681284
{
12691285
foreach (string keyword in features.accessKeywords)
1270-
if (line.StartsWith(keyword)) return true;
1286+
if (line.StartsWith(keyword) && SpaceFollows(line, keyword)) return true;
12711287
foreach (string keyword in features.declKeywords)
1272-
if (line.StartsWith(keyword)) return true;
1288+
if (line.StartsWith(keyword) && SpaceFollows(line, keyword)) return true;
12731289
return false;
12741290
}
12751291

1292+
private static bool SpaceFollows(string line, string keyword)
1293+
{
1294+
var len = keyword.Length;
1295+
if (line.Length > len) return line[len] <= 32;
1296+
else return true;
1297+
}
1298+
12761299
#endregion
12771300

12781301
#region function_completion

0 commit comments

Comments
 (0)