microsoft / TypeScript

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

Infinite Intellisense Loading... #57470

Open ADSNB opened 7 months ago

ADSNB commented 7 months ago

Type: Bug

Basically when I open my nextjs with typescript project the intellisense works for the first 1~~5 seconds and after that the intellisense stop working. I can't navigate into objects, classes, functions, intellisense don't work anymore anywhere. The only thing that appears is "Loading..." when I hover any function/methods/objct/path and in the bottom corner is saying "Loading intellisense status...".

This issue is very annoying. Trying to develop a software without intellisense is just unproductive. In this past couple of days vscode has not been able to load the intellisense corretly at all in this project.

I've created this nextJS project using create-next-app with tailwindcss and typescript (following theire doc), I've added prisma, prisma class generators, nextUI to use in most of the UI components, trpc using querys with zod as validators, materialUI for icons, next-swagger-doc for swagger documentation.

I have seen a lot of topics over the internet about this issue and every single one of them has different ways to fix this and most of the responses of the people who got it working is "for now it's working" and we can't be sure it's have been fixed yet, because most of them don't reply the topic if the error is gone for good or they just moved on to another IDE.

I have tried a lot of things to try to fix this issue and still the intellisense is not working. Some of the things I tried are:

0 - Installed NodeJS Current then moved back to NodeJS LTS. 1 - Uninstall vs code and install a clean version. 2 - Install vs code insiders version. 3 - Start extension Bisect 4 - Clone entire repo again 5 - Force vscode to use typescript from the node_modules (project version) instead the workspace version. 6 - Clean cache folders located in "C:\Users[USER]\AppData\Roaming\Code\Cache\Cache_Data" and "C:\Users[USER]\AppData\Roaming\Code\CachedData". 7 - Restart TS server works for about 1~~5 seconds and then I lose intellisense functionality again. 8 - Trying to disable all extensions from VS code doesn't solve the issue. 9 - Enable TS server logs and check the logs to find issues. I have found some lines that could mean some issues, like:

"FileWatcher:: Added:: WatchInfo: c:/Projects/vega/tsconfig.json 2000 undefined"

"FileWatcher:: Added:: WatchInfo: c:/Projects/vega/tailwind.config.ts 500 undefined WatchType: Closed Script info"

"DirectoryWatcher:: Added:: WatchInfo: c:/Projects/vega/node_modules 1 undefined Project: c:/Projects/vega/tsconfig.json WatchType: Failed Lookup Locations"

But I'm not sure if this is normal messages or errors messages.

Any help is appreciated.

