Skip to content

fix: LS not showing existing diagnostics on file open #966

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

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions integration/lsp/viewengine_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ describe('Angular language server', () => {
},
});
});

it('should show existing diagnostics on external template', async () => {
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
languageId: 'typescript',
version: 1,
text: `{{ doesnotexist }}`,
},
});
const diagnostics: lsp.Diagnostic[] = await new Promise(resolve => {
client.onNotification(
lsp.PublishDiagnosticsNotification.type, (params: lsp.PublishDiagnosticsParams) => {
resolve(params.diagnostics);
});
});
expect(diagnostics.length).toBe(1);
expect(diagnostics[0].message).toContain(`Identifier 'doesnotexist' is not defined.`);
});
});

describe('initialization', () => {
Expand Down
18 changes: 7 additions & 11 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,9 @@ export class Session {
// configFileErrors is an empty array even if there's no error, so check length.
this.connection.console.error(configFileErrors.map(e => e.messageText).join('\n'));
}
if (!configFileName) {
// It is not really an error if there is no config file, because the
// first call to openClientFile() will create a project for the file if
// it does not exist, but the method will not return the config filename.
// In subsequent operations, we'll call this.getDefaultProjectForScriptInfo(),
// and there we make a second call to openClientFile(). By then, since
// the project has already been created, we will receive the config
// filename, and we can attach the file to the project it belongs to.
return;
}
const project = this.projectService.findProject(configFileName);
const project = configFileName ?
this.projectService.findProject(configFileName) :
this.projectService.getScriptInfo(filePath)?.containingProjects.find(isConfiguredProject);
if (!project) {
this.connection.console.error(`Failed to find project for ${filePath}`);
return;
Expand Down Expand Up @@ -577,3 +569,7 @@ function isAngularProject(project: ts.server.Project, ngCore: string): boolean {
}
return false;
}

function isConfiguredProject(project: ts.server.Project): project is ts.server.ConfiguredProject {
return project.projectKind === ts.server.ProjectKind.Configured;
}