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

Report an error on ts plugin version mismatch #143

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/tsPlugin/initTsPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { version as gratsTsVersion } from "typescript";
import type * as TS from "typescript/lib/tsserverlibrary";
import { extract } from "../Extractor";
import { FAKE_ERROR_CODE } from "../utils/DiagnosticError";
Expand Down Expand Up @@ -26,6 +27,24 @@ export function initTsPlugin(modules: { typescript: typeof TS }) {
proxy[k] = (...args: Array<any>) => x.apply(info.languageService, args);
}

if (ts.version !== gratsTsVersion) {
proxy.getCompilerOptionsDiagnostics = (): TS.Diagnostic[] => {
const prev = info.languageService.getCompilerOptionsDiagnostics();
return [
...prev,
{
category: ts.DiagnosticCategory.Error,
code: 0,
messageText: typeScriptVersionMismatch(ts.version),
file: undefined,
start: undefined,
length: undefined,
},
];
};
return proxy;
}

proxy.getSyntacticDiagnostics = (filename): TS.DiagnosticWithLocation[] => {
const prior = info.languageService.getSyntacticDiagnostics(filename);
const doc = info.languageService.getProgram()?.getSourceFile(filename);
Expand Down Expand Up @@ -103,3 +122,10 @@ export function initTsPlugin(modules: { typescript: typeof TS }) {

return { create };
}

function typeScriptVersionMismatch(extensionVersion: string) {
return `grats-plugin-ts error: The version of TypeScript picked up by Grats does not match the version used by VSCode.
Grats is using ${gratsTsVersion} but VSCode is using ${extensionVersion}.
This may be caused by a yarn.lock or package-lock.json which is pinning a different version of TypeScript for Grats than the version used by the rest of your project.
See https://github.com/captbaritone/grats/issues/142> for more information.`;
}
Loading