@@ -12,6 +12,7 @@ import { filesState, documentsState, settingsState } from '../state';
1212import type { Diagnostic , ParseOptions } from '@asyncapi/parser/cjs' ;
1313import type { DocumentDiagnostics } from '../state/documents.state' ;
1414import { SchemaParser } from '@asyncapi/parser' ;
15+ import { getLocationForJsonPath , parseWithPointers } from '@stoplight/yaml' ;
1516
1617export class ParserService extends AbstractService {
1718 private parser ! : Parser ;
@@ -71,14 +72,36 @@ export class ParserService extends AbstractService {
7172 getRangeForJsonPath ( uri : string , jsonPath : string | Array < string | number > ) {
7273 try {
7374 const { documents } = documentsState . getState ( ) ;
75+
76+ const extras = documents [ String ( uri ) ] ?. extras ;
77+
78+ if ( extras ) {
79+ jsonPath = Array . isArray ( jsonPath ) ? jsonPath : jsonPath . split ( '/' ) . map ( untilde ) ;
80+ if ( jsonPath [ 0 ] === '' ) jsonPath . shift ( ) ;
81+
82+ return extras . document . getRangeForJsonPath ( jsonPath ) ;
83+ }
84+ } catch ( err ) {
85+ console . error ( err ) ;
86+ }
87+ }
88+
89+ getRangeForYamlPath ( uri : string , jsonPath : string | Array < string | number > ) {
90+ try {
91+ const { documents } = documentsState . getState ( ) ;
92+
7493 const extras = documents [ String ( uri ) ] ?. extras ;
94+
7595 if ( extras ) {
7696 jsonPath = Array . isArray ( jsonPath ) ? jsonPath : jsonPath . split ( '/' ) . map ( untilde ) ;
7797 if ( jsonPath [ 0 ] === '' ) jsonPath . shift ( ) ;
78- return extras . document . getRangeForJsonPath ( jsonPath , true ) ;
98+ const yamlDoc = parseWithPointers ( this . svcs . editorSvc . value ) ;
99+
100+ const location = getLocationForJsonPath ( yamlDoc , jsonPath , true ) ;
101+ return location ?. range || { start : { line : 0 , character : 0 } , end : { line : 0 , character : 0 } } ;
79102 }
80- } catch ( err : any ) {
81- return ;
103+ } catch ( err ) {
104+ console . error ( err ) ;
82105 }
83106 }
84107
0 commit comments