Skip to content

Commit

Permalink
Added completion for pack/unpack format characters (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
King2500 committed Jun 2, 2019
1 parent 0294bda commit 06438d4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,71 @@ public class PhpCompletionTokens {
"PATH_INFO",
"ORIG_PATH_INFO",
};

public static String[] packFuncs = { "pack:0" };
public static String[] unpackFuncs = { "unpack:0" };
public static String[] packCodes = {
"a",
"A",
"h",
"H",
"c",
"C",
"s",
"S",
"n",
"v",
"i",
"I",
"l",
"L",
"N",
"V",
"q",
"Q",
"J",
"P",
"f",
"g",
"G",
"d",
"e",
"E",
"x",
"X",
"Z",
"@"
};
public static String[] packCodesInfos = {
"NUL-padded string",
"SPACE-padded string",
"Hex string, low nibble first",
"Hex string, high nibble first",
"signed char",
"unsigned char",
"signed short (always 16 bit, machine byte order)",
"unsigned short (always 16 bit, machine byte order)",
"unsigned short (always 16 bit, big endian byte order)",
"unsigned short (always 16 bit, little endian byte order)",
"signed integer (machine dependent size and byte order)",
"unsigned integer (machine dependent size and byte order)",
"signed long (always 32 bit, machine byte order)",
"unsigned long (always 32 bit, machine byte order)",
"unsigned long (always 32 bit, big endian byte order)",
"unsigned long (always 32 bit, little endian byte order)",
"signed long long (always 64 bit, machine byte order)",
"unsigned long long (always 64 bit, machine byte order)",
"unsigned long long (always 64 bit, big endian byte order)",
"unsigned long long (always 64 bit, little endian byte order)",
"float (machine dependent size and representation)",
"float (machine dependent size, little endian byte order)",
"float (machine dependent size, big endian byte order)",
"double (machine dependent size and representation)",
"double (machine dependent size, little endian byte order)",
"double (machine dependent size, big endian byte order)",
"NUL byte",
"Back up one byte",
"NUL-padded string",
"NUL-fill to absolute position"
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public void addCompletions(@NotNull CompletionParameters parameters,
boolean resultCaseSensitivity = true;
String[] deprecatedElements = {};
boolean allowMultiple = false;
boolean allowRepeat = false;
String splitter = ",";
String splitterSpace = " ";
boolean overwriteExistingCompletions = false;
InsertHandler<LookupElement> insertHandler = null;

Expand Down Expand Up @@ -265,6 +267,23 @@ else if (numParts <= 3 && patternMatches(DATETIME_PREFIX_NUMBERS_UNITS, stringPr
resultElements = PhpCompletionTokens.envNames;
}

if (methodMatches(funcName, paramIndex, PhpCompletionTokens.packFuncs) && !stringPrefix.contains("*")) {
resultElements = PhpCompletionTokens.packCodes;
resultInfos = PhpCompletionTokens.packCodesInfos;
allowMultiple = true;
allowRepeat = true;
splitter = "";
}

if (methodMatches(funcName, paramIndex, PhpCompletionTokens.unpackFuncs) && !stringPrefix.contains("*")) {
resultElements = PhpCompletionTokens.packCodes;
resultInfos = PhpCompletionTokens.packCodesInfos;
allowMultiple = true;
allowRepeat = true;
splitter = "/";
splitterSpace = "";
}

if (methodMatchesAt(funcName, paramIndex, PhpCompletionTokens.httpHeaderResponseFuncs, 0)) {
boolean isFullHeader = funcName.equals("header");
if (!stringPrefix.contains(":") && !stringPrefix.startsWith("HTTP/1.0") && !stringPrefix.startsWith("HTTP/1.1")) {
Expand Down Expand Up @@ -479,8 +498,13 @@ else if (stringPrefix.startsWith("X-XSS-Protection: ")) {
return;
}

if (allowMultiple && stringPrefix.contains(splitter + " ")) {
result = result.withPrefixMatcher(stringPrefix.substring(stringPrefix.lastIndexOf(splitter + " ") + 2));
// ", "
String split = splitter + splitterSpace;
if (allowMultiple && !splitter.isEmpty() && stringPrefix.contains(split)) {
result = result.withPrefixMatcher(stringPrefix.substring(stringPrefix.lastIndexOf(split) + split.length()));
}
else if (allowMultiple && splitter.isEmpty()) {
result = result.withPrefixMatcher("");
}

if (overwriteExistingCompletions) {
Expand All @@ -489,7 +513,7 @@ else if (stringPrefix.startsWith("X-XSS-Protection: ")) {

for (int i = 0; i < resultElements.length; i++) {

if (allowMultiple && stringPrefix.contains(resultElements[i] + splitter)) {
if (allowMultiple && !allowRepeat && stringPrefix.contains(resultElements[i] + splitter)) {
continue;
}
String postfix = Arrays.asList(resultPostfixExceptions).contains(resultElements[i]) ? resultPostfixAlt : resultPostfix;
Expand Down

0 comments on commit 06438d4

Please sign in to comment.