vscode-postfix-ts
vscode-postfix-ts copied to clipboard
No type suggestions in arrow functions for destructured args
Example:
const test = ({}: A) => { }
const test = ([]: A) => { }
// works fine if you name arg or change const to function
After A there are only identifier-suggestions, but should be only type as I started in https://github.com/ipatalas/vscode-postfix-ts/issues/62#issuecomment-1244882584
That would actually work but there is a big flaw in this extension. To analyze AST I don't use entire source code file but only everything from the beginning of the file (needed for context where we are for multi-line expressions). Everything past the cursor is discarded: https://github.com/ipatalas/vscode-postfix-ts/blob/a126e74e3f201507eef55108fd91cbb74b396a86/src/postfixCompletionProvider.ts#L89-L98
There was a reason behind that which I obviously don't remember now :)
Unfortunately that changes the AST interpretation and in this particular case I don't have TypeReference node which could be used to identify that as a type:

Changing that core behavior to start using full source code file is the way to go but that's a huge change and potentially a lot of templates will break. I'm gonna give it a shot to see how bad is it over the weekend. Maybe I'm just overreacting and that would be super cool because that opens more possibilities. I remember sometimes I had to implement some workarounds because of that different AST - this places will likely break but that should be just a few.
Changing that core behavior to start using full source code file is the way to go but that's a huge change
Hey, @ipatalas ! I just took a look at this.
There was a reason behind that which I obviously don't remember now
It seems pretty obvious, otherwise getting a node text for replacement would be hard (starting from something like a.b.castas.c(), ending with functions that work with AST to get last node name to infer the const name for example)
I tried a few different ways to solve it, probably patching the AST is only correct way, but this workaround would require a lot of code + tests.
So, the way where we discard everything after the dot is correct so we 100% don't change the code after the postfix itself (eg func.castas(args) -> (func(args) as ))
I decided to go to with an easy way and just use node of full source file for canUse
Btw I'm pushing a lot of changes on next branch, will you have a minute to discuss them?
I decided to go to with an easy way and just use node of full source file for
canUse
While I was cherry-picking your changes from next branch I found out that this particular change broke quite a lot of tests (and the functionality behind them).
I'm trying to understand what happened and fix that :)
Update: Ok, narrowed it down to custom templates only so maybe the problem can be fixed there.
Was it intentional for fullCurrentNode to contain the part after the dot as well? That's why it breaks because the old currentNode does not contain that.
Funny thing is it doesn't break for all custom templates but only those with identifier or string-literal when clause.
Update: almost got it, I know what's the root cause. This code: https://github.com/ipatalas/vscode-postfix-ts/blob/8480b790917178a08410372102e33916ee9b249f/src/postfixCompletionProvider.ts#L100-L102
Before using full source it was working just fine but now it's not. Anyway that was relatively easy to fix so now I'm at 3 breaking tests out of 18 originally so almost there.
All right, had another try few hours later and all green now :)