tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
482 stars 38 forks source link

Support $ autosubscription syntax (store references) #4

Closed tomblachut closed 3 years ago

tomblachut commented 5 years ago

~I've been thinking about that for a bit now and finally asked JB for input.~

~Basically I see 2 approaches here:~

~1. Extend JS language/parser (and also TS ones). Turns out this is insanely over-complicated because there are edge-cases in Svelte 😉 Svelte handles this after parsing step because it doesn't need to care about editing features. (See #46)

  1. Monkey-patch this on top of JS identifiers/references. I still don't know how to handle types but hey, TS is not supported anyway yet.~

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004377420-Treat-part-of-JS-identifier-specially-depending-on-context

I guess preliminary type-unsafe support will be easy enough.

(also, related docs: http://www.jetbrains.org/intellij/sdk/docs/reference_guide/custom_language_support/rename_refactoring.html)

unlocomqx commented 5 years ago

I gave it a shot in my "reactive" branch. it's not so great but it could be helpful https://github.com/unlocomqx/svelte-intellij/tree/reactive

tomblachut commented 5 years ago

Thx! I'll give it a spin

today- commented 4 years ago

Great job on last update. Now $stores are reconginzing and highlighting by IDE.

But TS-types are incorrent, now they show Store's type, not the value istelf.

I tried to evaluate Type from .subscribe() method as Svelte do and created such snippet

type Unsubscriber<T extends {subscribe: any}> = T['subscribe'] extends ((v: infer S) => any) ?
  (S extends (v: infer V) => any ? V : never) : never;

type StoredValue = Unsubscriber<typeof store>;
tomblachut commented 4 years ago

@today- Current implementation is pretty stupid unfortunately

find usages action also don't find them properly

tomblachut commented 4 years ago

There's progress

image