Skip to content

Commit 7774f73

Browse files
authored
1 parent b3bc713 commit 7774f73

File tree

7 files changed

+7
-97
lines changed

7 files changed

+7
-97
lines changed

src/vs/base/common/arrays.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -624,35 +624,7 @@ function getActualStartIndex<T>(array: T[], start: number): number {
624624
return start < 0 ? Math.max(start + array.length, 0) : Math.min(start, array.length);
625625
}
626626

627-
/**
628-
* Utility that helps to pick a property from an object.
629-
*
630-
* ## Examples
631-
*
632-
* ```typescript
633-
* interface IObject = {
634-
* a: number,
635-
* b: string,
636-
* };
637-
*
638-
* const list: IObject[] = [
639-
* { a: 1, b: 'foo' },
640-
* { a: 2, b: 'bar' },
641-
* ];
642-
*
643-
* assert.deepStrictEqual(
644-
* list.map(pick('a')),
645-
* [1, 2],
646-
* );
647-
* ```
648-
*/
649-
export const pick = <TObject, TKeyName extends keyof TObject>(
650-
key: TKeyName,
651-
) => {
652-
return (obj: TObject): TObject[TKeyName] => {
653-
return obj[key];
654-
};
655-
};
627+
656628

657629
/**
658630
* When comparing two values,

src/vs/base/test/common/arrays.test.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import assert from 'assert';
66
import * as arrays from '../../common/arrays.js';
77
import * as arraysFind from '../../common/arraysFind.js';
88
import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';
9-
import { pick } from '../../common/arrays.js';
109

1110
suite('Arrays', () => {
1211

@@ -400,63 +399,7 @@ suite('Arrays', () => {
400399
);
401400
});
402401

403-
suite('pick', () => {
404-
suite('object', () => {
405-
test('numbers', () => {
406-
const array = [{ v: 3, foo: 'a' }, { v: 5, foo: 'b' }, { v: 2, foo: 'c' }, { v: 2, foo: 'd' }, { v: 17, bar: '1' }, { v: -100, baz: '10' }];
407402

408-
assert.deepStrictEqual(
409-
array.map(pick('v')),
410-
[3, 5, 2, 2, 17, -100],
411-
);
412-
});
413-
414-
test('strings', () => {
415-
const array = [{ v: 3, foo: 'a' }, { v: 5, foo: 'b' }, { v: 2, foo: 'c' }, { v: 2, foo: 'd' }, { v: 17, bar: '1' }, { v: -100, baz: '10' }, { foo: '12' }];
416-
417-
assert.deepStrictEqual(
418-
array.map(pick('foo')),
419-
['a', 'b', 'c', 'd', undefined, undefined, '12'],
420-
);
421-
});
422-
423-
test('booleans', () => {
424-
const array = [{ v: 3, foo: 'a' }, { v: 5, foo: 'b' }, { v: 2, foo: 'c' }, { v: 2, foo: 'd' }, { v: 17, bar: true }, { v: -100, bar: false }, { bar: false }];
425-
426-
assert.deepStrictEqual(
427-
array.map(pick('bar')),
428-
[undefined, undefined, undefined, undefined, true, false, false],
429-
);
430-
});
431-
432-
test('objects', () => {
433-
const array = [{ v: { test: 12 } }, { v: { test: 24 } }, {}, { v: { test: 17892 } }];
434-
435-
assert.deepStrictEqual(
436-
array.map(pick('v')),
437-
[{ test: 12 }, { test: 24 }, undefined, { test: 17892 }],
438-
);
439-
});
440-
441-
test('mixed', () => {
442-
const array = [{ v: { test: 104 } }, { v: 2 }, {}, { v: '24' }, { v: null }];
443-
444-
assert.deepStrictEqual(
445-
array.map(pick('v')),
446-
[{ test: 104 }, 2, undefined, '24', null],
447-
);
448-
});
449-
});
450-
451-
test('string', () => {
452-
const array = ['haallo', 'there', ':wave:', '!'];
453-
454-
assert.deepStrictEqual(
455-
array.map(pick('length')),
456-
[6, 5, 6, 1],
457-
);
458-
});
459-
});
460403

461404
suite('ArrayQueue', () => {
462405
suite('takeWhile/takeFromEndWhile', () => {

src/vs/editor/common/codecs/baseToken.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { pick } from '../../../base/common/arrays.js';
76
import { assert } from '../../../base/common/assert.js';
87
import { IRange, Range } from '../../../editor/common/core/range.js';
98

@@ -90,7 +89,7 @@ export abstract class BaseToken<TText extends string = string> {
9089
tokens: readonly BaseToken[],
9190
delimiter: string = '',
9291
): string {
93-
return tokens.map(pick('text')).join(delimiter);
92+
return tokens.map(token => token.text).join(delimiter);
9493
}
9594

9695
/**

src/vs/editor/common/codecs/simpleCodec/simpleDecoder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
LeftAngleBracket,
3939
RightAngleBracket,
4040
} from './tokens/index.js';
41-
import { pick } from '../../../../base/common/arrays.js';
4241
import { ISimpleTokenClass, SimpleToken } from './tokens/simpleToken.js';
4342

4443
/**
@@ -71,7 +70,7 @@ export const WELL_KNOWN_TOKENS: readonly ISimpleTokenClass<TSimpleToken>[] = Obj
7170
* the {@link LinesDecoder} which emits {@link Line} tokens without them.
7271
*/
7372
const WORD_STOP_CHARACTERS: readonly string[] = Object.freeze(
74-
WELL_KNOWN_TOKENS.map(pick('symbol')),
73+
WELL_KNOWN_TOKENS.map(token => token.symbol),
7574
);
7675

