Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/linkify/common/linkifiedText.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
7
import { Location, SymbolInformation, Uri } from '../../../vscodeTypes';
8
9
export class LinkifyLocationAnchor {
10
constructor(
11
public readonly value: Uri | Location,
12
public readonly title?: string
13
) { }
14
}
15
16
export class LinkifySymbolAnchor {
17
constructor(
18
public readonly symbolInformation: SymbolInformation,
19
public readonly resolve?: (token: CancellationToken) => Promise<SymbolInformation>,
20
) { }
21
}
22
23
export type LinkifiedPart = string | LinkifyLocationAnchor | LinkifySymbolAnchor;
24
25
export interface LinkifiedText {
26
readonly parts: readonly LinkifiedPart[];
27
}
28
29
/**
30
* Coalesces adjacent string parts into a single string part.
31
*/
32
export function coalesceParts(parts: readonly LinkifiedPart[]): LinkifiedPart[] {
33
const out: LinkifiedPart[] = [];
34
35
for (const part of parts) {
36
const previous = out.at(-1);
37
if (typeof part === 'string' && typeof previous === 'string') {
38
out[out.length - 1] = previous + part;
39
} else {
40
out.push(part);
41
}
42
}
43
44
return out;
45
}
46
47