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

fix: vue-tsc does not show ts errors in the terminal with --incremental #158

Merged
Merged
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion packages/typescript/lib/node/decorateProgram.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Language } from '@volar/language-core';
import type * as ts from 'typescript';
import { notEmpty } from './utils';
import { getServiceScript, notEmpty } from './utils';
import { transformDiagnostic } from './transform';

export function decorateProgram(language: Language, program: ts.Program) {
Expand All @@ -11,6 +11,7 @@ export function decorateProgram(language: Language, program: ts.Program) {
const getSyntacticDiagnostics = program.getSyntacticDiagnostics;
const getSemanticDiagnostics = program.getSemanticDiagnostics;
const getGlobalDiagnostics = program.getGlobalDiagnostics;
const getSourceFileByPath = program.getSourceFileByPath;

// for tsc --noEmit --watch
// @ts-ignore
Expand Down Expand Up @@ -46,4 +47,17 @@ export function decorateProgram(language: Language, program: ts.Program) {
.map(d => transformDiagnostic(language, d))
.filter(notEmpty);
};

// fix https://github.com/vuejs/language-tools/issues/4099
program.getSourceFileByPath = path => {
const sourceFile = getSourceFileByPath(path);
if (sourceFile) {
const [serviceScript, sourceScript] = getServiceScript(language, sourceFile.fileName);
if (serviceScript) {
sourceFile.text = sourceScript.snapshot.getText(0, sourceScript.snapshot.getLength())
+ sourceFile.text.substring(sourceScript.snapshot.getLength());
}
}
return sourceFile;
};
}
4 changes: 2 additions & 2 deletions packages/typescript/lib/node/proxyCreateProgram.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as ts from 'typescript';
import { decorateProgram } from './decorateProgram';
import { LanguagePlugin, createLanguage } from '@volar/language-core';
import type * as ts from 'typescript';
import { createResolveModuleName } from '../resolveModuleName';
import { decorateProgram } from './decorateProgram';

export function proxyCreateProgram(
ts: typeof import('typescript'),
Expand Down
12 changes: 0 additions & 12 deletions packages/typescript/lib/node/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type * as ts from 'typescript';
import { getServiceScript, notEmpty } from './utils';

const transformedDiagnostics = new WeakMap<ts.Diagnostic, ts.Diagnostic | undefined>();
const transformedSourceFiles = new WeakMap<ts.SourceFile, ts.SourceFile>();

export function transformCallHierarchyItem(language: Language, item: ts.CallHierarchyItem, filter: (data: CodeInformation) => boolean): ts.CallHierarchyItem {
const span = transformSpan(language, item.file, item.span, filter);
Expand Down Expand Up @@ -39,7 +38,6 @@ export function transformDiagnostic<T extends ts.Diagnostic>(language: Language,
...diagnostic,
start: sourceSpan.start,
length: sourceSpan.length,
file: transformSourceFile(diagnostic.file, sourceScript.snapshot.getText(0, sourceScript.snapshot.getLength())),
});
}
}
Expand All @@ -54,16 +52,6 @@ export function transformDiagnostic<T extends ts.Diagnostic>(language: Language,
return transformedDiagnostics.get(diagnostic) as T | undefined;
}

export function transformSourceFile(sourceFile: ts.SourceFile, sourceText: string): ts.SourceFile {
if (!transformedSourceFiles.has(sourceFile)) {
transformedSourceFiles.set(sourceFile, {
...sourceFile,
text: sourceText,
});
}
return transformedSourceFiles.get(sourceFile)!;
}

export function transformFileTextChanges(language: Language, changes: ts.FileTextChanges, filter: (data: CodeInformation) => boolean): ts.FileTextChanges | undefined {
const [_, source] = getServiceScript(language, changes.fileName);
if (source) {
Expand Down
Loading