-
Notifications
You must be signed in to change notification settings - Fork 123
fix: match external templates to project on startup #988
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
Changes from all 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 |
---|---|---|
|
@@ -15,7 +15,7 @@ import * as notification from '../common/notifications'; | |
import {tsCompletionEntryToLspCompletionItem} from './completion'; | ||
import {tsDiagnosticToLspDiagnostic} from './diagnostic'; | ||
import {ServerHost} from './server_host'; | ||
import {filePathToUri, lspPositionToTsPosition, lspRangeToTsPositions, tsTextSpanToLspRange, uriToFilePath} from './utils'; | ||
import {filePathToUri, isConfiguredProject, lspPositionToTsPosition, lspRangeToTsPositions, tsTextSpanToLspRange, uriToFilePath} from './utils'; | ||
|
||
export interface SessionOptions { | ||
host: ServerHost; | ||
|
@@ -131,6 +131,25 @@ export class Session { | |
// project as dirty to force update the graph. | ||
project.markAsDirty(); | ||
this.info(`Enabling Ivy language service for ${project.projectName}.`); | ||
|
||
// Send diagnostics since we skipped this step when opening the file | ||
// (because language service was disabled while waiting for ngcc). | ||
// First, make sure the Angular project is complete. | ||
this.runGlobalAnalysisForNewlyLoadedProject(project); | ||
project.refreshDiagnostics(); // Show initial diagnostics | ||
} | ||
|
||
/** | ||
* Invoke the compiler for the first time so that external templates get | ||
* matched to the project they belong to. | ||
*/ | ||
private runGlobalAnalysisForNewlyLoadedProject(project: ts.server.Project) { | ||
if (!project.hasRoots()) { | ||
return; | ||
} | ||
const fileName = project.getRootScriptInfos()[0].fileName; | ||
// Getting semantic diagnostics will trigger a global analysis. | ||
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 it that getting semantic diagnostics always triggers global analysis or is this just because we're triggering diagnostics on a root file? 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. Getting semantic diagnostics always triggers global analysis, because a new compiler is created every time. Technically any file will do, not just root files, but the file must be part of the project, so root file is a convenient candidate. |
||
project.getLanguageService().getSemanticDiagnostics(fileName); | ||
} | ||
|
||
/** | ||
|
@@ -293,7 +312,6 @@ export class Session { | |
this.projectService.findProject(configFileName) : | ||
this.projectService.getScriptInfo(filePath)?.containingProjects.find(isConfiguredProject); | ||
if (!project) { | ||
this.error(`Failed to find project for ${filePath}`); | ||
return; | ||
} | ||
if (project.languageServiceEnabled) { | ||
|
@@ -553,7 +571,7 @@ export class Session { | |
return; | ||
} | ||
|
||
if (this.ivy && project instanceof ts.server.ConfiguredProject) { | ||
if (this.ivy && isConfiguredProject(project)) { | ||
// Keep language service disabled until ngcc is completed. | ||
project.disableLanguageService(); | ||
this.connection.sendNotification(notification.RunNgcc, { | ||
|
@@ -594,7 +612,3 @@ export class Session { | |
return false; | ||
} | ||
} | ||
|
||
function isConfiguredProject(project: ts.server.Project): project is ts.server.ConfiguredProject { | ||
return project.projectKind === ts.server.ProjectKind.Configured; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.