@@ -2,11 +2,11 @@ import { Edit, Point, SyntaxNode, Tree } from 'tree-sitter';
22import { Position } from 'vscode-languageserver-textdocument' ;
33import { DocumentType } from '../../document/Document' ;
44import { createEdit } from '../../document/DocumentUtils' ;
5- import { parserFactory } from '../../parser/ParserFactory' ;
6- import { parserType } from '../../parser/ParserType' ;
5+ import { ParserFactory } from '../../parser/ParserFactory' ;
76import { Measure } from '../../telemetry/TelemetryDecorator' ;
87import { TopLevelSection , TopLevelSections , IntrinsicsSet } from '../CloudFormationEnums' ;
98import { normalizeIntrinsicFunction } from '../semantic/Intrinsics' ;
9+ import { ParserType } from './SyntaxTreeFactory' ;
1010import { extractEntityFromNodeTextYaml } from './utils/NodeParse' ;
1111import { NodeSearch } from './utils/NodeSearch' ;
1212import { NodeStructure } from './utils/NodeStructure' ;
@@ -29,15 +29,19 @@ export abstract class SyntaxTree {
2929 private readonly parser ;
3030 private rawContent : string ;
3131 private _lines : string [ ] | undefined ;
32+ private readonly parserType : ParserType ;
3233
3334 protected constructor (
3435 public readonly type : DocumentType ,
3536 content : string ,
37+ factory : ParserFactory ,
38+ parserType : ParserType ,
3639 ) {
40+ this . parserType = parserType ;
3741 if ( type === DocumentType . YAML ) {
38- this . parser = parserFactory . createYamlParser ( ) ;
42+ this . parser = factory . createYamlParser ( ) ;
3943 } else {
40- this . parser = parserFactory . createJsonParser ( ) ;
44+ this . parser = factory . createJsonParser ( ) ;
4145 }
4246 this . rawContent = content ;
4347 this . tree = this . parser . parse ( this . rawContent ) ;
@@ -48,21 +52,21 @@ export abstract class SyntaxTree {
4852 return this . _lines ;
4953 }
5054
51- @Measure ( { name : 'updateWithEdit' , captureErrorAttributes : true , attributes : { 'parser.type' : parserType } } )
55+ @Measure ( { name : 'updateWithEdit' , captureErrorAttributes : true } )
5256 public updateWithEdit ( content : string , edit : Edit ) {
5357 this . _lines = undefined ; // Invalidate cache
5458 this . rawContent = content ; // Update raw content
5559 this . tree . edit ( edit ) ;
5660 this . tree = this . parser . parse ( content , this . tree ) ;
5761 }
5862
59- @Measure ( { name : 'update' , captureErrorAttributes : true , attributes : { 'parser.type' : parserType } } )
63+ @Measure ( { name : 'update' , captureErrorAttributes : true } )
6064 public update ( textToInsert : string , start : Point , end : Point ) {
6165 const { newContent, edit } = createEdit ( this . content ( ) , textToInsert , start , end ) ;
6266 this . updateWithEdit ( newContent , edit ) ;
6367 }
6468
65- @Measure ( { name : 'getNodeAtPosition' , captureErrorAttributes : true , attributes : { 'parser.type' : parserType } } )
69+ @Measure ( { name : 'getNodeAtPosition' , captureErrorAttributes : true } )
6670 public getNodeAtPosition ( position : Position ) : SyntaxNode {
6771 const point : Point = {
6872 row : position . line ,
@@ -416,7 +420,7 @@ export abstract class SyntaxTree {
416420 * Analyzes a node to determine its semantic path within the document.
417421 * It walks up the tree from the given node, building a property path and identifying the entity root.
418422 */
419- @Measure ( { name : 'getPathAndEntityInfo' , captureErrorAttributes : true , attributes : { 'parser.type' : parserType } } )
423+ @Measure ( { name : 'getPathAndEntityInfo' , captureErrorAttributes : true } )
420424 public getPathAndEntityInfo ( node : SyntaxNode ) : PathAndEntity {
421425 if ( ! node ) {
422426 return {
@@ -842,7 +846,7 @@ export abstract class SyntaxTree {
842846 * @param pathSegments Array like ["Resources", "MyBucket", "Properties", "BucketName"] or ["Resources", "MyBucket", "Properties", 0]
843847 * @returns Object with the node and whether the full path was resolved
844848 */
845- @Measure ( { name : 'getNodeByPath' , captureErrorAttributes : true , attributes : { 'parser.type' : parserType } } )
849+ @Measure ( { name : 'getNodeByPath' , captureErrorAttributes : true } )
846850 getNodeByPath ( pathSegments : ReadonlyArray < string | number > ) : {
847851 node : SyntaxNode | undefined ;
848852 fullyResolved : boolean ;
@@ -962,7 +966,7 @@ export abstract class SyntaxTree {
962966 }
963967
964968 // Finds CloudFormation sections (Parameters, Resources, etc.)
965- @Measure ( { name : 'findTopLevelSections' , attributes : { 'parser.type' : parserType } } )
969+ @Measure ( { name : 'findTopLevelSections' } )
966970 public findTopLevelSections ( sectionsToFind : TopLevelSection [ ] ) : Map < TopLevelSection , SyntaxNode > {
967971 const result = new Map < TopLevelSection , SyntaxNode > ( ) ;
968972 if ( sectionsToFind . length === 0 ) {
0 commit comments