diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 7e2e9430f7e..5561369422a 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -372,7 +372,8 @@ namespace ts { errorCount => result.onWatchStatusChange!( createCompilerDiagnostic(getWatchErrorSummaryDiagnosticMessage(errorCount), errorCount), newLine, - compilerOptions + compilerOptions, + errorCount ) ); }; @@ -480,14 +481,14 @@ namespace ts { return createProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences); } - export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void; + export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number) => void; /** Create the program with rootNames and options, if they are undefined, oldProgram and new configFile diagnostics create new program */ export type CreateProgram = (rootNames: ReadonlyArray | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: ReadonlyArray, projectReferences?: ReadonlyArray | undefined) => T; /** Host that has watch functionality used in --watch mode */ export interface WatchHost { /** If provided, called with Diagnostic message that informs about change in watch status */ - onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void; + onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number): void; /** Used to watch changes in source files, missing files needed to update the program or config file */ watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index e514ca01e79..22d28efd2f4 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -241,7 +241,7 @@ namespace ts.GoToDefinition { function getConstructSignatureDefinition(): DefinitionInfo[] | undefined { // Applicable only if we are in a new expression, or we are on a constructor declaration // and in either case the symbol has a construct signature definition, i.e. class - if (symbol.flags & SymbolFlags.Class && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) { + if (symbol.flags & SymbolFlags.Class && !(symbol.flags & SymbolFlags.Function) && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) { const cls = find(filteredDeclarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration"); return getSignatureDefinition(cls.members, /*selectConstructors*/ true); } diff --git a/src/testRunner/unittests/tscWatch/watchApi.ts b/src/testRunner/unittests/tscWatch/watchApi.ts index 35527b73701..facd668b825 100644 --- a/src/testRunner/unittests/tscWatch/watchApi.ts +++ b/src/testRunner/unittests/tscWatch/watchApi.ts @@ -37,4 +37,32 @@ namespace ts.tscWatch { checkProgramActualFiles(program, [mainFile.path, libFile.path, settingsJson.path]); }); }); + + describe("unittests:: tsc-watch:: watchAPI:: tsc-watch expose error count to watch status reporter", () => { + const projectRoot = "/user/username/projects/project"; + const configFileJson: any = { + compilerOptions: { module: "commonjs" }, + files: ["index.ts"] + }; + const config: File = { + path: `${projectRoot}/tsconfig.json`, + content: JSON.stringify(configFileJson) + }; + const mainFile: File = { + path: `${projectRoot}/index.ts`, + content: "let compiler = new Compiler(); for (let i = 0; j < 5; i++) {}" + }; + + it("verify that the error count is correctly passed down to the watch status reporter", () => { + const files = [libFile, mainFile, config]; + const host = createWatchedSystem(files, { currentDirectory: projectRoot }); + let watchedErrorCount; + const reportWatchStatus: WatchStatusReporter = (_, __, ___, errorCount) => { + watchedErrorCount = errorCount; + }; + const compilerHost = createWatchCompilerHostOfConfigFile(config.path, {}, host, /*createProgram*/ undefined, /*reportDiagnostic*/ undefined, reportWatchStatus); + createWatchProgram(compilerHost); + assert.equal(watchedErrorCount, 2, "The error count was expected to be 2 for the file change"); + }); + }); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index bffe2114d19..67d6a98e11e 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4491,13 +4491,13 @@ declare namespace ts { createProgram?: CreateProgram; } function createIncrementalProgram({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions): T; - type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void; + type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number) => void; /** Create the program with rootNames and options, if they are undefined, oldProgram and new configFile diagnostics create new program */ type CreateProgram = (rootNames: ReadonlyArray | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: ReadonlyArray, projectReferences?: ReadonlyArray | undefined) => T; /** Host that has watch functionality used in --watch mode */ interface WatchHost { /** If provided, called with Diagnostic message that informs about change in watch status */ - onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void; + onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number): void; /** Used to watch changes in source files, missing files needed to update the program or config file */ watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; /** Used to watch resolved module's failed lookup locations, config file specs, type roots where auto type reference directives are added */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 457a1acb227..279357eddf7 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4491,13 +4491,13 @@ declare namespace ts { createProgram?: CreateProgram; } function createIncrementalProgram({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions): T; - type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void; + type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number) => void; /** Create the program with rootNames and options, if they are undefined, oldProgram and new configFile diagnostics create new program */ type CreateProgram = (rootNames: ReadonlyArray | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: ReadonlyArray, projectReferences?: ReadonlyArray | undefined) => T; /** Host that has watch functionality used in --watch mode */ interface WatchHost { /** If provided, called with Diagnostic message that informs about change in watch status */ - onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void; + onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number): void; /** Used to watch changes in source files, missing files needed to update the program or config file */ watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; /** Used to watch resolved module's failed lookup locations, config file specs, type roots where auto type reference directives are added */ diff --git a/tests/cases/fourslash/gotoDefinitionConstructorFunction.ts b/tests/cases/fourslash/gotoDefinitionConstructorFunction.ts new file mode 100644 index 00000000000..aa149e70d7d --- /dev/null +++ b/tests/cases/fourslash/gotoDefinitionConstructorFunction.ts @@ -0,0 +1,15 @@ +/// +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @filename: gotoDefinitionConstructorFunction.js +//// function /*end*/StringStreamm() { +//// } +//// StringStreamm.prototype = { +//// }; +//// +//// function runMode () { +//// new [|/*start*/StringStreamm|]() +//// }; + +verify.goToDefinition('start', 'end')