Skip to content

Report declaration emit errors #699

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

Merged
merged 5 commits into from
Sep 18, 2014
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
25 changes: 21 additions & 4 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1598,9 +1598,9 @@ module ts {
}

// Only perform incremental parsing on open files that are being edited. If a file was
// open, but is now closed, we want to reparse entirely so we don't have any tokens that
// open, but is now closed, we want to re-parse entirely so we don't have any tokens that
// are holding onto expensive script snapshot instances on the host. Similarly, if a
// file was closed, then we always want to reparse. This is so our tree doesn't keep
// file was closed, then we always want to re-parse. This is so our tree doesn't keep
// the old buffer alive that represented the file on disk (as the host has moved to a
// new text buffer).
var textChangeRange: TypeScript.TextChangeRange = null;
Expand Down Expand Up @@ -1650,12 +1650,29 @@ module ts {
return program.getDiagnostics(getSourceFile(filename).getSourceFile());
}

// getSemanticDiagnostiscs return array of Diagnostics. If '-d' is not enabled, only report semantic errors
// If '-d' enabled, report both semantic and emitter errors
function getSemanticDiagnostics(filename: string) {
synchronizeHostData();

filename = TypeScript.switchToForwardSlashes(filename)

return getFullTypeCheckChecker().getDiagnostics(getSourceFile(filename));
var compilerOptions = program.getCompilerOptions();
var checker = getFullTypeCheckChecker();
var targetSourceFile = getSourceFile(filename);

// Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file.
// Therefore only get diagnostics for given file.

var allDiagnostics = checker.getDiagnostics(targetSourceFile);
if (compilerOptions.declaration) {
// If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface
// Get emitter-diagnostics requires calling TypeChecker.emitFiles so we have to define CompilerHost.writer which does nothing because emitFiles function has side effects defined by CompilerHost.writer
var savedWriter = writer;
writer = (filename: string, data: string, writeByteOrderMark: boolean) => { };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems wrong. A more appropriate pattern would be:

var savedWriter = writer;
allDiagnostics ...
writer = savedWriter;

allDiagnostics = allDiagnostics.concat(checker.emitFiles(targetSourceFile).errors);
writer = savedWriter;
}
return allDiagnostics
}

function getCompilerOptionsDiagnostics() {
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/fourslash/getSemanticDiagnosticForDeclaration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />

// @declaration: true
//// interface privateInterface {}
//// export class Bar implements /*1*/privateInterface/*2*/{ }

verify.errorExistsBetweenMarkers("1", "2");
verify.numberOfErrorsInCurrentFile(1);


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />

//// interface privateInterface {}
//// export class Bar implements /*1*/privateInterface/*2*/{ }

verify.numberOfErrorsInCurrentFile(0);