Skip to content

Commit f504cbe

Browse files
committed
Add a command to toggle TODO visibility
This only toggles as a bool though, so you can't set it to show TODO without HACK etc. Fixes #6118
1 parent 36445ae commit f504cbe

4 files changed

Lines changed: 159 additions & 0 deletions

File tree

‎package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
}
111111
],
112112
"commands": [
113+
{
114+
"command": "dart.toggleShowTodos",
115+
"title": "Toggle Show TODOs",
116+
"category": "Dart"
117+
},
113118
{
114119
"command": "flutter.createProject",
115120
"title": "Create New Project",

‎src/extension/commands/analyzer.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Logger } from "../../shared/interfaces";
77
import { getRandomInt } from "../../shared/utils/fs";
88
import { envUtils } from "../../shared/vscode/utils";
99
import { Analytics, AnalyticsEvent } from "../analytics";
10+
import { config } from "../config";
1011
import { ringLog } from "../extension";
1112
import { openLogContents } from "../utils";
1213
import { getLogHeader } from "../utils/log";
@@ -51,6 +52,21 @@ export class AnalyzerCommands {
5152
analytics.log(AnalyticsEvent.Command_ForceReanalyze);
5253
await analyzer.forceReanalyze();
5354
}));
55+
context.subscriptions.push(vs.commands.registerCommand("dart.toggleShowTodos", async () => {
56+
const settingName = "showTodos";
57+
const currentValue = config.showTodos;
58+
const newValue = !currentValue;
59+
60+
let target = vs.ConfigurationTarget.Global;
61+
const configValue = vs.workspace.getConfiguration("dart").inspect(settingName);
62+
if (configValue?.workspaceFolderValue !== undefined) {
63+
target = vs.ConfigurationTarget.WorkspaceFolder;
64+
} else if (configValue?.workspaceValue !== undefined) {
65+
target = vs.ConfigurationTarget.Workspace;
66+
}
67+
68+
await config.setShowTodos(newValue, target);
69+
}));
5470
}
5571

