Skip to content

Commit b5ed7f3

Browse files
author
zhengbli
committed
Add support for jsconfig.json in language service
1 parent 31bbac3 commit b5ed7f3

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,9 @@ namespace ts {
493493
* @param basePath A root directory to resolve relative path entries in the config
494494
* file to. e.g. outDir
495495
*/
496-
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}): ParsedCommandLine {
497-
const { options: optionsFromJsonConfigFile, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath);
496+
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, configFileName: string, existingOptions: CompilerOptions = {}): ParsedCommandLine {
497+
const basePath = getDirectoryPath(configFileName);
498+
const { options: optionsFromJsonConfigFile, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath, configFileName);
498499

499500
const options = extend(existingOptions, optionsFromJsonConfigFile);
500501
return {
@@ -547,10 +548,14 @@ namespace ts {
547548
}
548549
}
549550

550-
export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string): { options: CompilerOptions, errors: Diagnostic[] } {
551+
export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: CompilerOptions, errors: Diagnostic[] } {
551552
const options: CompilerOptions = {};
552553
const errors: Diagnostic[] = [];
553554

555+
if (configFileName && getBaseFileName(configFileName) === "jsconfig.json") {
556+
options.allowJs = true;
557+
}
558+
554559
if (!jsonOptions) {
555560
return { options, errors };
556561
}

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ namespace ts {
376376
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
377377
return;
378378
}
379-
const configParseResult = parseJsonConfigFileContent(configObject, sys, getDirectoryPath(configFileName), commandLine.options);
379+
const configParseResult = parseJsonConfigFileContent(configObject, sys, configFileName, commandLine.options);
380380
if (configParseResult.errors.length > 0) {
381381
reportDiagnostics(configParseResult.errors, /* compilerHost */ undefined);
382382
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);

src/server/editorServices.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,10 +1026,16 @@ namespace ts.server {
10261026
// the newly opened file.
10271027
findConfigFile(searchPath: string): string {
10281028
while (true) {
1029-
const fileName = ts.combinePaths(searchPath, "tsconfig.json");
1030-
if (this.host.fileExists(fileName)) {
1031-
return fileName;
1029+
const tsconfigFileName = ts.combinePaths(searchPath, "tsconfig.json");
1030+
if (this.host.fileExists(tsconfigFileName)) {
1031+
return tsconfigFileName;
1032+
}
1033+
1034+
const jsconfigFileName = ts.combinePaths(searchPath, "jsconfig.json");
1035+
if (this.host.fileExists(jsconfigFileName)) {
1036+
return jsconfigFileName;
10321037
}
1038+
10331039
const parentPath = ts.getDirectoryPath(searchPath);
10341040
if (parentPath === searchPath) {
10351041
break;
@@ -1172,15 +1178,13 @@ namespace ts.server {
11721178

11731179
configFileToProjectOptions(configFilename: string): { succeeded: boolean, projectOptions?: ProjectOptions, error?: ProjectOpenResult } {
11741180
configFilename = ts.normalizePath(configFilename);
1175-
// file references will be relative to dirPath (or absolute)
1176-
const dirPath = ts.getDirectoryPath(configFilename);
11771181
const contents = this.host.readFile(configFilename);
11781182
const rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.parseConfigFileTextToJson(configFilename, contents);
11791183
if (rawConfig.error) {
11801184
return { succeeded: false, error: rawConfig.error };
11811185
}
11821186
else {
1183-
const parsedCommandLine = ts.parseJsonConfigFileContent(rawConfig.config, this.host, dirPath);
1187+
const parsedCommandLine = ts.parseJsonConfigFileContent(rawConfig.config, this.host, configFilename);
11841188
Debug.assert(!!parsedCommandLine.fileNames);
11851189

11861190
if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) {

0 commit comments

Comments
 (0)