3
3
FileTuple ,
4
4
findRoot as findConfigFileRoot ,
5
5
isError ,
6
+ LiquidDocDefinition ,
7
+ LiquidDocDefinitionMap ,
8
+ LiquidDocParameter ,
6
9
makeFileExists ,
7
10
makeGetDefaultSchemaTranslations ,
8
11
makeGetDefaultTranslations ,
@@ -12,6 +15,7 @@ import {
12
15
path ,
13
16
recursiveReadDirectory ,
14
17
SourceCodeType ,
18
+ visit ,
15
19
} from '@shopify/theme-check-common' ;
16
20
import {
17
21
Connection ,
@@ -169,6 +173,56 @@ export function startServer(
169
173
return getDefaultSchemaTranslations ( ) ;
170
174
} ;
171
175
176
+ // todo - put this stuff in theme check common
177
+ const getLiquidDocDefinitionsForURI = async (
178
+ uri : string ,
179
+ snippetName : string ,
180
+ ) : Promise < LiquidDocDefinitionMap > => {
181
+ const rootUri = await findThemeRootURI ( uri ) ;
182
+ const snippetURI = path . join ( rootUri , 'snippets' , `${ snippetName } .liquid` ) ;
183
+ const snippet = documentManager . get ( snippetURI ) ;
184
+
185
+ if ( ! snippet || isError ( snippet ) ) return { } ;
186
+
187
+ if ( snippet . type !== SourceCodeType . LiquidHtml ) return { } ;
188
+
189
+ // read the snippet AST
190
+ const ast = snippet . ast ;
191
+ if ( isError ( ast ) ) return { } ;
192
+
193
+ const docDefinitions = visit < SourceCodeType . LiquidHtml , LiquidDocDefinition > ( ast , {
194
+ LiquidRawTag : ( node , _ancestors ) => {
195
+ if ( node . name === 'doc' ) {
196
+ const body = node . body ;
197
+ const paramNodes = visit < SourceCodeType . LiquidHtml , LiquidDocParameter > ( body , {
198
+ LiquidDocParamNode : ( node ) => {
199
+ return [
200
+ {
201
+ name : node . paramName . value ,
202
+ description : node . paramDescription . value ,
203
+ type : node . paramType . value ,
204
+ } ,
205
+ ] ;
206
+ } ,
207
+ } ) ;
208
+ return {
209
+ name : snippetName ,
210
+ description : 'placeholder' ,
211
+ parameters : paramNodes ,
212
+ } ;
213
+ }
214
+ } ,
215
+ } ) ;
216
+
217
+ const returnVal : LiquidDocDefinitionMap = {
218
+ [ snippetName ] : {
219
+ name : snippetName ,
220
+ parameters : docDefinitions [ 0 ] . parameters ,
221
+ } ,
222
+ } ;
223
+ return returnVal ;
224
+ } ;
225
+
172
226
const snippetFilter = ( [ uri ] : FileTuple ) => / \. l i q u i d $ / . test ( uri ) && / s n i p p e t s / . test ( uri ) ;
173
227
const getSnippetNamesForURI : GetSnippetNamesForURI = async ( uri : string ) => {
174
228
const rootUri = await findThemeRootURI ( uri ) ;
@@ -249,6 +303,7 @@ export function startServer(
249
303
getMetafieldDefinitions ,
250
304
getTranslationsForURI ,
251
305
getThemeSettingsSchemaForURI ,
306
+ getLiquidDocDefinitionsForURI ,
252
307
) ;
253
308
254
309
const executeCommandProvider = new ExecuteCommandProvider (
0 commit comments