Skip to content

Commit 13798e2

Browse files
authored
Ensure job is always ended. (#26)
1 parent 3d5ee26 commit 13798e2

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/analysis/typepal/refactor/Rename.rsc

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,9 @@ RenameResult rename(
139139
private RenameResult _rename(
140140
Focus cursor
141141
, str newName
142-
, RenameConfig config) {
143-
144-
/* Initially, we expect at least the following work
145-
- 1 unit of work to initialize the renaming
146-
- 1 unit of 'workspace work' to resolve definitions
147-
- 1 unit of 'workspace work' to find all files with occurrences
142+
, RenameConfig config) = job(config.jobLabel, RenameResult(void(str, int) jobStep) {
148143

149-
Any additional work will be added based on the results of above steps.
150-
*/
151-
jobStart(config.jobLabel, totalWork = 2 * WORKSPACE_WORK + 1);
152-
jobStep(config.jobLabel, "Initializing renaming");
144+
jobStep("Initializing renaming", 1);
153145

154146
// Tree & TModel caching
155147

@@ -254,7 +246,7 @@ private RenameResult _rename(
254246
, RenameConfig() { return cachedConfig; }
255247
);
256248

257-
jobStep(config.jobLabel, "Resolving definitions of <cursor[0].src>", work = WORKSPACE_WORK);
249+
jobStep("Resolving definitions of <cursor[0].src>", WORKSPACE_WORK);
258250
defs = getCursorDefinitions(cursor, parseLocCached, getTModelCached, r);
259251

260252
if (defs == {}) r.msg(error(cursor[0].src, "No definitions found"));
@@ -263,25 +255,25 @@ private RenameResult _rename(
263255
return <docEdits, getMessages()>;
264256
}
265257

266-
jobStep(config.jobLabel, "Looking for files with occurrences of name under cursor", work = WORKSPACE_WORK);
258+
jobStep("Looking for files with occurrences of name under cursor", WORKSPACE_WORK);
267259
<maybeDefFiles, maybeUseFiles, newNameFiles> = findOccurrenceFiles(defs, cursor, newName, parseLocCached, r);
268260

269261
jobTodo(config.jobLabel, work = (size(maybeDefFiles) + size(maybeUseFiles) + size(newNameFiles)) * FILE_WORK);
270262

271263
set[Define] additionalDefs = {};
272264
solve (additionalDefs) {
273265
for (loc f <- maybeDefFiles) {
274-
jobStep(config.jobLabel, "Looking for additional definitions in <f>", work = 0);
266+
jobStep("Looking for additional definitions in <f>", 0);
275267
tr = parseLocCached(f);
276268
tm = getTModelCached(tr);
277269
additionalDefs += findAdditionalDefinitions(defs, tr, tm, r);
278270
}
279271
defs += additionalDefs;
280272
}
281-
jobStep(config.jobLabel, "Done looking for additional definitions", work = FILE_WORK * size(maybeDefFiles));
273+
jobStep("Done looking for additional definitions", FILE_WORK * size(maybeDefFiles));
282274

283275
for (loc f <- newNameFiles) {
284-
jobStep(config.jobLabel, "Validating occurrences of new name \'<newName>\' in <f>", work = FILE_WORK);
276+
jobStep("Validating occurrences of new name \'<newName>\' in <f>", FILE_WORK);
285277
tr = parseLocCached(f);
286278
validateNewNameOccurrences(defs, newName, tr, r);
287279
}
@@ -295,7 +287,7 @@ private RenameResult _rename(
295287

296288
for (loc f <- defFiles) {
297289
fileDefs = {d | d <- defs, d.defined.top == f};
298-
jobStep(config.jobLabel, "Renaming <size(fileDefs)> definitions in <f>", work = FILE_WORK);
290+
jobStep("Renaming <size(fileDefs)> definitions in <f>", FILE_WORK);
299291
tr = parseLocCached(f);
300292
tm = getTModelCached(tr);
301293

@@ -311,7 +303,7 @@ private RenameResult _rename(
311303
}
312304

313305
for (loc f <- maybeUseFiles) {
314-
jobStep(config.jobLabel, "Renaming uses in <f>", work = FILE_WORK);
306+
jobStep("Renaming uses in <f>", FILE_WORK);
315307
tr = parseLocCached(f);
316308
tm = getTModelCached(tr);
317309

@@ -343,9 +335,14 @@ private RenameResult _rename(
343335
}
344336
}
345337

346-
jobEnd(config.jobLabel, success = !errorReported());
347338
return <docEdits, convertedMessages>;
348-
}
339+
}, /* Initially, we expect at least the following work
340+
- 1 unit of work to initialize the renaming
341+
- 1 unit of 'workspace work' to resolve definitions
342+
- 1 unit of 'workspace work' to find all files with occurrences
343+
344+
Any additional work will be added based on the results of above steps.
345+
*/ totalWork = 2 * WORKSPACE_WORK + 1);
349346

350347
// TODO If performance bottleneck, rewrite to binary search
351348
@synopsis{Compute locations of names of `defs` in `tr`.}

0 commit comments

Comments
 (0)