5672
private async showServerRestartPrompt(): Promise<void> {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { strict as assert } from "assert";
2+
import * as vs from "vscode";
3+
import { activate, helloWorldMainFile } from "../../helpers";
4+
5+
describe("toggle show TODOs", () => {
6+
const settingName = "showTodos";
7+
let config: vs.WorkspaceConfiguration;
8+
9+
function refresh(): void {
10+
config = vs.workspace.getConfiguration("dart");
11+
}
12+
13+
beforeEach(async () => {
14+
await activate(helloWorldMainFile);
15+
refresh();
16+
// Clear overrides to start from a clean state.
17+
await config.update(settingName, undefined, vs.ConfigurationTarget.Global);
18+
await config.update(settingName, undefined, vs.ConfigurationTarget.Workspace);
19+
refresh();
20+
});
21+
22+
// (multi-root) Workspaces are tested in the 'multi_root' tests. This test project is a single folder.
23+
24+
it("toggles in User settings when not defined anywhere", async () => {
25+
// Default is true.
26+
refresh();
27+
assert.strictEqual(config.get(settingName), true);
28+
29+
await vs.commands.executeCommand("dart.toggleShowTodos");
30+
refresh();
31+
assert.strictEqual(config.get(settingName), false);
32+
assert.strictEqual(config.inspect(settingName)?.globalValue, false);
33+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, undefined);
34+
35+
await vs.commands.executeCommand("dart.toggleShowTodos");
36+
refresh();
37+
assert.strictEqual(config.get(settingName), true);
38+
assert.strictEqual(config.inspect(settingName)?.globalValue, true);
39+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, undefined);
40+
});
41+
42+
it("toggles in User settings when defined in User settings", async () => {
43+
await config.update(settingName, false, vs.ConfigurationTarget.Global);
44+
refresh();
45+
assert.strictEqual(config.get(settingName), false);
46+
47+
await vs.commands.executeCommand("dart.toggleShowTodos");
48+
refresh();
49+
assert.strictEqual(config.get(settingName), true);
50+
assert.strictEqual(config.inspect(settingName)?.globalValue, true);
51+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, undefined);
52+
assert.strictEqual(config.inspect(settingName)?.workspaceFolderValue, undefined);
53+
54+
await vs.commands.executeCommand("dart.toggleShowTodos");
55+
refresh();
56+
assert.strictEqual(config.get(settingName), false);
57+
assert.strictEqual(config.inspect(settingName)?.globalValue, false);
58+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, undefined);
59+
assert.strictEqual(config.inspect(settingName)?.workspaceFolderValue, undefined);
60+
});
61+
62+
it("toggles in User settings when defined in User settings as an array", async () => {
63+
await config.update(settingName, ["TODO", "HACK"], vs.ConfigurationTarget.Global);
64+
refresh();
65+
assert.deepStrictEqual(config.get(settingName), ["TODO", "HACK"]);
66+
67+
await vs.commands.executeCommand("dart.toggleShowTodos");
68+
refresh();
69+
assert.strictEqual(config.get(settingName), false);
70+
assert.strictEqual(config.inspect(settingName)?.globalValue, false);
71+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, undefined);
72+
assert.strictEqual(config.inspect(settingName)?.workspaceFolderValue, undefined);
73+
74+
await vs.commands.executeCommand("dart.toggleShowTodos");
75+
refresh();
76+
assert.strictEqual(config.get(settingName), true);
77+
assert.strictEqual(config.inspect(settingName)?.globalValue, true);
78+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, undefined);
79+
assert.strictEqual(config.inspect(settingName)?.workspaceFolderValue, undefined);
80+
});
81+
82+
it("toggles in Workspace (Folder) settings when defined in Workspace (Folder) settings (single-root workspace)", async () => {
83+
await config.update(settingName, false, vs.ConfigurationTarget.Workspace);
84+
refresh();
85+
assert.strictEqual(config.get(settingName), false);
86+
87+
await vs.commands.executeCommand("dart.toggleShowTodos");
88+
refresh();
89+
assert.strictEqual(config.get(settingName), true);
90+
assert.strictEqual(config.inspect(settingName)?.globalValue, undefined);
91+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, true);
92+
93+
await vs.commands.executeCommand("dart.toggleShowTodos");
94+
refresh();
95+
assert.strictEqual(config.get(settingName), false);
96+
assert.strictEqual(config.inspect(settingName)?.globalValue, undefined);
97+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, false);
98+
});
99+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { strict as assert } from "assert";
2+
import * as vs from "vscode";
3+
import { activate, helloWorldMainFile } from "../../helpers";
4+
5+
describe("toggle show TODOs", () => {
6+
const settingName = "showTodos";
7+
let config: vs.WorkspaceConfiguration;
8+
9+
function refresh(): void {
10+
config = vs.workspace.getConfiguration("dart");
11+
}
12+
13+
beforeEach(async () => {
14+
await activate(helloWorldMainFile);
15+
refresh();
16+
// Clear overrides to start from a clean state.
17+
await config.update(settingName, undefined, vs.ConfigurationTarget.Global);
18+
await config.update(settingName, undefined, vs.ConfigurationTarget.Workspace);
19+
refresh();
20+
});
21+
22+
it("toggles in Workspace settings when defined in Folder settings (multi-root workspace)", async () => {
23+
await config.update(settingName, false, vs.ConfigurationTarget.Workspace);
24+
refresh();
25+
assert.strictEqual(config.get(settingName), false);
26+
27+
await vs.commands.executeCommand("dart.toggleShowTodos");
28+
refresh();
29+
assert.strictEqual(config.get(settingName), true);
30+
assert.strictEqual(config.inspect(settingName)?.globalValue, undefined);
31+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, true);
32+
33+
await vs.commands.executeCommand("dart.toggleShowTodos");
34+
refresh();
35+
assert.strictEqual(config.get(settingName), false);
36+
assert.strictEqual(config.inspect(settingName)?.globalValue, undefined);
37+
assert.strictEqual(config.inspect(settingName)?.workspaceValue, false);
38+
});
39+
});

0 commit comments

Comments
 (0)