7776
/**

src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatPromptAttachmentModel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { URI } from '../../../../../base/common/uri.js';
7-
import { pick } from '../../../../../base/common/arrays.js';
87
import { Emitter } from '../../../../../base/common/event.js';
98
import { PromptParser } from '../../common/promptSyntax/parsers/promptParser.js';
109
import { BasePromptParser } from '../../common/promptSyntax/parsers/basePromptParser.js';
@@ -51,7 +50,7 @@ export class ChatPromptAttachmentModel extends ObservableDisposable {
5150
// otherwise return `URI` for the main reference and
5251
// all valid child `URI` references it may contain
5352
return [
54-
...reference.allValidReferences.map(pick('uri')),
53+
...reference.allValidReferences.map(ref => ref.uri),
5554
reference.uri,
5655
];
5756
}

src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { localize } from '../../../../../../nls.js';
88
import { PROMPT_LANGUAGE_ID } from '../constants.js';
99
import { PromptParser } from '../parsers/promptParser.js';
1010
import { match, splitGlobAware } from '../../../../../../base/common/glob.js';
11-
import { pick } from '../../../../../../base/common/arrays.js';
1211
import { type URI } from '../../../../../../base/common/uri.js';
1312
import { type IPromptFileReference } from '../parsers/types.js';
1413
import { assert } from '../../../../../../base/common/assert.js';
@@ -252,7 +251,7 @@ export class PromptsService extends Disposable implements IPromptsService {
252251
}
253252

254253
const instructions = await this.getAllMetadata(
255-
instructionFiles.map(pick('uri')),
254+
instructionFiles.map(file => file.uri),
256255
);
257256

258257
const foundFiles = new ResourceSet();

src/vs/workbench/contrib/chat/test/common/promptSyntax/service/promptsService.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import assert from 'assert';
77
import * as sinon from 'sinon';
88
import { URI } from '../../../../../../../base/common/uri.js';
99
import { MockFilesystem } from '../testUtils/mockFilesystem.js';
10-
import { pick } from '../../../../../../../base/common/arrays.js';
1110
import { Schemas } from '../../../../../../../base/common/network.js';
1211
import { Range } from '../../../../../../../editor/common/core/range.js';
1312
import { assertDefined } from '../../../../../../../base/common/types.js';
@@ -874,7 +873,7 @@ suite('PromptsService', () => {
874873
]);
875874

876875
assert.deepStrictEqual(
877-
instructions.map(pick('path')),
876+
instructions.map(i => i.path),
878877
[
879878
// local instructions
880879
URI.joinPath(rootFolderUri, '.github/prompts/file1.instructions.md').path,
@@ -1055,7 +1054,7 @@ suite('PromptsService', () => {
10551054
]);
10561055

10571056
assert.deepStrictEqual(
1058-
instructions.map(pick('path')),
1057+
instructions.map(i => i.path),
10591058
[
10601059
// local instructions
10611060
URI.joinPath(rootFolderUri, '.github/prompts/file1.instructions.md').path,

0 commit comments

Comments
 (0)