fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
6.32k stars 204 forks source link

Autocomplete Pollution #932

Open NonSpicyBurrito opened 3 days ago

NonSpicyBurrito commented 3 days ago

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 commented 1 day ago

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?

NonSpicyBurrito commented 1 day ago

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

NonSpicyBurrito commented 1 day ago

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 commented 1 day ago

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

NonSpicyBurrito commented 8 hours ago

valibot

fabian-hiller commented 3 hours ago

In my VS Code the ordering is different:

Screenshot

NonSpicyBurrito commented 3 hours ago

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 commented 3 hours ago

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 commented 45 minutes ago

I'm unsure. Some ideas: