33 type CompletionItemTag ,
44 type CompletionList ,
55 type Disposable ,
6+ type LanguageServiceContext ,
67 type LanguageServicePlugin ,
78 type TextDocument ,
89 transformCompletionItem ,
@@ -86,9 +87,43 @@ export function create(
8687 } ,
8788 } ;
8889 } ;
90+ const getDocumentContext : ( context : LanguageServiceContext ) => html . DocumentContext = context => ( {
91+ resolveReference ( ref , base ) {
92+ let baseUri = URI . parse ( base ) ;
93+ const decoded = context . decodeEmbeddedDocumentUri ( baseUri ) ;
94+ if ( decoded ) {
95+ baseUri = decoded [ 0 ] ;
96+ }
97+ if (
98+ modulePathCache
99+ && baseUri . scheme === 'file'
100+ && ! ref . startsWith ( './' )
101+ && ! ref . startsWith ( '../' )
102+ ) {
103+ const map = modulePathCache ;
104+ if ( ! map . has ( ref ) ) {
105+ const fileName = baseUri . fsPath . replace ( / \\ / g, '/' ) ;
106+ const promise = resolveModuleName ( fileName , ref ) ;
107+ map . set ( ref , promise ) ;
108+ if ( promise instanceof Promise ) {
109+ promise . then ( res => map . set ( ref , res ) ) ;
110+ }
111+ }
112+ const cached = modulePathCache . get ( ref ) ;
113+ if ( cached instanceof Promise ) {
114+ throw cached ;
115+ }
116+ if ( cached ) {
117+ return cached ;
118+ }
119+ }
120+ return resolveReference ( ref , baseUri , context . env . workspaceFolders ) ;
121+ } ,
122+ } ) ;
89123 const baseService = languageId === 'jade'
90124 ? createPugService ( {
91125 useDefaultDataProvider : false ,
126+ getDocumentContext,
92127 getCustomData ( ) {
93128 return [
94129 ...customData ,
@@ -100,41 +135,7 @@ export function create(
100135 : createHtmlService ( {
101136 documentSelector : [ 'html' , 'markdown' ] ,
102137 useDefaultDataProvider : false ,
103- getDocumentContext ( context ) {
104- return {
105- resolveReference ( ref , base ) {
106- let baseUri = URI . parse ( base ) ;
107- const decoded = context . decodeEmbeddedDocumentUri ( baseUri ) ;
108- if ( decoded ) {
109- baseUri = decoded [ 0 ] ;
110- }
111- if (
112- modulePathCache
113- && baseUri . scheme === 'file'
114- && ! ref . startsWith ( './' )
115- && ! ref . startsWith ( '../' )
116- ) {
117- const map = modulePathCache ;
118- if ( ! map . has ( ref ) ) {
119- const fileName = baseUri . fsPath . replace ( / \\ / g, '/' ) ;
120- const promise = resolveModuleName ( fileName , ref ) ;
121- map . set ( ref , promise ) ;
122- if ( promise instanceof Promise ) {
123- promise . then ( res => map . set ( ref , res ) ) ;
124- }
125- }
126- const cached = modulePathCache . get ( ref ) ;
127- if ( cached instanceof Promise ) {
128- throw cached ;
129- }
130- if ( cached ) {
131- return cached ;
132- }
133- }
134- return resolveReference ( ref , baseUri , context . env . workspaceFolders ) ;
135- } ,
136- } ;
137- } ,
138+ getDocumentContext,
138139 getCustomData ( ) {
139140 return [
140141 ...customData ,
0 commit comments