WarningImHack3r / intellij-shadcn-plugin

Add, update and delete your shadcn/ui components without leaving your IDE
5 stars 1 forks source link

[crash] Comments parsing removes parts of the tsconfig in some cases #48

Closed shimizu-izumi closed 5 months ago

shimizu-izumi commented 5 months ago

What is the issue?

Crashes with JSON decoding exception

What are the steps to reproduce this issue?

Update the plugin to the newest version and create a Next.js project (I used yarn create t3-app)

What were you expecting to happen?

It working correctly

Paste any relevant logs, error output, etc.

kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 473: Expected colon ':', but had ',' instead at path: $
JSON input: .....eUrl": ".",
"paths": {
"~*.ts",
"***.cjs",
"***.ts"
],
"excl.....
    at com.github.warningimhack3r.intellijshadcnplugin.backend.sources.Source.parseTsConfig(Source.kt:120)
    at com.github.warningimhack3r.intellijshadcnplugin.backend.sources.impl.ReactSource.resolveAlias(ReactSource.kt:42)
    at com.github.warningimhack3r.intellijshadcnplugin.backend.sources.Source.getInstalledComponents(Source.kt:154)
    at com.github.warningimhack3r.intellijshadcnplugin.ui.ISPWindowContents$panel$1$1.invokeSuspend(ISPWindowContents.kt:54)
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelled}@4d5be620, Dispatchers.Default]

What OS are you experiencing the problem on?

Windows

Additional platform information

Build version: WebStorm 2024.1.4 Build: #WS-241.17890.13 June 4, 2024 JRE: 17.0.11+1-b1207.24, JetBrains s.r.o. JVM: 17.0.11+1-b1207.24, OpenJDK 64-Bit Server VM, JetBrains s.r.o. Operating System: Windows 11.0 (amd64)

=== Plugins === Custom plugins: [Space (241.17890.8), Catppuccin Theme (3.3.1), Ideolog (222.3.2.0), .env files support (2024.1), GitHub Copilot (1.5.9.5799), shadcn/ui Components Manager (0.8.3), Atom Material Icons (97.0.0), Rainbow Brackets (2024.2.4-241)] Disabled plugins:[Discord Rich Presence (1.4.0)]

Duplicates

WarningImHack3r commented 5 months ago

Hi there @shimizu-izumi, your tsconfig.json doesn’t seem valid, is it the file this snippet comes from? Can you check it and send it here if it seems correct?

shimizu-izumi commented 5 months ago

Yes, the crash is caused by my tsconfig.json which is valid, the only thing I touched was removing the comments. The crash seems to happen because I can't properly parse "baseUrl":".",`` in the compiler options object

shimizu-izumi commented 5 months ago
{
  "compilerOptions": {
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "es2022",
    "allowJs": true,
    "resolveJsonModule": true,
    "moduleDetection": "force",
    "isolatedModules": true,

    "strict": true,
    "noUncheckedIndexedAccess": true,
    "checkJs": true,

    "lib": ["dom", "dom.iterable", "ES2022"],
    "noEmit": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "jsx": "preserve",
    "plugins": [{ "name": "next" }],
    "incremental": true,

    "baseUrl": ".",
    "paths": {
      "~/*": ["./src/*"]
    }
  },
  "include": [
    ".eslintrc.cjs",
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "**/*.cjs",
    "**/*.js",
    ".next/types/**/*.ts"
  ],
  "exclude": ["node_modules"]
}
WarningImHack3r commented 5 months ago

Oooooh I get it: I'm removing comments by replacing everything between /* and */ by matching a regex. Unfortunately, I don't check whether I'm inside a key or value or not.

What's happening is that you happen to have a matching pattern it's removing: from the /* in your ~/* path key to the */ inside the **/*.ts in your include array!

Thus, the file becomes:

...
"baseUrl": ".",
"paths": {
"~|*.ts",
"***.cjs",
"***.ts"
],
...

(where | is where stuff has been removed), making the file completely invalid in-memory!

Such a bad luck scenario :O I'll try to fix that ASAP :)

WarningImHack3r commented 5 months ago

@shimizu-izumi your current config will work with the update I just pushed, but the plugin is still not 100% accurate with tsconfig.json files including non-standard-JSON features. It's still a temporary patch to support simple cases, proper fully-featured JSON5 files support is coming in a future update.

Sorry for your 2 recent issues!

shimizu-izumi commented 5 months ago

No problem, it's not like they hindered me to work on the project at all. Also I don't know if it's part of the plugin but when adding a component WebStorm gives me a notification that it needs some radix UI package and when I click install nothing happens. I use yarn, is it not compatible, a big or did I simply miss a setting for it?

WarningImHack3r commented 5 months ago

WebStorm gives me a notification that it needs some radix UI package and when I click install nothing happens. I use yarn, is it not compatible, a big or did I simply miss a setting for it?

I indeed trigger this from my plugin but it should install the dependency in the background when you click install, and then notify you again when it's done. If it's not the case after a few seconds (regular time to run yarn i radix-ui), can you please open a new issue?

shimizu-izumi commented 5 months ago

Sure, I will observe it more tomorrow and create a new issue if really nothing happens

WarningImHack3r commented 5 months ago

@shimizu-izumi the update is live! Sorry for the inconvenience once again :(