Path: blob/main/extensions/copilot/src/platform/parser/test/node/getNodeToDocument.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 { _getNodeToDocument } from '../../node/docGenParsing';7import { WASMLanguage } from '../../node/treeSitterLanguages';8import { insertRangeMarkers, MarkerRange } from './markers';910export async function srcWithAnnotatedNodeToDoc(language: WASMLanguage, source: string, includeSelection = false) {11const { deannotatedSrc, annotatedRange: selection } = deannotateSrc(source);1213const result = await _getNodeToDocument(14language,15deannotatedSrc,16selection17);1819const identifier = result.nodeIdentifier;2021const markers: MarkerRange[] = [];2223if (identifier !== undefined && identifier !== '') {24const identIx = deannotatedSrc.indexOf(identifier);25if (identIx !== -1) {26markers.push({27startIndex: identIx,28endIndex: identIx + identifier.length,29kind: 'IDENT'30});31}32}3334if (includeSelection) {35markers.push(36{37startIndex: selection.startIndex,38endIndex: selection.endIndex,39kind: 'SELECTION'40}41);42}4344markers.push(45{46startIndex: result.nodeToDocument.startIndex,47endIndex: result.nodeToDocument.endIndex,48kind: result.nodeToDocument.type.toUpperCase(),49}50);5152return insertRangeMarkers(deannotatedSrc, markers);53}545556