@@ -6,8 +6,7 @@ import { DefinitionParams, ReferenceParams } from 'vscode-languageserver-protoco
6
6
import { jsonPointerEvaluate } from '@swagger-api/apidom-reference' ;
7
7
8
8
import { LanguageSettings } from '../../apidom-language-types' ;
9
- import { getParser , isAsyncDoc } from '../../parser-factory' ;
10
- import { getSourceMap , isArray , isMember , isObject , setMetadataMap } from '../../utils/utils' ;
9
+ import { getSourceMap , isArray , isMember , isObject } from '../../utils/utils' ;
11
10
12
11
export interface DefinitionService {
13
12
doProvideDefinition (
@@ -35,26 +34,15 @@ export class DefaultDefinitionService implements DefinitionService {
35
34
textDocument : TextDocument ,
36
35
definitionParams : DefinitionParams ,
37
36
) : Promise < Location | null > {
38
- const parser = getParser ( textDocument ) ;
39
- const text : string = textDocument . getText ( ) ;
40
-
41
37
const offset = textDocument . offsetAt ( definitionParams . position ) ;
42
38
43
- const result = await parser . parse ( text , { sourceMap : true } ) ;
44
-
39
+ const result = await this . settings ! . documentCache ?. get ( textDocument ) ;
40
+ if ( ! result ) return null ;
45
41
const api : ObjectElement = < ObjectElement > result . api ;
46
42
47
43
// no API document has been parsed
48
44
if ( api === undefined ) return null ;
49
45
50
- // use the type related metadata at root level
51
- setMetadataMap (
52
- api ,
53
- isAsyncDoc ( text ) ? 'asyncapi' : 'openapi' ,
54
- this . settings ?. metadata ?. metadataMaps ,
55
- ) ; // TODO (francesco.tumanischvili@smartbear.com) move to parser/adapter, extending the one standard
56
- api . freeze ( ) ; // !! freeze and add parent !!
57
-
58
46
// TODO (francesco.tumanischvili@smartbear.com): handle by predicates and adapters, look for
59
47
// refElements and/or metadata, replace current shaky handling by `$ref` key lookup
60
48
const node = findAtOffset ( { offset, includeRightBound : true } , api ) ;
@@ -94,27 +82,16 @@ export class DefaultDefinitionService implements DefinitionService {
94
82
textDocument : TextDocument ,
95
83
referenceParams : ReferenceParams ,
96
84
) : Promise < Location [ ] | null > {
97
- const parser = getParser ( textDocument ) ;
98
- const text : string = textDocument . getText ( ) ;
99
-
100
85
// const asyncapi: boolean = isAsyncDoc(textDocument);
101
86
const offset = textDocument . offsetAt ( referenceParams . position ) ;
102
87
103
- const result = await parser . parse ( text , { sourceMap : true } ) ;
104
-
88
+ const result = await this . settings ! . documentCache ?. get ( textDocument ) ;
89
+ if ( ! result ) return null ;
105
90
const api : ObjectElement = < ObjectElement > result . api ;
106
91
107
92
// no API document has been parsed
108
93
if ( api === undefined ) return null ;
109
94
110
- // use the type related metadata at root level
111
- setMetadataMap (
112
- api ,
113
- isAsyncDoc ( text ) ? 'asyncapi' : 'openapi' ,
114
- this . settings ?. metadata ?. metadataMaps ,
115
- ) ; // TODO (francesco.tumanischvili@smartbear.com) move to parser/adapter, extending the one standard
116
- api . freeze ( ) ; // !! freeze and add parent !!
117
-
118
95
// TODO(francesco.tumanischvili@smartbear.com): handle by predicates and adapters, look for
119
96
// refElements and/or metadata, replace current shaky handling by `$ref` key lookup
120
97
const node = findAtOffset ( { offset, includeRightBound : true } , api ) ;
0 commit comments