VS Code version: Code 1.86.1 (31c37ee8f63491495ac49e43b8544550fbae4533, 2024-02-07T09:08:20.941Z) OS version: Windows_NT x64 10.0.19045 Modes:

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 9 3900XT 12-Core Processor (24 x 3793)| |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
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.94GB (20.59GB free)| |Process Argv|--crash-reporter-id f67be61d-5abc-48d3-82e2-d0a3448fac79| |Screen Reader|no| |VM|0%|
Extensions (18) Extension|Author (truncated)|Version ---|---|--- Bookmarks|ale|13.4.2 vscode-tailwindcss|bra|0.10.5 npm-intellisense|chr|1.4.5 path-intellisense|chr|2.8.5 vscode-eslint|dba|2.4.4 prettier-vscode|esb|10.1.0 code-runner|for|0.12.1 languague-renpy|Luq|2.2.2 git-graph|mhu|1.30.0 debugpy|ms-|2024.0.0 python|ms-|2024.0.1 vscode-pylance|ms-|2024.2.1 vscode-typescript-next|ms-|5.4.20240208 color-highlight|nau|2.5.0 indent-rainbow|ode|8.3.1 prisma|Pri|5.9.1 errorlens|use|3.16.0 vscode-icons|vsc|12.7.0
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscorecescf:30445987 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:30899288 vscaac:30438847 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythongtdpath:30769146 welcomedialogc:30910334 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 accentitlementsc:30887149 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 pydisww2:30959801 edj9j583:30958191 7j2b6412:30949929 ccp2r6:30958158 ```
ADSNB commented 7 months ago

This is my tsconfig file: tsconfig.json

This is my packages file: package.json

wynnw commented 7 months ago

python/pylance extension has broken in a similar way with 1.86.1.

ADSNB commented 7 months ago

I've tried a couple of things this past few days to try to figure out what is happening with vscode intellisense. I've discovered the intellisense stopped working when I browse specific files meaning if I don't open this files the intellisense work normally as supposed to. This are ordinary files like .TS and .TSX.

So, now that I know what files are impacting the intellisense, I tried to narrow down the issue. I moved the files to upper directories, changed the project location, renamed the files and functions to shorter names to see if this are related to path or name extensions exception/errors. So, all of this attempts doesn't fixed the problem.

Since these attempts that I've made was related to files locations and naming appear not be the issue, I was trying to see what imports was used in these files that was breaking the code because, the written code works without any issue on the browser and even in developers console I don't have any warnings or errors. I finally discovered that this import was breaking the intellisense:

import { ConstructionCompanyCreateOneSchema } from "@/database/prisma/generated/schemas/createOneConstructionCompany.schema"; 

This schemas and objects are automatically generated by "prisma-trpc-generator" package (https://github.com/omar-dulaimi/prisma-trpc-generator). All of this files work and build without any issue. One thing I noticed though is that this table "ConstructionCompany" has relation with "ConstructionCompanyProject", one to many. This creates a bound/relation between the two table and prisma-trpc-generator probably generate more code making zod create safety rules around it. But like I said, the code don't have any typescript error. So, here are some of the code that is generated and breaks vscode intellisense:

Code of "...\schemas\createOneConstructionCompany.schema.ts":

import { z } from  'zod';

import { ConstructionCompanyCreateInputObjectSchema } from  './objects/ConstructionCompanyCreateInput.schema';

import { ConstructionCompanyUncheckedCreateInputObjectSchema } from  './objects/ConstructionCompanyUncheckedCreateInput.schema';

export  const  ConstructionCompanyCreateOneSchema  =  z.object({

    data:  z.union([

        ConstructionCompanyCreateInputObjectSchema,

        ConstructionCompanyUncheckedCreateInputObjectSchema,

    ]),

});

Code of "...\schemas\objects\ConstructionCompanyUncheckedCreateInput.schema.ts":

import { z } from  'zod';

import { ConstructionCompanyProjectUncheckedCreateNestedManyWithoutConstructionCompanyInputObjectSchema } from  './ConstructionCompanyProjectUncheckedCreateNestedManyWithoutConstructionCompanyInput.schema';

import  type { Prisma } from  '@prisma/client';

const  Schema:  z.ZodType<Prisma.ConstructionCompanyUncheckedCreateInput> =  z

    .object({

    ConstructionCompanyId:  z.string().optional(),

    CreatedAt:  z.coerce.date().optional(),

    CreatedByUserId:  z.string().optional().nullable(),

    ModifiedAt:  z.coerce.date().optional().nullable(),

    ModifiedByUserId:  z.string().optional().nullable(),

    Name:  z.string(),

    ConstructionCompanyProject:  z

        .lazy(

            () =>

                ConstructionCompanyProjectUncheckedCreateNestedManyWithoutConstructionCompanyInputObjectSchema,

        )

        .optional(),

    })

    .strict();

export  const  ConstructionCompanyUncheckedCreateInputObjectSchema  =  Schema;

Code of: "...\schemas\objects\ConstructionCompanyCreateInput.schema.ts":

import { z } from  'zod';

import { ConstructionCompanyProjectCreateNestedManyWithoutConstructionCompanyInputObjectSchema } from  './ConstructionCompanyProjectCreateNestedManyWithoutConstructionCompanyInput.schema';

import  type { Prisma } from  '@prisma/client';

const  Schema:  z.ZodType<Prisma.ConstructionCompanyCreateInput> =  z

    .object({

    ConstructionCompanyId:  z.string().optional(),

    CreatedAt:  z.coerce.date().optional(),

    CreatedByUserId:  z.string().optional().nullable(),

    ModifiedAt:  z.coerce.date().optional().nullable(),

    ModifiedByUserId:  z.string().optional().nullable(),

    Name:  z.string(),

    ConstructionCompanyProject:  z

        .lazy(

            () =>

                    ConstructionCompanyProjectCreateNestedManyWithoutConstructionCompanyInputObjectSchema,

            )

            .optional(),

        })

        .strict();

export  const  ConstructionCompanyCreateInputObjectSchema  =  Schema;

Any ideas?

ADSNB commented 7 months ago

I created a repo where we can reproduce the error with the vs code intellisense.

Repo: https://github.com/ADSNB/intellisense-bug-zod-infer

Basically to initialize the repo you should execute "npm install" and "npx prisma generate" to generate the schemas and objects from prisma database.

Open the file "src\app\comp1\constructionCompany\component\test.tsx".

If we comment z.infer line the intellisense will work: Untitled

If we uncomment z.infer line the intellisense will stop working in entire project: Untitled2

RyanCavanaugh commented 7 months ago

I've tried unsuccessfully to get a repro of this via tsc in latest, so this is probably something LS-specific