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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Version 5.3.0 (Unreleased)

- Fixed text-only Todo parsing so item ranges no longer access unavailable VS Code document APIs.
- Fixed embedded todo scanning and external-search result parsing for files and tool output that use classic Mac carriage-return line endings.
- Fixed dependency indexing so one unreadable or removed Todo file no longer hides dependencies from other workspace files.
- Fixed embedded todo parsing for file paths that start with a number.
- Fixed date-sorted archiving so consecutive finished todos are ordered by their own completion dates.
Expand Down
5 changes: 3 additions & 2 deletions src/utils/ackmate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { splitLines } from './line-splitting';

/* ACKMATE */

const Ackmate = {
newLineRe: /\r?\n/g,
filePathRe: /^:?([^]+)$/,
matchLineRe: /^(\d+)(?:;\d+ \d+)?:([^]*)$/,

Expand All @@ -10,7 +11,7 @@ const Ackmate = {
},

parse(str) {
const lines = str.split(Ackmate.newLineRe);
const lines = splitLines(str);

let filePath, match;

Expand Down
3 changes: 2 additions & 1 deletion src/utils/embedded/providers/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Consts from '../../../consts';
import { hasConditionalExcludeGlobs, isFileIncluded } from '../../file-globs';
import { getWorkspaceExcludeRules } from '../../workspace-excludes';
import { getFollowingContext } from '../context';
import { splitLines } from '../../line-splitting';
import { parseEmbeddedMatches } from '../regex';

/* ABSTRACT */
Expand Down Expand Up @@ -200,7 +201,7 @@ class Abstract {

parseContent(filePath: string, content: string) {
const data = [],
lines = content.split(/\r?\n/);
lines = splitLines(content);

if (!content) return data;

Expand Down
3 changes: 2 additions & 1 deletion src/utils/embedded/providers/ag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import File from '../../file';
import Folder from '../../folder';
import { flatMapFulfilled } from '../../promises';
import { getWorkspaceExcludeGlobs } from '../../workspace-excludes';
import { splitLines } from '../../line-splitting';
import { parseEmbeddedMatches } from '../regex';
import Abstract from './abstract';

Expand Down Expand Up @@ -106,7 +107,7 @@ class AG extends Abstract {
const content = await File.read(filePath);

if (content !== undefined) {
contextLines[filePath] = content.split(/\r?\n/);
contextLines[filePath] = splitLines(content);
}
}
)
Expand Down
3 changes: 2 additions & 1 deletion src/utils/embedded/regex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as _ from 'lodash';
import stringMatches from 'string-matches';
import { splitLines } from '../line-splitting';

export const parseEmbeddedMatches = (line: string, regex: RegExp) =>
stringMatches(line, regex).map((match) => ({
Expand All @@ -12,7 +13,7 @@ export const parseEmbeddedMatches = (line: string, regex: RegExp) =>
export const hasEmbeddedMatch = (content: string, regex: RegExp): boolean => {
const matcher = new RegExp(regex.source, regex.flags);

return content.split(/\r?\n/).some((line) => {
return splitLines(content).some((line) => {
matcher.lastIndex = 0;

return matcher.test(_.trimStart(line));
Expand Down
1 change: 1 addition & 0 deletions src/utils/line-splitting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const splitLines = (text: string): string[] => text.split(/\r\n?|\n/);
15 changes: 15 additions & 0 deletions test/ackmate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@ describe('Ackmate parser', () => {
},
]);
});

it('parses records separated by classic Mac line endings', () => {
expect(Ackmate.parse('TODO.md\r2:TODO first\r3:FIXME second')).to.deep.equal([
{
filePath: 'TODO.md',
lineNr: 1,
line: 'TODO first',
},
{
filePath: 'TODO.md',
lineNr: 2,
line: 'FIXME second',
},
]);
});
});
6 changes: 6 additions & 0 deletions test/embedded-regex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ describe('Embedded todo scan pre-check', () => {
expect(hasEmbeddedMatch(content, regex)).to.equal(true);
expect(hasEmbeddedMatch('// TODO ignored', regex)).to.equal(false);
});

it('recognizes embedded todos in files with classic Mac line endings', () => {
const regex = /^\/\/\s*(TASK):?\s*(.*)$/gi;

expect(hasEmbeddedMatch('const ready = true;\r // TASK ship it', regex)).to.equal(true);
});
});

describe('Embedded todo line parsing', () => {
Expand Down