Skip to content

Commit

Permalink
Fixes #331
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano committed May 23, 2024
1 parent 88e421b commit 1e61ba6
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [2.5.1] - 2024-XX-XX
- Fix issue [#328](https://github.com/intersystems/language-server/issues/328): Fix namespace detection for Diagnostic computation
- Fix issue [#331](https://github.com/intersystems/language-server/issues/331): Fix display of method arguments with a colon in the default value
- Parser changes:
- DP-430950: Support new `Requires` Query keyword

Expand Down
88 changes: 86 additions & 2 deletions server/src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1902,8 +1902,92 @@ async function determineUndeclaredLocalVarClass(
* @param FormalSpec The value of the FormalSpec column in %Dictionary.CompiledMethod.
*/
export function beautifyFormalSpec(FormalSpec: string): string {
// Split the FormalSpec by commas not enclosed in parenthesis, then rejoin with added space before doing regex replaces
return "(" + FormalSpec.split(/,(?![^(]*\))/).join(", ").replace(/:/g," As ").replace(/\*/g,"Output ").replace(/&/g,"ByRef ").replace(/=/g," = ") + ")";
let result = "", inParen = false, inQuote = false, inBraces = 0;
for (const c of FormalSpec) {
if (!inParen && !inQuote && !inBraces) {
// In the argument list
switch (c) {
case ",":
result += ", ";
break;
case "*":
result += "Output ";
break;
case "&":
result += "ByRef ";
break;
case ":":
result += " As ";
break;
case "=":
result += " = ";
break;
case "\"":
inQuote = true;
result += c;
break;
case "(":
inParen = true;
result += c;
break;
case "{":
inBraces++;
result += c;
break;
default:
result += c;
}
} else if (!inQuote) {
if (inBraces) {
// In a COS block
switch (c) {
case "\"":
inQuote = true;
result += c;
break;
case "{":
inBraces++;
result += c;
break;
case "}":
inBraces--;
result += c;
break;
default:
result += c;
}
} else {
// In the class parameter list
switch (c) {
case ",":
result += ", ";
break;
case "=":
result += " = ";
break;
case "\"":
inQuote = true;
result += c;
break;
case ")":
inParen = false;
result += c;
break;
case "{":
inBraces++;
result += c;
break;
default:
result += c;
}
}
} else {
// In a quoted string
if (c == "\"") inQuote = false;
result += c;
}
}
return `(${result})`;
}

/**
Expand Down

0 comments on commit 1e61ba6

Please sign in to comment.