Skip to content

Commit b048f5f

Browse files
kyliauayazhafiz
authored andcommitted
fix: misleading error message about missing config when opening new file
This commit fixes a false alarm that says a config file cannot be found when the language server tries to open a file for the first time. We actually make two calls to `openClientFile()`. 1. In the first call, if the project doesn't already exist, the method will create a project but it will not return the config filename. 2. In the second call, since the project has already been created, the call to `openClientFile()` should succeed and we should receive a config filename. If we don't receive one then it is an error, and we should log message here instead of logging it in step (1).
1 parent 7a13d08 commit b048f5f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

server/src/session.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export class Session {
205205
const {configFileName} = this.projectService.openClientFile(scriptInfo.fileName);
206206
if (!configFileName) {
207207
// Failed to find a config file. There is nothing we could do.
208+
this.connection.console.error(`No config file for ${scriptInfo.fileName}`);
208209
return;
209210
}
210211
project = this.projectService.findProject(configFileName);
@@ -266,7 +267,13 @@ export class Session {
266267
this.connection.console.error(configFileErrors.map(e => e.messageText).join('\n'));
267268
}
268269
if (!configFileName) {
269-
this.connection.console.error(`No config file for ${filePath}`);
270+
// It is not really an error if there is no config file, because the
271+
// first call to openClientFile() will create a project for the file if
272+
// it does not exist, but the method will not return the config filename.
273+
// In subsequent operations, we'll call this.getDefaultProjectForScriptInfo(),
274+
// and there we make a second call to openClientFile(). By then, since
275+
// the project has already been created, we will receive the config
276+
// filename, and we can attach the file to the project it belongs to.
270277
return;
271278
}
272279
const project = this.projectService.findProject(configFileName);

0 commit comments

Comments
 (0)