Skip to content

Commit

Permalink
Merge pull request #3159 from obsidian-tasks-group/fix-stuck-loading-…
Browse files Browse the repository at this point in the history
…tasks

fix: ! Prevent Tasks getting stuck 'Loading Tasks...' (again)
  • Loading branch information
claremacrae authored Oct 29, 2024
2 parents 6c14468 + 26e5762 commit a13bbf7
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 a13bbf7

Please sign in to comment.