Path: blob/main/extensions/copilot/src/platform/parser/test/node/getTestableNode.util.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { deannotateSrc } from '../../../../util/common/test/annotatedSrc';6import { _getTestableNode } from '../../node/testGenParsing';7import { WASMLanguage } from '../../node/treeSitterLanguages';8import { insertRangeMarkers, MarkerRange } from './markers';910export async function srcWithAnnotatedTestableNode(language: WASMLanguage, source: string, includeSelection = false) {11const { deannotatedSrc, annotatedRange: selection } = deannotateSrc(source);1213const result = await _getTestableNode(14language,15deannotatedSrc,16selection17);1819if (result === null) {20return 'testable node NOT found';21}2223const markers: MarkerRange[] = [];2425const ident = result.identifier;26markers.push({27startIndex: ident.range.startIndex,28endIndex: ident.range.endIndex,29kind: 'IDENT',30});3132if (includeSelection) {33markers.push(34{35startIndex: selection.startIndex,36endIndex: selection.endIndex,37kind: 'SELECTION'38}39);40}4142markers.push(43{44startIndex: result.node.startIndex,45endIndex: result.node.endIndex,46kind: `NODE(${result.node.type})`,47}48);4950return insertRangeMarkers(deannotatedSrc, markers);51}525354