Closed phil294 closed 3 years ago
Can we ignore that case (just type this
if you want @
)?
Probably most @
usage is this.
so it's acceptable tradeoff.
ignore that case
This is problematic because it means disallowing the syntax altogether, not just missing type hints. There is only a single one-fits-all transformation step which has no knowledge of the kind of incoming LSP request or cursor position. So replacing all occurences of @
with this.
is not okay, it would introduce syntax errors where it is used as plain this
without dot.
I just tried another workaround: Replacing @
with this.valueOf()
and map cursor position |
from @|
to this.|valueOf()
. This would work, but unfortunately, tsserver does not agree:
//@ts-check
let a = {
b: 1,
c() {
return this.valueOf().b // Syntax error: Property 'b' does not exist on type 'Object'.ts(2339)
}
}
when it does work - evaluating a.c()
results in 1
as expected.
So right now the only solution that I can think of is fixing the extension's architecture but personally, I don't plan on doing that any time soon.
/ come to think about it, maybe we can overwrite typing of .valueOf()
? :S
Edit: There was an error in my thinking, tsserver
's opinion on .b
does not matter, as the emulated cursor is placed before valueOf
, not before b
. In other words, this .valueOf()
approach is possible and I'll push it in a few minutes
ok nevermind what I wrote above, I released v1.1.0 with which everything should work just as expected, even when CS compilation is not possible
If you happen to work with it again @isral, could you please give me feedback on whether it works for you?
A better replacement may be (this._, this)
. I haven't thought through all the situations but it seems like it may work to get the dot in the right place for autocompletes while still returning the correct type/value.
A better replacement may be
(this._, this)
. I haven't thought through all the situations but it seems like it may work to get the dot in the right place for autocompletes while still returning the correct type/value.
oh that's clever!
cursor after
@
does not offer context autocomplete, onlythis.
does.This cannot be easily solved with a simple replaceAll because it can also mean this without the dot:
is