Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed constant CPU use and typing lag in workspaces with many Markdown notes. Dependency warnings now reuse the notes already loaded for the sidebars and rescan only edited files; reopening every note after each edit made VS Code close and reopen them in a loop. Unrelated setting changes no longer reload every task file, sidebar and badge refreshes reuse unchanged scans, and the new `todo.refreshDelay` setting controls how long these refreshes wait after an edit. [#306](https://github.com/vycdev/vscode-todo-plus-two/issues/306)
- Encoded terminal periods in generated relative file links so filenames ending in a period survive link parsing and archive moves.
- Kept literal `@due(...)` examples inside other tag arguments out of the Due sidebar and due-date colors in Todo files; a real due tag later on the same task still applies. Due examples in inline code are no longer colored either.

### Version 5.4.0

Expand Down
33 changes: 28 additions & 5 deletions src/todo/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
findMarkdownTaskTag,
getMarkdownCommentRanges,
getMarkdownTaskTags,
getTodoTaskTags,
maskMarkdownTaskText,
transformMarkdownTaskText,
} from '../utils/markdown-task-text';
Expand Down Expand Up @@ -80,10 +81,7 @@ class Document {
regex: RegExp
) {
if (this.isMarkdown()) return this.getMarkdownItems(Item, regex);
const matchText = _.isString(this.text)
? parseCodeBlocks(this.text).maskedText
: getCodeBlocks(this.textDocument).maskedText,
matches = stringMatches(matchText, regex);
const matches = stringMatches(this.getMatchText(), regex);

return matches.map((match) => {
const item = new Item(this.textEditor, undefined, match);
Expand All @@ -94,6 +92,12 @@ class Document {
});
}

private getMatchText() {
return _.isString(this.text)
? parseCodeBlocks(this.text).maskedText
: getCodeBlocks(this.textDocument).maskedText;
}

getItemAt(
Item:
| typeof Line
Expand Down Expand Up @@ -168,7 +172,26 @@ class Document {
}

getTagsDue() {
return this.getItems(Tag, Consts.regexes.tagDue);
const tags = this.getItems(Tag, Consts.regexes.tagDue);
if (this.isMarkdown() || !tags.length) return tags;

// A due example inside another tag's argument is literal text, as in the Due view.
const text = this.getMatchText(),
outerStartsByLine = new Map<number, Set<number>>();

return tags.filter((tag) => {
const start = tag.matchRange.start,
lineStart = text.lastIndexOf('\n', start - 1) + 1;
if (!outerStartsByLine.has(lineStart)) {
const lineEnd = text.indexOf('\n', start),
line = text.slice(lineStart, lineEnd < 0 ? text.length : lineEnd);
outerStartsByLine.set(
lineStart,
new Set(getTodoTaskTags(line).map((outer) => lineStart + outer.start))
);
}
return outerStartsByLine.get(lineStart).has(start);
});
}

getTodos() {
Expand Down
12 changes: 4 additions & 8 deletions src/utils/due_tasks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Due from './due';
import { maskInlineCode } from './todo-status';
import { parseCodeBlocks } from './code-blocks';
import { getTodoTaskTags } from './markdown-task-text';

export interface DueTaskLine {
date: Date;
Expand Down Expand Up @@ -39,14 +40,9 @@ export const getDueTaskLines = (

if (!matches(maskedText, todoRegex) || matches(maskedText, finishedRegex)) return;

const tags: string[] = [],
duePattern = /@due\([^)]*\)/gi;
let match: RegExpExecArray;

while ((match = duePattern.exec(maskedText))) {
if (match.index && /[a-zA-Z0-9`]/.test(maskedText[match.index - 1])) continue;
tags.push(match[0]);
}
const tags = getTodoTaskTags(text)
.filter((tag) => /^@due\([^)]*\)$/i.test(tag.text))
.map((tag) => tag.text);

for (const tag of tags) {
const value = Due.extract(tag),
Expand Down
15 changes: 15 additions & 0 deletions test/due-tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,19 @@ describe('Due task lines', () => {

expect(tasks.map((task) => task.lineNumber)).to.deep.equal([1]);
});

it('ignores literal due examples inside other tag arguments', () => {
const tasks = getDueTaskLines(
[
'☐ Example @id(release @due(2026-07-03))',
'☐ Release @note(@due(2026-07-01)) @due(2026-07-04)',
],
todoRegex,
finishedRegex,
today
);

expect(tasks.map((task) => task.lineNumber)).to.deep.equal([1]);
expect(tasks[0].dateKey).to.equal('2026-07-04');
});
});
20 changes: 20 additions & 0 deletions test/fenced-document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,23 @@ describe('Fenced Todo document parsing', () => {
});
});
});

describe('Todo document due tags', () => {
it('ignores due examples inside other tag arguments and inline code', () => {
withDocument((Document) => {
const doc = new Document(
[
'☐ Example @id(release @due(2026-07-03))',
'☐ Release @note(@due(2026-07-01)) @due(2026-07-04)',
'☐ Code `@due(2026-07-02)` @due(2026-07-05)',
'@due(2026-07-06) ☐ Leading',
].join('\n')
);
expect(doc.getTagsDue().map((tag) => tag.text)).to.deep.equal([
'@due(2026-07-04)',
'@due(2026-07-05)',
'@due(2026-07-06)',
]);
});
});
});
Loading