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

autcomplete for module names is not working #430

Closed
AhmadMayo opened this issue Aug 5, 2020 · 13 comments
Closed

autcomplete for module names is not working #430

AhmadMayo opened this issue Aug 5, 2020 · 13 comments
Labels
bug Something isn't working

Comments

@AhmadMayo
Copy link

Describe the bug
When I try to import any package, the editor doesn't suggest anything except "*.svelte" as the package name. Surprisingly when I type the name of any package, the intellisense works correctly for the exported variables and types.

To Reproduce

  1. Use svelte template
  2. Open App.svelte
  3. Type import x from"" and tap ctrl+space - or whatever open the suggestions list - when the cursor is between the quotes of the module name.

Expected behavior
VSCode displays the names of the installed packages

Screenshots
Screenshot from 2020-08-05 20-00-17
Screenshot from 2020-08-05 20-00-53
Screenshot from 2020-08-05 20-09-57
Screenshot from 2020-08-05 20-12-42

System (please complete the following information):

  • OS: Ubuntu 20.04
  • IDE: VSCode
  • Plugin/Package: "Svelte for VSCode"

Additional context
None

@AhmadMayo AhmadMayo added the bug Something isn't working label Aug 5, 2020
@jasonlyu123
Copy link
Member

jasonlyu123 commented Aug 6, 2020

I'm guessing this is because you run npm install after the extension is initialized. It that case the detection of node_modules is already finished. Due to the memory usage issues, we can't add all the added files to the compilation list but manual imported one is fine. If you restart your language-server after npm install it should work fine.

@AhmadMayo
Copy link
Author

I tested your theory, but I think it's not totally correct. I have two folders, the first is just the empty template (14 dev deoendency and 1 dependency), and the other with installed packages (23 dev deps and 3 deps). It's working in the empty template project, but not the other.

From the plugin output tap:

SnapshotManager File Statistics:
Project files: 5
Svelte files: 12
From node_modules: 73
Total: 91

I don't thinks that's a lot of modules nor files, but may be I'm wrong. Can you guide me to get to the cause of the issue?

@jasonlyu123
Copy link
Member

73 seems reasonable to me, typescript will only grab the definition file when applicable. Does the one that is not working also built on top of the official template?

@AhmadMayo
Copy link
Author

Yes, but I tweeked the config files a little.

tsconfig:

{
  "extends": "@tsconfig/svelte/tsconfig.json",

  "include": ["src/**/*"],
  "exclude": ["node_modules/*", "__sapper__/*", "public/*"],
  "compilerOptions": {
    "moduleResolution": "node",
    "target": "es2020",
    "importsNotUsedAsValues": "error",
    "isolatedModules": true,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "types": ["svelte"]
  },
}

rollup.config

import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import {terser} from 'rollup-plugin-terser';
import sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';
import postCSSImport from "postcss-import";
import replace from "@rollup/plugin-replace";
import json from '@rollup/plugin-json';
import svelteSVG from "rollup-plugin-svelte-svg";
import dotenv from 'dotenv-flow';
import dotenvExpand from 'dotenv-expand';
import config from './package.json';

dotenvExpand(dotenv.config());
const env = Object.fromEntries(
  Object.entries(process.env).filter(([key]) => key.startsWith('SVELTE_')),
);
env.VERSION = config.version;
env.PUBLIC_URL = config.homepage || '';

const production = !process.env.ROLLUP_WATCH;

function serve() {
  let server;

  function toExit() {
    if (server) server.kill(0);
  }

  return {
    writeBundle() {
      if (server) return;
      server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
        stdio: ['ignore', 'inherit', 'inherit'],
        shell: true,
      });

      process.on('SIGTERM', toExit);
      process.on('exit', toExit);
    },
  };
}

export default {
  input: 'src/main.ts',
  output: {
    sourcemap: true,
    format: 'es',
    name: 'app',
    dir: 'public/build/',
    manualChunks(id) {
      if (id.includes('node_modules')) {
        const pathSegments = id.replace(/.*node_modules\//, '').split('/');
        return pathSegments[0] + '/' + pathSegments.slice(1).join('-');
      }

      if (id.includes('/src/ui/')) {
        return 'ui/' + id.split('/').reverse()[0];
      }
    }
  },
  moduleContext: id => {
    const thisAsWindowForModules = 'node_modules/intl-';

    if (id.includes(thisAsWindowForModules)) {
      return 'window';
    }
  },
  plugins: [
    replace({'process.env': JSON.stringify(env)}),
    json(),
    svelteSVG(),
    svelte({
      // enable run-time checks when not in production
      dev: !production,
      // we'll extract any component CSS out into
      // a separate file - better for performance
      css: css => {
        css.write('public/build/bundle.css');
      },
      preprocess: sveltePreprocess({
        postcss: {
          plugins: [
            postCSSImport(),
          ],
        }
      }),
    }),

    // If you have external dependencies installed from
    // npm, you'll most likely need these plugins. In
    // some cases you'll need additional configuration -
    // consult the documentation for details:
    // https://github.com/rollup/plugins/tree/master/packages/commonjs
    resolve({
      browser: true,
      dedupe: ['svelte'],
    }),
    commonjs(),
    typescript({sourceMap: !production}),

    // In dev mode, call `npm run start` once
    // the bundle has been generated
    !production && serve(),

    // Watch the `public` directory and refresh the
    // browser on changes when not in production
    !production && livereload('public'),

    // If we're building for production (npm run build
    // instead of npm run dev), minify
    production && terser(),
  ],
  watch: {
    clearScreen: false,
  },
};

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Aug 10, 2020
…nstead

Less setup for people (`"types": ["svelte"]` now obsolete), makes TS search more of the other globals.
sveltejs#430
dummdidumm added a commit that referenced this issue Aug 11, 2020
…nstead (#441)

Less setup for people (`"types": ["svelte"]` now obsolete), makes TS search more of the other globals.
#430
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Aug 12, 2020
@dummdidumm
Copy link
Member

dummdidumm commented Aug 13, 2020

Although this is fixed by us, you still need to adjust your tsconfig to get the desired behavior. Remove "types": ["svelte"] from your tsconfig and wait for this PR to land and update @tsconfig/svelte after it's released.

@AhmadMayo
Copy link
Author

Thanks a lot

@dummdidumm
Copy link
Member

I was too quick on "remove "type": ["svelte"] - that's needed for TS files to not error on .svelte imports. I'm not sure if you can get the desired behavior right now.

@AhmadMayo
Copy link
Author

Thanks a lot for your time. Should we reopen? And is there anything I can do to help

@dummdidumm
Copy link
Member

If I try to reproduce this with the starter template I get other suggestions besides *.svelte. Which suggestions are you missing in your case?

@dummdidumm dummdidumm reopened this Aug 14, 2020
@dummdidumm dummdidumm removed the Fixed Fixed in master branch. Pending production release. label Aug 14, 2020
@AhmadMayo
Copy link
Author

Everything. Even dev dependencies like typescript or rollup don't appear

@dummdidumm
Copy link
Member

If I checkout the starter template, transform to TS, npm i, open App.svelte, then I get more than just *.svelte. I also get things such as typescript. I also get them when using your tsconfig.json.

@AhmadMayo
Copy link
Author

AhmadMayo commented Aug 14, 2020

It's probably related to the number of installed packages. I'll try to create a repo where I could reproduce the issue, but I will not be able to do it before tuesday

@AhmadMayo
Copy link
Author

@dummdidumm I removed node_modules and package-lock.json in my project, reinstalled, restarted svelte server and now it works. May be your fix did solve it after all. Thank you very much for your time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants