Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/parser/test/node/getTestableNode.util.ts
13405 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 { deannotateSrc } from '../../../../util/common/test/annotatedSrc';
7
import { _getTestableNode } from '../../node/testGenParsing';
8
import { WASMLanguage } from '../../node/treeSitterLanguages';
9
import { insertRangeMarkers, MarkerRange } from './markers';
10
11
export async function srcWithAnnotatedTestableNode(language: WASMLanguage, source: string, includeSelection = false) {
12
const { deannotatedSrc, annotatedRange: selection } = deannotateSrc(source);
13
14
const result = await _getTestableNode(
15
language,
16
deannotatedSrc,
17
selection
18
);
19
20
if (result === null) {
21
return 'testable node NOT found';
22
}
23
24
const markers: MarkerRange[] = [];
25
26
const ident = result.identifier;
27
markers.push({
28
startIndex: ident.range.startIndex,
29
endIndex: ident.range.endIndex,
30
kind: 'IDENT',
31
});
32
33
if (includeSelection) {
34
markers.push(
35
{
36
startIndex: selection.startIndex,
37
endIndex: selection.endIndex,
38
kind: 'SELECTION'
39
}
40
);
41
}
42
43
markers.push(
44
{
45
startIndex: result.node.startIndex,
46
endIndex: result.node.endIndex,
47
kind: `NODE(${result.node.type})`,
48
}
49
);
50
51
return insertRangeMarkers(deannotatedSrc, markers);
52
}
53
54