microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.13k stars 12.5k forks source link

TypeScript language server fails to recognize new files and needs restart #60040

Open itsjavi opened 3 months ago

itsjavi commented 3 months ago

Type: Bug

Since the last update(s) or so, the TypeScript language server fails to recognize or do any code completion on newly created (or copy-pasted) files, no matter if they are TS or TSX.

With TS files it fails to do code completion for any other code from my project (cannot find anything from my project to import when I do CTRL+SPACE).

For TSX files, it fails to recognize React and all I get is syntax errors for JSX code.

I have to manually restart the TS language server in order to fix this. That or wait ~5s.

Context:

VS Code version: Code 1.92.1 (Universal) (eaa41d57266683296de7d118f574d0c2652e1fc4, 2024-08-07T20:16:39.455Z) OS version: Darwin arm64 23.5.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M1 Max (10 x 2400)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off| |Load (avg)|2, 2, 2| |Memory (System)|32.00GB (1.05GB free)| |Process Argv|--crash-reporter-id 593ea142-22bd-42ca-a19a-94f980be787b| |Screen Reader|no| |VM|0%|
Extensions (37) Extension|Author (truncated)|Version ---|---|--- rust-bundle|1Yi|1.0.0 html-class-suggestions|And|1.2.1 biome|bio|2.3.0 vscode-tailwindcss|bra|0.12.6 npm-intellisense|chr|1.4.5 path-intellisense|chr|2.9.0 vscode-css-modules|cli|0.5.1 vscode-notes|dio|1.2.1 rust-syntax|dus|0.6.1 prettier-vscode|esb|10.4.0 html-slim-scss-css-class-completion|gen|1.7.8 codespaces|Git|1.17.2 copilot|Git|1.221.0 copilot-chat|Git|0.18.1 vscode-github-actions|git|0.26.3 vscode-scss|mrm|0.10.0 black-formatter|ms-|2024.2.0 debugpy|ms-|2024.10.0 python|ms-|2024.12.2 vscode-pylance|ms-|2024.8.1 jupyter|ms-|2024.7.0 jupyter-keymap|ms-|1.1.2 jupyter-renderers|ms-|1.0.19 vscode-jupyter-cell-tags|ms-|0.1.9 vscode-jupyter-slideshow|ms-|0.1.6 live-server|ms-|0.4.14 vscode-speech|ms-|0.10.0 material-icon-theme|PKi|5.9.0 vscode-css-peek|pra|4.4.1 code-snapshot|rob|0.2.1 rust-analyzer|rus|0.3.2062 tauri-vscode|tau|0.2.6 luna-paint|Tyr|0.16.0 vscode-mdx|uni|1.8.9 vscode-wakatime|Wak|24.6.0 pretty-ts-errors|Yoa|0.6.0 vscode-className-completion|zwk|0.0.18
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes627:30244334 vscoreces:30445986 vscod805cf:30301675 binariesv615:30325510 vsaa593:30376534 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonnoceb:30805159 asynctok:30898717 pythonregdiag2:30936856 pythonmypyd1:30879173 2e7ec940:31000449 pythontbext0:30879054 accentitlementsc:30995553 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 dsvsc021:30996838 da93g388:31013173 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31068756 dwnewjupytercf:31046870 2f103344:31071589 impr_priority:31102340 refactort:31108082 pythonrstrctxt:31112756 wkspc-onlycs-t:31111718 wkspc-ranged-t:31111713 ```
itsjavi commented 3 months ago

It seems it's just very slow on large projects, and I am on a good macbook M1 Max with 32GB of RAM.

mjbvz commented 1 month ago

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

If it does, can you share an example project which causes this issue?

itsjavi commented 1 month ago

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

If it does, can you share an example project which causes this issue?

Yes, I can reproduce. Unfortunately the large project is not public and I cannot share it, but I had similar experiences with large nextjs projects, even if they don't use shadcn/ui.

This is my tsconfig if it helps

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "target": "ES2020",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./src/*"]
    },

    // Best practices
    "noFallthroughCasesInSwitch": true,
    "verbatimModuleSyntax": true,

    // Some stricter flags
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noPropertyAccessFromIndexSignature": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules", ".next"]
}

package.json deps:

{
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@auth/drizzle-adapter": "^1.5.0",
    "@mdx-js/loader": "^3.0.1",
    "@mdx-js/react": "^3.0.1",
    "@neondatabase/serverless": "^0.9.5",
    "@next/mdx": "^14.2.13",
    "@oslojs/encoding": "^1.0.0",
    "@react-email/components": "^0.0.25",
    "@react-email/render": "^1.0.1",
    "@types/mdx": "^2.0.13",
    "@uidotdev/usehooks": "^2.4.1",
    "@upstash/redis": "^1.34.0",
    "@vercel/analytics": "^1.3.1",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.1",
    "dayjs": "^1.11.13",
    "dotenv": "^16.4.5",
    "drizzle-orm": "^0.33.0",
    "fast-csv": "^5.0.1",
    "framer-motion": "^11.5.6",
    "lucide-react": "^0.445.0",
    "next": "14.2.13",
    "next-auth": "5.0.0-beta.21",
    "next-themes": "^0.3.0",
    "nuqs": "^1.19.2",
    "oslo": "^1.2.1",
    "postgres": "^3.4.4",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "resend": "^4.0.0",
    "server-only": "^0.0.1",
    "sharp": "^0.33.5",
    "tailwind-merge": "^2.5.2",
    "tailwindcss-animate": "^1.0.7",
    "zod": "^3.23.8"
  },
  "devDependencies": {
    "@svgr/webpack": "^8.1.0",
    "@swc/core": "^1.7.26",
    "@swc/jest": "^0.2.36",
    "@types/chroma-js": "^2.4.4",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.16.5",
    "@types/pg": "^8.11.10",
    "@types/pg-copy-streams": "^1.2.5",
    "@types/react": "^18.3.8",
    "@types/react-dom": "^18.3.0",
    "chroma-js": "^3.1.1",
    "drizzle-kit": "^0.24.2",
    "jest": "^29.7.0",
    "pg": "^8.13.0",
    "pg-copy-streams": "^6.0.6",
    "postcss": "^8.4.47",
    "prettier": "^3.3.3",
    "pwa-asset-generator": "^6.3.2",
    "react-email": "3.0.1",
    "sort-package-json": "^2.10.1",
    "tailwindcss": "^3.4.13",
    "typescript": "^5.6.2"
  },
  "packageManager": "pnpm@8.15.9",
  "engines": {
    "node": ">=20.5.0"
  }
}
mjbvz commented 1 month ago

Ok thanks, I'm going to move this over to TS to see if the team has an ideas

RyanCavanaugh commented 1 month ago

I have to manually restart the TS language server in order to fix this. That or wait ~5s.

This is pretty normal when we're in polling mode and doesn't seem unusual (5s is not a long time?). We'd need a repo to clone to investigate further