Skip to content

Commit f239a04

Browse files
authored
Merge pull request #3450 from obsidian-tasks-group/fix-continuations-in-placeholders
fix: Support line continuations in TQ_extra_instructions & placeholders
2 parents a0d8849 + d6c8f85 commit f239a04

File tree

5 files changed

+15
-29
lines changed

5 files changed

+15
-29
lines changed

docs/Queries/Query File Defaults.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ When editing `TQ_extra_instructions` in Obsidian's File properties editor, you c
6060
> - `TQ_extra_instructions` is especially useful when you have more than one Tasks search block in a file, and you want the same instructions to be present in all the searches.
6161
> - Before this feature, if those standard instructions changed, you had to remember to update every search.
6262
> - Now you can put those standard instructions in `TQ_extra_instructions`, and only update them in one place.
63+
> - Since Tasks X.Y.Z, `TQ_extra_instructions` does support [[Line Continuations]].
6364
6465
> [!note]
6566
> The `TQ_extra_instructions` property isn't an array. It's a single string value, and the `|-` allows it to span multiple lines.
@@ -248,6 +249,3 @@ The `type` values are explained in the [Property types](https://help.obsidian.md
248249
- Tasks searches in **Canvas cards** cannot use [[Query File Defaults]], because the [Canvas format](https://jsoncanvas.org) does not support frontmatter/properties.
249250
- The workaround is to use the Canvas [Convert to file](https://help.obsidian.md/Plugins/Canvas#Add+text+cards) facility to convert cards which contain Tasks queries to a separate Markdown note, embedded in the canvas.
250251
- You can then add Query File Defaults to the new note.
251-
- The property `TQ_extra_instructions` can contain any kind of Tasks instruction, including placeholders.
252-
- But it does not work with [[Line Continuations]].
253-
- The workaround is to write any long instructions all on one line when placed in `TQ_extra_instructions`.

docs/What is New/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ _In recent [Tasks releases](https://github.com/obsidian-tasks-group/obsidian-tas
1313
## 7.x releases
1414

1515
- X.Y.Z:
16+
- [[Line Continuations]] can now be used in the [[Query File Defaults]] property `TQ_extra_instructions`.
1617
- [[Check your Statuses]] report now contains samples of each status, and a convenient search to test them.
1718
- 7.19.0:
1819
- New setting to [[Recurring Tasks#Remove scheduled date on recurrence|remove scheduled date on recurrence]].

src/Query/Query.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ ${source}`;
184184
const queryContext = makeQueryContext(tasksFile);
185185
try {
186186
expandedSource = expandPlaceholders(source, queryContext);
187+
if (expandedSource !== source) {
188+
expandedSource = continueLines(expandedSource)
189+
.map((statement) => statement.anyContinuationLinesRemoved)
190+
.join('\n');
191+
}
187192
} catch (error) {
188193
if (error instanceof Error) {
189194
this._error = error.message;

tests/Query/Query.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -876,18 +876,16 @@ group by folder
876876
`);
877877
});
878878

879-
it('does not work with continuation lines in multi-line property with query.file.property via placeholder', () => {
879+
it('should work with continuation lines in multi-line property with query.file.property via placeholder', () => {
880880
const propertyValue = `path \\
881881
includes query_using_properties
882882
`;
883883
const query = makeQueryFromPropertyWithValue('task_instructions_with_continuation_line', propertyValue);
884884

885-
expect(query.error).not.toBeUndefined();
886-
expect(query.error).toMatchInlineSnapshot(`
887-
"do not understand query
888-
Problem statement:
889-
{{query.file.property('task_instructions_with_continuation_line')}}: statement 1 after expansion of placeholder =>
890-
path \\
885+
expect(query.error).toBeUndefined();
886+
expect(query.explainQuery()).toMatchInlineSnapshot(`
887+
"{{query.file.property('task_instructions_with_continuation_line')}} =>
888+
path includes query_using_properties
891889
"
892890
`);
893891
});

tests/Scripting/Includes.test.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,10 @@ return "Hello World";`;
155155

156156
const expectedStatement = 'group by function return "Hello World";';
157157

158-
it('includes placeholder DOES NOT YET SUPPORT line continuations in include value', () => {
159-
// TODO Teach '{{includes.x}}' to support line continuations
160-
// Just as TQ_extra_instructions (in Query File Defaults) does not work with line continuations,
161-
// so includes in placeholders do not.
162-
// This is because line continuations are applied only once, before the placeholders
163-
// are expanded.
164-
158+
it('includes placeholder supports line continuations in include value', () => {
165159
const source = '{{includes.instruction_with_continuation_lines}}';
166-
const query = createQuery(source, includes);
167-
expect(query.error).toMatchInlineSnapshot(`
168-
"Could not interpret the following instruction as a Boolean combination:
169-
return "Hello World";
170-
171-
The error message is:
172-
All filters in a Boolean instruction must be inside one of these pairs of delimiter characters: (...) or [...] or {...} or "...". Combinations of those delimiters are no longer supported.
173-
Problem statement:
174-
{{includes.instruction_with_continuation_lines}}: statement 2 after expansion of placeholder =>
175-
return "Hello World";
176-
"
177-
`);
160+
const query = createValidQuery(source, includes);
161+
expectExpandedStatementToBe(query.grouping[0].statement, expectedStatement);
178162
});
179163

180164
it('include instruction supports line continuations in include value', () => {

0 commit comments

Comments
 (0)