sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.22k stars 195 forks source link

Support for detecting directive functions and components declared in `.d.ts` files #1396

Closed ohmree closed 2 years ago

ohmree commented 2 years ago

Is your feature request related to a problem? Please describe. I tried using unplugin-auto-import with the sveltekit demo app template (ts, eslint and prettier all enabled). It generates an auto-imports.d.ts file that looks like this:

declare global {
  // This is an example of an auto-imported component from `unplugin-icons`:
  const IconCarbonApps: typeof import('~icons/carbon/apps')['default']
  const scale: typeof import('svelte/transition')['scale']
  // ...
}
export {}

And the language server and svelte-check complain about it:

$ pnpm check

> my-project@0.0.1 check /path/to/project
> svelte-check --tsconfig ./tsconfig.json

====================================
Loading svelte-check in workspace: /path/to/project
Getting Svelte diagnostics...

/path/to/project/src/routes/todos/index.svelte:39:7
Warn: 'scale' is not defined (svelte)
      class:done={todo.done}
      transition:scale|local={{ start: 0.7 }}
      animate:flip={{ duration: 200 }}

/path/to/project/src/routes/todos/index.svelte:40:7
Warn: 'flip' is not defined (svelte)
      transition:scale|local={{ start: 0.7 }}
      animate:flip={{ duration: 200 }}
    >

====================================
svelte-check found 0 errors, 2 warnings, and 0 hints

When the resulting code does in fact work: I can see the transitions and animations as defined by the default template, as well as the IconCarbonApps component (which compiles into a svg tag) without having explicitly imported them.

Also I'm not sure it's related, but vite-plugin-svelte also complains about the icon component on HMR even though there's no visual difference between including and omitting its import statement:

12:29:48 AM [vite-plugin-svelte] /path/to/project/src/lib/header/Header.svelte:6:0 'IconCarbonApps' is not defined

One hypothesis I have is that this could be related to the vite plugin order, but I digress.

Describe the solution you'd like I'd like to not receive warnings in my editor (doom emacs with lsp-mode in case that matters), in the svelte-check cli and from the vite plugin.

Describe alternatives you've considered

Additional context N/A.

jasonlyu123 commented 2 years ago

These warnings are from the svelte compiler. So it doesn't make sense for it to support reading a .d.ts file to find out global variables.

For ways to filter out the warning, it's tracked in https://github.com/sveltejs/language-tools/issues/855. And for allowing configuration for defining global variables for the svelte compiler. it's tracked in https://github.com/sveltejs/svelte/issues/7240.

Closing in favour of these two issues.