Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSDoc for hook examples #3022

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RodolfoSilva
Copy link
Contributor

@chrismccord, reopened this which was previously incorporated into #2892 PR


I've added JSDoc annotations to the Hook usage examples in order to enhance IDE autocomplete functionality. Often, developers find themselves referring back to the documentation to recall a Hook's structure and its associated functions. Embedding type documentation directly within the code streamlines this process, offering a more efficient development experience.

@chrismccord
Copy link
Member

Will this work for markdown and elixir docs in the editor? I'm happy to see us JSDoc the source files, but including it in the Elixir docs is out of place unless it really provides robust integration with ls servers/editors at large

@RodolfoSilva
Copy link
Contributor Author

Yes, this is fully compatible with all editors. Im use this approach with a clean vscode version. Without any additional plugin.

This turn possible to use the autocomplete when we are developing a new hook.

@SteffenDE
Copy link
Collaborator

This does indeed help editors like VSCode to properly suggest completions when working with hooks.

Old:
image

New:
image

The completions come from https://www.npmjs.com/package/@types/phoenix_live_view though, not directly from the LV js code.

@rhcarvalho
Copy link
Contributor

Oh yeah this worked for me on an existing project. Indeed helps improve autocomplete in VSCode (perhaps other editors too depending on setup/config).

I wish this was opt-in and the least intrusive as possible.

I tried a few other options like putting //@ts-check on top of the file (https://code.visualstudio.com/docs/languages/javascript#_type-checking), installing the @types/phoenix_live_view using npm, and defining the type on LiveSocket. They all bring something, but I'm not particularly satisfied inflicting the changes on everyone.

Ideally there'd be some one-liner we could include in the phx.new app.js template or docs. The //@ts-check comment is the closest one so far, but it doesn't give good autocomplete suggestions for Hooks the way we tend to write them.

@SteffenDE
Copy link
Collaborator

Thank you for the bump. If there is a better way to solve it we might revisit this later, but I think these changes are fine.

@RodolfoSilva
Copy link
Contributor Author

@chrismccord could you check out @SteffenDE demonstration?

I've tested this on:

  • VSCode
  • SublimeText
  • Intellij
  • Zed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants