Add event for reporting tsconfig errors
This commit is contained in:
parent
71fc58197c
commit
c14362e2ae
3 changed files with 26 additions and 16 deletions
|
@ -2748,6 +2748,10 @@
|
||||||
"category": "Message",
|
"category": "Message",
|
||||||
"code": 6128
|
"code": 6128
|
||||||
},
|
},
|
||||||
|
"The config file '{0}' found doesn't contain any source files.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 6129
|
||||||
|
},
|
||||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 7005
|
"code": 7005
|
||||||
|
|
|
@ -1096,12 +1096,12 @@ namespace ts.server {
|
||||||
* @param filename is absolute pathname
|
* @param filename is absolute pathname
|
||||||
* @param fileContent is a known version of the file content that is more up to date than the one on disk
|
* @param fileContent is a known version of the file content that is more up to date than the one on disk
|
||||||
*/
|
*/
|
||||||
openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind) {
|
openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind): { info: ScriptInfo, configFileName?: string, configFileErrors?: Diagnostic[] } {
|
||||||
this.openOrUpdateConfiguredProjectForFile(fileName);
|
const { configFileName, configFileErrors } = this.openOrUpdateConfiguredProjectForFile(fileName);
|
||||||
const info = this.openFile(fileName, /*openedByClient*/ true, fileContent, scriptKind);
|
const info = this.openFile(fileName, /*openedByClient*/ true, fileContent, scriptKind);
|
||||||
this.addOpenFile(info);
|
this.addOpenFile(info);
|
||||||
this.printProjects();
|
this.printProjects();
|
||||||
return info;
|
return { info, configFileName, configFileErrors };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1109,7 +1109,7 @@ namespace ts.server {
|
||||||
* we first detect if there is already a configured project created for it: if so, we re-read
|
* we first detect if there is already a configured project created for it: if so, we re-read
|
||||||
* the tsconfig file content and update the project; otherwise we create a new one.
|
* the tsconfig file content and update the project; otherwise we create a new one.
|
||||||
*/
|
*/
|
||||||
openOrUpdateConfiguredProjectForFile(fileName: string) {
|
openOrUpdateConfiguredProjectForFile(fileName: string): { configFileName?: string, configFileErrors?: Diagnostic[] } {
|
||||||
const searchPath = ts.normalizePath(getDirectoryPath(fileName));
|
const searchPath = ts.normalizePath(getDirectoryPath(fileName));
|
||||||
this.log("Search path: " + searchPath, "Info");
|
this.log("Search path: " + searchPath, "Info");
|
||||||
const configFileName = this.findConfigFile(searchPath);
|
const configFileName = this.findConfigFile(searchPath);
|
||||||
|
@ -1119,7 +1119,7 @@ namespace ts.server {
|
||||||
if (!project) {
|
if (!project) {
|
||||||
const configResult = this.openConfigFile(configFileName, fileName);
|
const configResult = this.openConfigFile(configFileName, fileName);
|
||||||
if (!configResult.success) {
|
if (!configResult.success) {
|
||||||
this.log("Error opening config file " + configFileName + " " + configResult.errorMsg);
|
return { configFileName, configFileErrors: configResult.errors };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.log("Opened configuration file " + configFileName, "Info");
|
this.log("Opened configuration file " + configFileName, "Info");
|
||||||
|
@ -1133,6 +1133,7 @@ namespace ts.server {
|
||||||
else {
|
else {
|
||||||
this.log("No config files found.");
|
this.log("No config files found.");
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1222,24 +1223,25 @@ namespace ts.server {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
configFileToProjectOptions(configFilename: string): { succeeded: boolean, projectOptions?: ProjectOptions, error?: ProjectOpenResult } {
|
configFileToProjectOptions(configFilename: string): { succeeded: boolean, projectOptions?: ProjectOptions, errors?: Diagnostic[] } {
|
||||||
configFilename = ts.normalizePath(configFilename);
|
configFilename = ts.normalizePath(configFilename);
|
||||||
// file references will be relative to dirPath (or absolute)
|
// file references will be relative to dirPath (or absolute)
|
||||||
const dirPath = ts.getDirectoryPath(configFilename);
|
const dirPath = ts.getDirectoryPath(configFilename);
|
||||||
const contents = this.host.readFile(configFilename);
|
const contents = this.host.readFile(configFilename);
|
||||||
const rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.parseConfigFileTextToJson(configFilename, contents);
|
const rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.parseConfigFileTextToJson(configFilename, contents);
|
||||||
if (rawConfig.error) {
|
if (rawConfig.error) {
|
||||||
return { succeeded: false, error: rawConfig.error };
|
return { succeeded: false, errors: [rawConfig.error] };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const parsedCommandLine = ts.parseJsonConfigFileContent(rawConfig.config, this.host, dirPath, /*existingOptions*/ {}, configFilename);
|
const parsedCommandLine = ts.parseJsonConfigFileContent(rawConfig.config, this.host, dirPath, /*existingOptions*/ {}, configFilename);
|
||||||
Debug.assert(!!parsedCommandLine.fileNames);
|
Debug.assert(!!parsedCommandLine.fileNames);
|
||||||
|
|
||||||
if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) {
|
if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) {
|
||||||
return { succeeded: false, error: { errorMsg: "tsconfig option errors" } };
|
return { succeeded: false, errors: parsedCommandLine.errors };
|
||||||
}
|
}
|
||||||
else if (parsedCommandLine.fileNames.length === 0) {
|
else if (parsedCommandLine.fileNames.length === 0) {
|
||||||
return { succeeded: false, error: { errorMsg: "no files found" } };
|
const error = createCompilerDiagnostic(Diagnostics.The_config_file_0_found_doesn_t_contain_any_source_files, configFilename);
|
||||||
|
return { succeeded: false, errors: [error] };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const projectOptions: ProjectOptions = {
|
const projectOptions: ProjectOptions = {
|
||||||
|
@ -1252,10 +1254,10 @@ namespace ts.server {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
openConfigFile(configFilename: string, clientFileName?: string): ProjectOpenResult {
|
openConfigFile(configFilename: string, clientFileName?: string): { success: boolean, project?: Project, errors?: Diagnostic[] } {
|
||||||
const { succeeded, projectOptions, error } = this.configFileToProjectOptions(configFilename);
|
const { succeeded, projectOptions, errors } = this.configFileToProjectOptions(configFilename);
|
||||||
if (!succeeded) {
|
if (!succeeded) {
|
||||||
return error;
|
return { success: false, errors };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const project = this.createProject(configFilename, projectOptions);
|
const project = this.createProject(configFilename, projectOptions);
|
||||||
|
@ -1265,7 +1267,8 @@ namespace ts.server {
|
||||||
project.addRoot(info);
|
project.addRoot(info);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return { errorMsg: "specified file " + rootFilename + " not found" };
|
const error = createCompilerDiagnostic(Diagnostics.File_0_not_found, rootFilename);
|
||||||
|
return { success: false, errors: [error] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
project.finishGraph();
|
project.finishGraph();
|
||||||
|
@ -1286,9 +1289,9 @@ namespace ts.server {
|
||||||
this.removeProject(project);
|
this.removeProject(project);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const { succeeded, projectOptions, error } = this.configFileToProjectOptions(project.projectFilename);
|
const { succeeded, projectOptions, errors } = this.configFileToProjectOptions(project.projectFilename);
|
||||||
if (!succeeded) {
|
if (!succeeded) {
|
||||||
return error;
|
return errors;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const oldFileNames = project.compilerService.host.roots.map(info => info.fileName);
|
const oldFileNames = project.compilerService.host.roots.map(info => info.fileName);
|
||||||
|
|
|
@ -561,7 +561,10 @@ namespace ts.server {
|
||||||
*/
|
*/
|
||||||
private openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind) {
|
private openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind) {
|
||||||
const file = ts.normalizePath(fileName);
|
const file = ts.normalizePath(fileName);
|
||||||
this.projectService.openClientFile(file, fileContent, scriptKind);
|
const { info, configFileName, configFileErrors } = this.projectService.openClientFile(file, fileContent, scriptKind);
|
||||||
|
if (configFileErrors) {
|
||||||
|
this.event({ triggerFile: fileName, configFile: configFileName, diagnostics: configFileErrors }, "configFileDiag");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody {
|
private getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody {
|
||||||
|
|
Loading…
Reference in a new issue