* Get task info for a specific file path (just-in-time)
(path: string)
| 257 | * Get task info for a specific file path (just-in-time) |
| 258 | */ |
| 259 | async getTaskInfo(path: string): Promise<TaskInfo | null> { |
| 260 | if (!this.isValidFile(path)) return null; |
| 261 | |
| 262 | const file = this.app.vault.getAbstractFileByPath(path); |
| 263 | if (!(file instanceof TFile)) return null; |
| 264 | |
| 265 | const pendingTaskInfo = this.getPendingTaskInfo(path); |
| 266 | const metadata = this.app.metadataCache.getFileCache(file); |
| 267 | if (!metadata?.frontmatter) { |
| 268 | if (pendingTaskInfo) { |
| 269 | return pendingTaskInfo; |
| 270 | } |
| 271 | |
| 272 | const frontmatter = await this.readFrontmatterFromFile(file); |
| 273 | if (!frontmatter || !this.isTaskFile(frontmatter)) return null; |
| 274 | |
| 275 | return this.extractTaskInfoFromNative(path, frontmatter); |
| 276 | } |
| 277 | |
| 278 | const metadataTaskInfo = this.isTaskFile(metadata.frontmatter) |
| 279 | ? this.extractTaskInfoFromNative(path, metadata.frontmatter) |
| 280 | : null; |
| 281 | |
| 282 | if (pendingTaskInfo && this.shouldUsePendingTaskInfo(pendingTaskInfo, metadataTaskInfo)) { |
| 283 | return pendingTaskInfo; |
| 284 | } |
| 285 | |
| 286 | this.pendingTaskInfoByPath.delete(path); |
| 287 | |
| 288 | return metadataTaskInfo; |
| 289 | } |
| 290 | |
| 291 | private getPendingTaskInfo(path: string): TaskInfo | null { |
| 292 | const taskInfo = this.pendingTaskInfoByPath.get(path); |
no test coverage detected