next.js
5c499049 - [next-ts-plugin] fix: language service crashes / metadata plugin not working (#77213)

Commit
1 year ago
[next-ts-plugin] fix: language service crashes / metadata plugin not working (#77213) ### Why? This PR tackles two issues: 1. The Next.js TS plugin for metadata wasn't working. 2. The language service occasionally crashes in large projects. #### The Next.js TS plugin for metadata wasn't working The plugin wasn't working due to the position mismatch of `optionalReplacementSpan` since VSCode [v1.86](https://code.visualstudio.com/updates/v1_86) due to the behavior change of mapping the `replacementSpan` with `optionalReplacementSpan` if it exists. x-ref: https://github.com/microsoft/vscode/pull/200945/files#diff-9027dfcf905374dcada6a75144ed94935254a5a6bf325a20d557201cd7fbe704R766 #### The language service occasionally crashes in large projects Since we spun up another language service and a custom language service host for metadata rules, it occasionally crashed on large projects. ### How? - Synced the `optionalReplacementSpan` to the new position. - Removed creating another language service and relying on `@typescript/vfs` for the virtual file system, which is recommended: "where files on disk aren't the source of truth". https://github.com/user-attachments/assets/b5b325a4-fd2f-4210-be68-1aa5e40229c2 ### Success Criteria - [x] Does it do completions with `export const metadata = { a }`? - [x] Does it disable the plugin with `{ enabled: false }` in the tsconfig.json? - [x] Does the language service not break when used in large projects? ### Follow Up This fix is a partial port from the commit [071d839](https://github.com/vercel/next.js/pull/77206/commits/071d83904588c10d276a09f4f1e78ec7305ff80d) and will continue to follow up on the refactors from PR #77206, including a proper test to prevent regression. --------- Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
Author
Parents
Loading