(
state: {
doc: { toString(): string; length: number };
selection?: { main: { head: number; anchor: number } };
},
plugin: TaskNotesPlugin,
activeWidgets: Map<string, TaskLinkWidget>,
currentFile?: string,
lastKnownWidgets?: Map<string, TaskLinkWidget>
)
| 215 | } |
| 216 | |
| 217 | export function buildTaskLinkDecorations( |
| 218 | state: { |
| 219 | doc: { toString(): string; length: number }; |
| 220 | selection?: { main: { head: number; anchor: number } }; |
| 221 | }, |
| 222 | plugin: TaskNotesPlugin, |
| 223 | activeWidgets: Map<string, TaskLinkWidget>, |
| 224 | currentFile?: string, |
| 225 | lastKnownWidgets?: Map<string, TaskLinkWidget> |
| 226 | ): DecorationSet { |
| 227 | const builder = new RangeSetBuilder<Decoration>(); |
| 228 | |
| 229 | // Validate inputs |
| 230 | if (!state || !plugin || !activeWidgets) { |
| 231 | return builder.finish(); |
| 232 | } |
| 233 | |
| 234 | const doc = state.doc; |
| 235 | if (!doc) { |
| 236 | return builder.finish(); |
| 237 | } |
| 238 | |
| 239 | // Validate plugin components |
| 240 | if (!plugin.app || !plugin.app.workspace) { |
| 241 | return builder.finish(); |
| 242 | } |
| 243 | |
| 244 | const detectionService = |
| 245 | plugin.taskLinkDetectionService || new TaskLinkDetectionService(plugin); |
| 246 | |
| 247 | // Use provided currentFile, or fall back to getting active view |
| 248 | if (!currentFile) { |
| 249 | const activeMarkdownView = plugin.app.workspace.getActiveViewOfType(MarkdownView); |
| 250 | if (!activeMarkdownView) { |
| 251 | return builder.finish(); |
| 252 | } |
| 253 | currentFile = activeMarkdownView.file?.path; |
| 254 | } |
| 255 | |
| 256 | if (!currentFile) { |
| 257 | return builder.finish(); |
| 258 | } |
| 259 | |
| 260 | // Validate current file path |
| 261 | if (typeof currentFile !== "string" || currentFile.length === 0) { |
| 262 | return builder.finish(); |
| 263 | } |
| 264 | |
| 265 | try { |
| 266 | // Process the entire document text for wikilinks |
| 267 | const text = doc.toString(); |
| 268 | |
| 269 | // Validate document text |
| 270 | if (typeof text !== "string") { |
| 271 | return builder.finish(); |
| 272 | } |
| 273 | |
| 274 | // Performance safeguard: skip processing extremely large documents |
no test coverage detected