Missing VS Code suggestions for payload imports

discord user avatar
alessiogr
Payload Team
5 months ago
32

Once in a while, VSCode just won't suggest imports from Payload (Webstorm does it). Example in the image



Has anyone else come across this?



(This also often happens with React imports, e.g. writing "useEffect" if I haven't imported anything from React before)



For comparison: Webstorm does this. Not perfect, as it imports from the dist folder, but better than nothing

  • default discord avatar
    paulpopus
    5 months ago

    I've been seeing this as well...are you developing straight in a project or in a module src which then gets imported?

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    Mh what exactly do you mean with > module src which then gets imported?

  • default discord avatar
    paulpopus
    5 months ago

    Ahh nvm, thought imports were only broken if your components were in a parent directory



    but I just tested it now in a starter project and there's still no autocomplete, I do remember these working though 😬



    my react autocompletes work though



    even without importing React first

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    Hm weirdly it does work in one other project of mine. But not in this one:

    https://github.com/AlessioGr/payload-plugin-ai/tree/master/demo

    maybe it has a problem if there's a sub-project (= demo folder) inside a project?



    lemmmme test it again



    yeah doesn't work



    I feel like that project structure really fucks with VS Code

    Code_2023-04-15_at_18.05.572x.jpg
  • default discord avatar
    paulpopus
    5 months ago

    ive had to add

    @types/react

    in mine



    for dev deps



    missed that crucial step lol



    but i saw ^ too

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    ahhhh yeah you're totally right, that fixes it for React



    Sadly not for the payload imports 😦

  • default discord avatar
    paulpopus
    5 months ago

    yeah payload ones still dont work, its extra annoying for the mystery (undocumented) imports



    maybe we should have aliases for payload?



    import { useHook } from 'payload/@utilities'
    import { Button } from 'payload/@components'


    idk if that'd complicate things more or improve dx though

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    hm what exactly would that improve, though?

  • default discord avatar
    paulpopus
    5 months ago

    hmm without intellisense not much at all...ignore that

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    for some reason, useAuth works here. But useField is not suggested



    Idk maybe your alias stuff would help. It seems vs code is just too braindead to find .ts files in subfolders for certain projects

    Code_2023-04-15_at_18.16.132x.jpg
  • default discord avatar
    paulpopus
    5 months ago

    do you think its a subfolder issue or a silent error in its indexer?



    ive never looked in the internals of vscode but it could be something odd...i almost never see intellisense not working

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    No idea. It is working for me, but not always. It seems to work for some things, and for some things it doesn't



    And weirdly, you can't find anything about it online



    You know what, Imma open up an issue on vs code and see what happens

  • default discord avatar
    paulpopus
    5 months ago

    good call

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    @paulpopus could you test if you can reproduce it too before I submit it?:

    https://github.com/AlessioGr/payload-plugin-lexical/blob/vscode-autosuggest-bug/src/index.tsx
  • default discord avatar
    paulpopus
    5 months ago

    sure, gimme a sec



    i cant get useField nor useAuth to autocomplete

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    But "payload" does autocomplete right?

  • default discord avatar
    paulpopus
    5 months ago

    yeah

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    okay perfect!!



    (useAuth stopped working for me as well)



    so weird

  • default discord avatar
    paulpopus
    5 months ago

    and i see correct types for useField once it is imported



    (alias) const useField: <T extends unknown>(options: Options) => FieldType<T>
    import useField
    Get and set the value of a form field.
  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    Oh yeah, importing it manually is fine



    https://github.com/microsoft/vscode/issues/180050


    let's seee

  • default discord avatar
    paulpopus
    5 months ago

    hopefully it gets sorted quickly, quite an annoying issue

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    Yeah definitely. With their 5k+ issues, my hopes are quite low, though



    Do react with a thumbs up to the issue, though! Apparently they look at those

  • default discord avatar
    paulpopus
    5 months ago

    added a comment too, hopefully it gets looked at...its the weekend though

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    hm @paulpopus



    not sure what I think about this



    Arc_2023-04-17_at_18.55.092x.jpg
    Arc_2023-04-17_at_18.55.542x.jpg
  • default discord avatar
    paulpopus
    5 months ago

    yeah i just saw that



    not happy with that answer



    why can you import something but doesnt get auto-imported ?

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    and isn't it part of the package.json?

    Discord_2023-04-17_at_18.57.002x.jpg
  • default discord avatar
    paulpopus
    5 months ago

    hmm before going deeper, @jmikrut any ideas?

  • discord user avatar
    jmikrut
    Payload Team
    5 months ago

    hmmmmm



    no clue



    this is super interesting though



    i think some imports might work if you have already imported something from one of the files somewhere



    like, i just got

    useAllFormFields

    to autocomplete, but i couldn't get

    useAuth

    to autocomplete in the public demo....



    so i'm thinking that there's gotta be a way to manually define which files should be indexed by TS in a node module



    worth looking into this further but i must go to bed

  • discord user avatar
    alessiogr
    Payload Team
    5 months ago

    That might explain why it sometimes works and sometimes doesn't. Maybe it also has something to do with the subfolders? Never had these issues when importing from top-level folders



    pft, 4am here and still going strong 😅 but good night!

  • discord user avatar
    jmikrut
    Payload Team
    5 months ago

    possibly. I think this will kill me if we don't get to the bottom of it



    @denolfe we should look into this tomorrow 😈



    i envy that

  • discord user avatar
    denolfe
    Payload Team
    5 months ago

    Hmm, very interesting, I can look into this

  • discord user avatar
    jmikrut
    Payload Team
    5 months ago

    it likely has something to do with the

    typings

    property in our package.json being incorrect



    we are looking into this

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.