Skip to content

Commit b6ca8f0

Browse files
committed
Connect SnippetHoverProvider with server
1 parent a41145a commit b6ca8f0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

packages/theme-language-server-common/src/hover/HoverProvider.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { MetafieldDefinitionMap, SourceCodeType, ThemeDocset } from '@shopify/theme-check-common';
1+
import {
2+
LiquidDocDefinition,
3+
MetafieldDefinitionMap,
4+
SourceCodeType,
5+
ThemeDocset,
6+
} from '@shopify/theme-check-common';
27
import { Hover, HoverParams } from 'vscode-languageserver';
38
import { TypeSystem } from '../TypeSystem';
49
import { DocumentManager } from '../documents';
@@ -11,6 +16,7 @@ import {
1116
LiquidObjectAttributeHoverProvider,
1217
LiquidObjectHoverProvider,
1318
LiquidTagHoverProvider,
19+
SnippetHoverProvider,
1420
TranslationHoverProvider,
1521
} from './providers';
1622
import { HtmlAttributeValueHoverProvider } from './providers/HtmlAttributeValueHoverProvider';
@@ -26,6 +32,10 @@ export class HoverProvider {
2632
readonly getMetafieldDefinitions: (rootUri: string) => Promise<MetafieldDefinitionMap>,
2733
readonly getTranslationsForURI: GetTranslationsForURI = async () => ({}),
2834
readonly getSettingsSchemaForURI: GetThemeSettingsSchemaForURI = async () => [],
35+
readonly getLiquidDocDefinitionsForURI: (
36+
uri: string,
37+
snippetName: string,
38+
) => Promise<LiquidDocDefinition>,
2939
) {
3040
const typeSystem = new TypeSystem(
3141
themeDocset,
@@ -41,6 +51,7 @@ export class HoverProvider {
4151
new HtmlAttributeHoverProvider(),
4252
new HtmlAttributeValueHoverProvider(),
4353
new TranslationHoverProvider(getTranslationsForURI, documentManager),
54+
new SnippetHoverProvider(getLiquidDocDefinitionsForURI),
4455
];
4556
}
4657

packages/theme-language-server-common/src/server/startServer.ts

+20
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {
33
FileTuple,
44
findRoot as findConfigFileRoot,
55
isError,
6+
LiquidDocDefinition,
67
makeFileExists,
78
makeGetDefaultSchemaTranslations,
89
makeGetDefaultTranslations,
910
makeGetMetafieldDefinitions,
11+
makeGetLiquidDocDefinitions,
1012
memoize,
1113
parseJSON,
1214
path,
@@ -171,6 +173,23 @@ export function startServer(
171173
return getDefaultSchemaTranslations();
172174
};
173175

176+
const getLiquidDocDefinitionsForURI = async (
177+
uri: string,
178+
snippetName: string,
179+
): Promise<LiquidDocDefinition> => {
180+
const rootUri = await findThemeRootURI(uri);
181+
const snippetURI = path.join(rootUri, 'snippets', `${snippetName}.liquid`);
182+
const snippet = documentManager.get(snippetURI);
183+
184+
if (!snippet || snippet.type !== SourceCodeType.LiquidHtml || isError(snippet.ast)) {
185+
return { name: snippetName };
186+
}
187+
188+
const getLiquidDocDefinitions = makeGetLiquidDocDefinitions(snippet.ast, snippetName);
189+
190+
return getLiquidDocDefinitions();
191+
};
192+
174193
const snippetFilter = ([uri]: FileTuple) => /\.liquid$/.test(uri) && /snippets/.test(uri);
175194
const getSnippetNamesForURI: GetSnippetNamesForURI = async (uri: string) => {
176195
const rootUri = await findThemeRootURI(uri);
@@ -251,6 +270,7 @@ export function startServer(
251270
getMetafieldDefinitions,
252271
getTranslationsForURI,
253272
getThemeSettingsSchemaForURI,
273+
getLiquidDocDefinitionsForURI,
254274
);
255275

256276
const executeCommandProvider = new ExecuteCommandProvider(

0 commit comments

Comments
 (0)