Skip to content

Commit 758890e

Browse files
committed
debug: introduce some unit tests for getVisibleAndSorted
1 parent 67f9228 commit 758890e

4 files changed

Lines changed: 110 additions & 37 deletions

File tree

src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { withUndefinedAsNull } from 'vs/base/common/types';
3838
import { sequence } from 'vs/base/common/async';
3939
import { IHistoryService } from 'vs/workbench/services/history/common/history';
4040
import { first } from 'vs/base/common/arrays';
41+
import { getVisibleAndSorted } from 'vs/workbench/contrib/debug/common/debugUtils';
4142

4243
const jsonRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
4344
jsonRegistry.registerSchema(launchSchemaId, launchSchema);
@@ -235,36 +236,13 @@ export class ConfigurationManager implements IConfigurationManager {
235236
for (let l of this.launches) {
236237
for (let name of l.getConfigurationNames()) {
237238
const config = l.getConfiguration(name) || l.getCompound(name);
238-
if (config && !config.presentation?.hidden) {
239+
if (config) {
239240
all.push({ launch: l, name, presentation: config.presentation });
240241
}
241242
}
242243
}
243244

244-
return all.sort((first, second) => {
245-
if (!first.presentation) {
246-
return 1;
247-
}
248-
if (!second.presentation) {
249-
return -1;
250-
}
251-
if (!first.presentation.group) {
252-
return 1;
253-
}
254-
if (!second.presentation.group) {
255-
return -1;
256-
}
257-
if (first.presentation.group !== second.presentation.group) {
258-
return first.presentation.group.localeCompare(second.presentation.group);
259-
}
260-
if (typeof first.presentation.order !== 'number') {
261-
return 1;
262-
}
263-
if (typeof second.presentation.order !== 'number') {
264-
return -1;
265-
}
266-
return first.presentation.order - second.presentation.order;
267-
});
245+
return getVisibleAndSorted(all);
268246
}
269247

270248
private registerListeners(): void {

src/vs/workbench/contrib/debug/browser/media/debugViewlet.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,3 @@
387387
overflow: hidden;
388388
text-overflow: ellipsis
389389
}
390-
391-
/* No workspace view */
392-
393-
.debug-viewlet > .noworkspace-view {
394-
padding: 0 20px 0 20px;
395-
}
396-
397-
.debug-viewlet > .noworkspace-view > p {
398-
line-height: 1.5em;
399-
}

src/vs/workbench/contrib/debug/common/debugUtils.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { equalsIgnoreCase } from 'vs/base/common/strings';
7-
import { IDebuggerContribution, IDebugSession } from 'vs/workbench/contrib/debug/common/debug';
7+
import { IDebuggerContribution, IDebugSession, IConfigPresentation } from 'vs/workbench/contrib/debug/common/debug';
88
import { URI as uri } from 'vs/base/common/uri';
99
import { isAbsolute } from 'vs/base/common/path';
1010
import { deepClone } from 'vs/base/common/objects';
@@ -236,3 +236,31 @@ function convertPaths(msg: DebugProtocol.ProtocolMessage, fixSourcePath: (toDA:
236236
break;
237237
}
238238
}
239+
240+
export function getVisibleAndSorted<T extends { presentation?: IConfigPresentation }>(array: T[]): T[] {
241+
return array.filter(config => !config.presentation?.hidden).sort((first, second) => {
242+
if (!first.presentation) {
243+
return 1;
244+
}
245+
if (!second.presentation) {
246+
return -1;
247+
}
248+
if (!first.presentation.group) {
249+
return 1;
250+
}
251+
if (!second.presentation.group) {
252+
return -1;
253+
}
254+
if (first.presentation.group !== second.presentation.group) {
255+
return first.presentation.group.localeCompare(second.presentation.group);
256+
}
257+
if (typeof first.presentation.order !== 'number') {
258+
return 1;
259+
}
260+
if (typeof second.presentation.order !== 'number') {
261+
return -1;
262+
}
263+
264+
return first.presentation.order - second.presentation.order;
265+
});
266+
}

src/vs/workbench/contrib/debug/test/common/debugUtils.test.ts

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7-
import { formatPII, getExactExpressionStartAndEnd } from 'vs/workbench/contrib/debug/common/debugUtils';
7+
import { formatPII, getExactExpressionStartAndEnd, getVisibleAndSorted } from 'vs/workbench/contrib/debug/common/debugUtils';
8+
import { IConfig } from 'vs/workbench/contrib/debug/common/debug';
89

910
suite('Debug - Utils', () => {
1011
test('formatPII', () => {
@@ -37,4 +38,80 @@ suite('Debug - Utils', () => {
3738
assert.deepEqual(getExactExpressionStartAndEnd('var t = a.b;c.d.name', 16, 20), { start: 13, end: 20 });
3839
assert.deepEqual(getExactExpressionStartAndEnd('var t = a.b.c-d.name', 16, 20), { start: 15, end: 20 });
3940
});
41+
42+
test('config presentation', () => {
43+
const configs: IConfig[] = [];
44+
configs.push({
45+
type: 'node',
46+
request: 'launch',
47+
name: 'p'
48+
});
49+
configs.push({
50+
type: 'node',
51+
request: 'launch',
52+
name: 'a'
53+
});
54+
configs.push({
55+
type: 'node',
56+
request: 'launch',
57+
name: 'b',
58+
presentation: {
59+
hidden: false
60+
}
61+
});
62+
configs.push({
63+
type: 'node',
64+
request: 'launch',
65+
name: 'c',
66+
presentation: {
67+
hidden: true
68+
}
69+
});
70+
configs.push({
71+
type: 'node',
72+
request: 'launch',
73+
name: 'd',
74+
presentation: {
75+
group: '2_group',
76+
order: 5
77+
}
78+
});
79+
configs.push({
80+
type: 'node',
81+
request: 'launch',
82+
name: 'e',
83+
presentation: {
84+
group: '2_group',
85+
order: 52
86+
}
87+
});
88+
configs.push({
89+
type: 'node',
90+
request: 'launch',
91+
name: 'f',
92+
presentation: {
93+
group: '1_group',
94+
order: 500
95+
}
96+
});
97+
configs.push({
98+
type: 'node',
99+
request: 'launch',
100+
name: 'g',
101+
presentation: {
102+
group: '5_group',
103+
order: 500
104+
}
105+
});
106+
107+
const sorted = getVisibleAndSorted(configs);
108+
assert.equal(sorted.length, 7);
109+
assert.equal(sorted[0].name, 'f');
110+
assert.equal(sorted[1].name, 'd');
111+
assert.equal(sorted[2].name, 'e');
112+
assert.equal(sorted[3].name, 'g');
113+
assert.equal(sorted[4].name, 'b');
114+
assert.equal(sorted[5].name, 'p');
115+
assert.equal(sorted[6].name, 'a');
116+
});
40117
});

0 commit comments

Comments
 (0)