Skip to content

Commit

Permalink
fix: ! Prevent Tasks getting stuck 'Loading Tasks...' (again)
Browse files Browse the repository at this point in the history
Fixes #3156
Fixes #3153
Fixes #3157

This essentially moves the code from PR #1524 to an outer scope,
so that it is also applied in the new parsing code for creating
ListItem objects.
  • Loading branch information
claremacrae committed Oct 29, 2024
1 parent 6c14468 commit 26e5762
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/Obsidian/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,43 @@ export function getTasksFromFileContent2(
let sectionIndex = 0;
const line2ListItem: Map<number, ListItem> = new Map();
for (const listItem of listItems) {
if (listItem.task !== undefined) {
const lineNumber = listItem.position.start.line;
if (lineNumber >= linesInFile) {
/*
Obsidian CachedMetadata has told us that there is a task on lineNumber, but there are
not that many lines in the file.
This was the underlying cause of all the 'Stuck on "Loading Tasks..."' messages,
as it resulted in the line 'undefined' being parsed.
Somehow the file had been shortened whilst Obsidian was closed, meaning that
when Obsidian started up, it got the new file content, but still had the old cached
data about locations of list items in the file.
*/
logger.debug(
`${filePath} Obsidian gave us a line number ${lineNumber} past the end of the file. ${linesInFile}.`,
);
return tasks;
}
if (currentSection === null || currentSection.position.end.line < lineNumber) {
// We went past the current section (or this is the first task).
// Find the section that is relevant for this task and the following of the same section.
currentSection = Cache.getSection(lineNumber, fileCache.sections);
sectionIndex = 0;
}
const lineNumber = listItem.position.start.line;
if (lineNumber >= linesInFile) {
/*
Obsidian CachedMetadata has told us that there is a task on lineNumber, but there are
not that many lines in the file.
This was the underlying cause of all the 'Stuck on "Loading Tasks..."' messages,
as it resulted in the line 'undefined' being parsed.
Somehow the file had been shortened whilst Obsidian was closed, meaning that
when Obsidian started up, it got the new file content, but still had the old cached
data about locations of list items in the file.
*/
logger.debug(
`${filePath} Obsidian gave us a line number ${lineNumber} past the end of the file. ${linesInFile}.`,
);
return tasks;
}
if (currentSection === null || currentSection.position.end.line < lineNumber) {
// We went past the current section (or this is the first task).
// Find the section that is relevant for this task and the following of the same section.
currentSection = Cache.getSection(lineNumber, fileCache.sections);
sectionIndex = 0;
}

if (currentSection === null) {
// Cannot process a task without a section.
continue;
}
if (currentSection === null) {
// Cannot process a task without a section.
continue;
}

const line = fileLines[lineNumber];
if (line === undefined) {
logger.debug(`${filePath}: line ${lineNumber} - ignoring 'undefined' line.`);
continue;
}
const line = fileLines[lineNumber];
if (line === undefined) {
logger.debug(`${filePath}: line ${lineNumber} - ignoring 'undefined' line.`);
continue;
}

if (listItem.task !== undefined) {
let task;
try {
task = Task.fromLine({
Expand Down

0 comments on commit 26e5762

Please sign in to comment.