-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add diagnostics to remind adding tsconfig file for certain external project #11932
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,11 +239,11 @@ namespace ts { | |
const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); | ||
const fileName = diagnostic.file.fileName; | ||
const relativeFileName = convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)); | ||
output += `${ relativeFileName }(${ line + 1 },${ character + 1 }): `; | ||
output += `${relativeFileName}(${line + 1},${character + 1}): `; | ||
} | ||
|
||
const category = DiagnosticCategory[diagnostic.category].toLowerCase(); | ||
output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }${ host.getNewLine() }`; | ||
output += `${category} TS${diagnostic.code}: ${flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine())}${host.getNewLine()}`; | ||
} | ||
return output; | ||
} | ||
|
@@ -1316,11 +1316,11 @@ namespace ts { | |
} | ||
else if (shouldAddFile) { | ||
findSourceFile(resolution.resolvedFileName, | ||
toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), | ||
toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), | ||
/*isDefaultLib*/ false, | ||
file, | ||
skipTrivia(file.text, file.imports[i].pos), | ||
file.imports[i].end); | ||
file, | ||
skipTrivia(file.text, file.imports[i].pos), | ||
file.imports[i].end); | ||
} | ||
|
||
if (isFromNodeModulesSearch) { | ||
|
@@ -1537,13 +1537,22 @@ namespace ts { | |
const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName); | ||
// Report error if the output overwrites input file | ||
if (filesByName.contains(emitFilePath)) { | ||
createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); | ||
let chain: DiagnosticMessageChain; | ||
const options = program.getCompilerOptions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should not option be captured from enclosing scope? |
||
if (!options.configFilePath) { | ||
// The program is from either inferred project or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "inferred project or" what? |
||
chain = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Adding_a_tsconfig_json_file_will_help_organizing_projects_with_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig); | ||
} | ||
chain = chainDiagnosticMessages(chain, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file, emitFileName); | ||
const diagnostic = createCompilerDiagnosticFromMessageChain(chain); | ||
createEmitBlockingDiagnostics(emitFileName, diagnostic); | ||
} | ||
|
||
// Report error if multiple files write into same file | ||
if (emitFilesSeen.contains(emitFilePath)) { | ||
// Already seen the same emit file - report error | ||
createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files); | ||
const diagnostic = createCompilerDiagnostic(Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files, emitFileName); | ||
createEmitBlockingDiagnostics(emitFileName, diagnostic); | ||
} | ||
else { | ||
emitFilesSeen.set(emitFilePath, true); | ||
|
@@ -1552,9 +1561,9 @@ namespace ts { | |
} | ||
} | ||
|
||
function createEmitBlockingDiagnostics(emitFileName: string, message: DiagnosticMessage) { | ||
function createEmitBlockingDiagnostics(emitFileName: string, diag: Diagnostic) { | ||
hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true); | ||
programDiagnostics.add(createCompilerDiagnostic(message, emitFileName)); | ||
programDiagnostics.add(diag); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,7 +374,9 @@ namespace ts.server { | |
|
||
private getCompilerOptionsDiagnostics(args: protocol.CompilerOptionsDiagnosticsRequestArgs) { | ||
const project = this.getProject(args.projectFileName); | ||
return this.convertToDiagnosticsWithLinePosition(project.getLanguageService().getCompilerOptionsDiagnostics(), /*scriptInfo*/ undefined); | ||
let diagnostics = this.convertToDiagnosticsWithLinePosition(project.getLanguageService().getCompilerOptionsDiagnostics(), /*scriptInfo*/ undefined); | ||
|
||
return diagnostics; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this split needed? |
||
} | ||
|
||
private convertToDiagnosticsWithLinePosition(diagnostics: Diagnostic[], scriptInfo: ScriptInfo) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile01.js' because it would overwrite input file. | ||
Adding a tsconfig.json file will help organizing projects with both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig | ||
|
||
|
||
!!! error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile01.js' because it would overwrite input file. | ||
!!! error TS5055: Adding a tsconfig.json file will help organizing projects with both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig | ||
==== tests/cases/conformance/salsa/myFile01.js (0 errors) ==== | ||
|
||
export default "hello"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile02.js' because it would overwrite input file. | ||
Adding a tsconfig.json file will help organizing projects with both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig | ||
|
||
|
||
!!! error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile02.js' because it would overwrite input file. | ||
!!! error TS5055: Adding a tsconfig.json file will help organizing projects with both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig | ||
==== tests/cases/conformance/salsa/myFile02.js (0 errors) ==== | ||
|
||
export default "hello"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to
"will help organize projects that contain both TypeScript and JavaScript files."