Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let a = (a: string, b: Record<string, number>, c?: number): void => {};

a("a", {}, 11);

type A<a, b, c> = a;

function b(
a: string,
b: A<string, Symbol, string>,
c: Record<string, number>,
d: number
): (() => void) | void {}

b("aa", "aa", {}, 2);

class B {
foo(a: (c: string, q: string) => void, c:number) {}

bar: (a: string) => void;
}

new B().foo(() => {}, 1);

new B().bar("aa");

a.call(this, 1);
45 changes: 41 additions & 4 deletions src/drivers/abstract-javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,47 @@ export function getParameterName(editor: vscode.TextEditor, position: vscode.Pos
const shouldHideRedundantAnnotations = vscode.workspace.getConfiguration('inline-parameters').get('hideRedundantAnnotations')

if (description && description.length > 0) {
try {
const functionDefinitionRegex = /[^ ](?!^)\((.*)\)\:/gm
let definition = description[0].contents[0].value.match(functionDefinitionRegex)
try {
let definition = description[0].contents[0].value;
// Find the bracket matching () => or () :
let pos = [0, -1];
let bracketsCount = 0;
let isFindingBrackets = false;
for (let i = definition.length - 1; i >= 0; i--) {
const e = definition[i];
switch (e) {
case ")":
if (bracketsCount === 0 && isFindingBrackets) pos[1] = i;
bracketsCount ++;
break;
case "(":
bracketsCount --;
if (bracketsCount === 0 && isFindingBrackets) {
pos[0] = i;
isFindingBrackets = false;
}
break;
case ":":
case "=":
if (bracketsCount === 0)
isFindingBrackets = true;
break;
case " ":
break;
default:
if (bracketsCount === 0) isFindingBrackets = false;
break;
}
}
definition = definition.slice(pos[0], pos[1] + 1);

if (!definition || definition.length === 0) {
return reject()
}

definition = definition[0].slice(2, -2)
definition = definition.slice(1, -1)
.replace(/\<.*?\>/g,'')
.replace(/\(.*?\)/g,'');

const jsParameterNameRegex = /^[a-zA-Z_$]([0-9a-zA-Z_$]+)?/g

Expand All @@ -38,6 +70,11 @@ export function getParameterName(editor: vscode.TextEditor, position: vscode.Pos

return parameter
})

// Typescript allows "this" type
if (parameters[0] === "this") {
parameters.shift();
}
} catch (err) {
console.error(err)
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"exclude": [
"node_modules",
".vscode-test"
".vscode-test",
"examples"
]
}