Skip to content

Commit cca32f0

Browse files
committed
Remove more try-finally blocks
1 parent 7d44a45 commit cca32f0

File tree

2 files changed

+48
-57
lines changed

2 files changed

+48
-57
lines changed

src/server/project.ts

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -852,46 +852,43 @@ namespace ts.server {
852852
*/
853853
updateGraph(): boolean {
854854
perfLogger.logStartUpdateGraph();
855-
try {
856-
this.resolutionCache.startRecordingFilesWithChangedResolutions();
857-
858-
const hasNewProgram = this.updateGraphWorker();
859-
const hasAddedorRemovedFiles = this.hasAddedorRemovedFiles;
860-
this.hasAddedorRemovedFiles = false;
861-
862-
const changedFiles: ReadonlyArray<Path> = this.resolutionCache.finishRecordingFilesWithChangedResolutions() || emptyArray;
863-
864-
for (const file of changedFiles) {
865-
// delete cached information for changed files
866-
this.cachedUnresolvedImportsPerFile.delete(file);
855+
this.resolutionCache.startRecordingFilesWithChangedResolutions();
856+
857+
const hasNewProgram = this.updateGraphWorker();
858+
const hasAddedorRemovedFiles = this.hasAddedorRemovedFiles;
859+
this.hasAddedorRemovedFiles = false;
860+
861+
const changedFiles: ReadonlyArray<Path> = this.resolutionCache.finishRecordingFilesWithChangedResolutions() || emptyArray;
862+
863+
for (const file of changedFiles) {
864+
// delete cached information for changed files
865+
this.cachedUnresolvedImportsPerFile.delete(file);
866+
}
867+
868+
// update builder only if language service is enabled
869+
// otherwise tell it to drop its internal state
870+
if (this.languageServiceEnabled) {
871+
// 1. no changes in structure, no changes in unresolved imports - do nothing
872+
// 2. no changes in structure, unresolved imports were changed - collect unresolved imports for all files
873+
// (can reuse cached imports for files that were not changed)
874+
// 3. new files were added/removed, but compilation settings stays the same - collect unresolved imports for all new/modified files
875+
// (can reuse cached imports for files that were not changed)
876+
// 4. compilation settings were changed in the way that might affect module resolution - drop all caches and collect all data from the scratch
877+
if (hasNewProgram || changedFiles.length) {
878+
this.lastCachedUnresolvedImportsList = getUnresolvedImports(this.program!, this.cachedUnresolvedImportsPerFile);
867879
}
868880

869-
// update builder only if language service is enabled
870-
// otherwise tell it to drop its internal state
871-
if (this.languageServiceEnabled) {
872-
// 1. no changes in structure, no changes in unresolved imports - do nothing
873-
// 2. no changes in structure, unresolved imports were changed - collect unresolved imports for all files
874-
// (can reuse cached imports for files that were not changed)
875-
// 3. new files were added/removed, but compilation settings stays the same - collect unresolved imports for all new/modified files
876-
// (can reuse cached imports for files that were not changed)
877-
// 4. compilation settings were changed in the way that might affect module resolution - drop all caches and collect all data from the scratch
878-
if (hasNewProgram || changedFiles.length) {
879-
this.lastCachedUnresolvedImportsList = getUnresolvedImports(this.program!, this.cachedUnresolvedImportsPerFile);
880-
}
881-
882-
this.projectService.typingsCache.enqueueInstallTypingsForProject(this, this.lastCachedUnresolvedImportsList, hasAddedorRemovedFiles);
883-
}
884-
else {
885-
this.lastCachedUnresolvedImportsList = undefined;
886-
}
881+
this.projectService.typingsCache.enqueueInstallTypingsForProject(this, this.lastCachedUnresolvedImportsList, hasAddedorRemovedFiles);
882+
}
883+
else {
884+
this.lastCachedUnresolvedImportsList = undefined;
885+
}
887886

888-
if (hasNewProgram) {
889-
this.projectProgramVersion++;
890-
}
891-
return !hasNewProgram;
892-
} finally {
893-
perfLogger.logStopUpdateGraph();
887+
if (hasNewProgram) {
888+
this.projectProgramVersion++;
894889
}
890+
perfLogger.logStopUpdateGraph();
891+
return !hasNewProgram;
895892
}
896893

897894
/*@internal*/

src/server/utilities.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,13 @@ namespace ts.server {
150150
}
151151

152152
private static run(self: ThrottledOperations, operationId: string, cb: () => void) {
153-
try {
154-
perfLogger.logStartScheduledOperation(operationId);
155-
self.pendingTimeouts.delete(operationId);
156-
if (self.logger) {
157-
self.logger.info(`Running: ${operationId}`);
158-
}
159-
cb();
160-
} finally {
161-
perfLogger.logStopScheduledOperation();
153+
perfLogger.logStartScheduledOperation(operationId);
154+
self.pendingTimeouts.delete(operationId);
155+
if (self.logger) {
156+
self.logger.info(`Running: ${operationId}`);
162157
}
158+
cb();
159+
perfLogger.logStopScheduledOperation();
163160
}
164161
}
165162

@@ -179,19 +176,16 @@ namespace ts.server {
179176
private static run(self: GcTimer) {
180177
self.timerId = undefined;
181178

182-
try {
183-
perfLogger.logStartScheduledOperation("GC collect");
184-
const log = self.logger.hasLevel(LogLevel.requestTime);
185-
const before = log && self.host.getMemoryUsage!(); // TODO: GH#18217
186-
187-
self.host.gc!(); // TODO: GH#18217
188-
if (log) {
189-
const after = self.host.getMemoryUsage!(); // TODO: GH#18217
190-
self.logger.perftrc(`GC::before ${before}, after ${after}`);
191-
}
192-
} finally {
193-
perfLogger.logStopScheduledOperation();
179+
perfLogger.logStartScheduledOperation("GC collect");
180+
const log = self.logger.hasLevel(LogLevel.requestTime);
181+
const before = log && self.host.getMemoryUsage!(); // TODO: GH#18217
182+
183+
self.host.gc!(); // TODO: GH#18217
184+
if (log) {
185+
const after = self.host.getMemoryUsage!(); // TODO: GH#18217
186+
self.logger.perftrc(`GC::before ${before}, after ${after}`);
194187
}
188+
perfLogger.logStopScheduledOperation();
195189
}
196190
}
197191

0 commit comments

Comments
 (0)