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

Autocomplete Pollution #932

Open
NonSpicyBurrito opened this issue Nov 18, 2024 · 13 comments
Open

Autocomplete Pollution #932

NonSpicyBurrito opened this issue Nov 18, 2024 · 13 comments
Assignees
Labels
question Further information is requested

Comments

@NonSpicyBurrito
Copy link

In VS Code, when you type string, VS Code autocomplete suggests import { string } from 'valibot' which is undesirable. This can be turned off by using ^valibot$ pattern in typescript.preferences.autoImportSpecifierExcludeRegexes.

However, if you have Valibot imported like so:

import * as v from 'valibot'

When you type string, VS Code autocomplete suggests "change string to v.string" which is also undesirable.

This not only happens to string, but also object, date, void, undefined, RegExp (due to v.regex), await (due to v.awaitAsync), return (due to v.returns) etc. This makes typing code like Date.now() via date[tab to autocomplete to Date].now() unusable as tab autocompletes to v.date instead, and also makes using your own snippets for keywords unusable (for example I have ret snippet which expands to return $0).

@fabian-hiller
Copy link
Owner

fabian-hiller commented Nov 20, 2024

Do you know if there is an option to disable import completion for a specific library in VS Code? Does ^valibot$ only disable named imports?

@fabian-hiller fabian-hiller self-assigned this Nov 20, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Nov 20, 2024
@NonSpicyBurrito
Copy link
Author

Yeah autoImportSpecifierExcludeRegexes only disables imports, and "change string to v.string" does not seem to be an import.

@NonSpicyBurrito
Copy link
Author

My current work around is to isolate all Valibot related code in their own modules, which is not really ideal. I have schemas in their own files, and re-export things like v.is.

@fabian-hiller
Copy link
Owner

I don't have the "change string to v.string" problem in my VS Code. Can you share a screenshot?

@NonSpicyBurrito
Copy link
Author

valibot

@fabian-hiller
Copy link
Owner

In my VS Code the ordering is different:

Screenshot

@NonSpicyBurrito
Copy link
Author

In your case the return is keyword autocomplete, mine is a snippet. I suppose it might be a niche use case, however this affects more than just snippets, for example it also affects autocompleting reg to RegExp:
image

@fabian-hiller
Copy link
Owner

Do you have any idea what we could do to improve this? Without a VS Code extension, we as a library probably have no control over the behaviour of the editor.

@NonSpicyBurrito
Copy link
Author

I'm unsure. Some ideas:

  • Rename to avoid collision, eg vString instead of string. This however would be a giant breaking change so it might be unrealistic.
  • From my understanding the "change string to v.string" autocomplete comes from TS language server, so perhaps a feature request for adding exclude patterns similar to import exclude patterns.

@fabian-hiller
Copy link
Owner

Thanks for your feedback! I don't have time to work on this issue right now, but I'll keep it in mind. Feel free to contact the TS language server team on GitHub and ask if this is the source of the problem. Feel free to link to this issue or tag me.

@andersk
Copy link
Contributor

andersk commented Dec 22, 2024

Note that VS Code gives these completions in value context but not in type context:

const a = string // suggests v.string
const b: string // suggests string

I don’t see anything wrong with this behavior? string is not ordinarily valid in value context anyway. If you’ve declared a variable named string, then string is suggested before v.string, and similarly for an identifier like undefined that’s valid in value context.

It’s true that date suggests v.date before Date, but Date suggests Date before v.date, so that hardly qualifies as “unusable”.

@NonSpicyBurrito
Copy link
Author

It cause specifically "typing lowercase date then auto completes to Date" unusable (as well as things like reg -> RegExp). It is correct that typing uppercase Date still works, but that's a different way of typing. It may not affect you, but to others, bringing in a library causes you to have to type in a different way is not ideal.

@miyaji255
Copy link

Rename to avoid collision, eg vString instead of string. This however would be a giant breaking change so it might be unrealistic.

import * as v from "valibot"; cannot be auto-completed. I believe this issue can also be resolved by using a prefix like vString.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants