Skip to content

Commit

Permalink
Connect SnippetHoverProvider with server
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Jan 17, 2025
1 parent 0d6fe25 commit d7b4b61
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/theme-language-server-common/src/hover/HoverProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { MetafieldDefinitionMap, SourceCodeType, ThemeDocset } from '@shopify/theme-check-common';
import {
LiquidDocDefinition,
MetafieldDefinitionMap,
SourceCodeType,
ThemeDocset,
} from '@shopify/theme-check-common';
import { Hover, HoverParams } from 'vscode-languageserver';
import { TypeSystem } from '../TypeSystem';
import { DocumentManager } from '../documents';
Expand All @@ -11,6 +16,7 @@ import {
LiquidObjectAttributeHoverProvider,
LiquidObjectHoverProvider,
LiquidTagHoverProvider,
SnippetHoverProvider,
TranslationHoverProvider,
} from './providers';
import { HtmlAttributeValueHoverProvider } from './providers/HtmlAttributeValueHoverProvider';
Expand All @@ -26,6 +32,10 @@ export class HoverProvider {
readonly getMetafieldDefinitions: (rootUri: string) => Promise<MetafieldDefinitionMap>,
readonly getTranslationsForURI: GetTranslationsForURI = async () => ({}),
readonly getSettingsSchemaForURI: GetThemeSettingsSchemaForURI = async () => [],
readonly getLiquidDocDefinitionsForURI: (
uri: string,
snippetName: string,
) => Promise<LiquidDocDefinition>,
) {
const typeSystem = new TypeSystem(
themeDocset,
Expand All @@ -41,6 +51,7 @@ export class HoverProvider {
new HtmlAttributeHoverProvider(),
new HtmlAttributeValueHoverProvider(),
new TranslationHoverProvider(getTranslationsForURI, documentManager),
new SnippetHoverProvider(getLiquidDocDefinitionsForURI),
];
}

Expand Down
20 changes: 20 additions & 0 deletions packages/theme-language-server-common/src/server/startServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {
FileTuple,
findRoot as findConfigFileRoot,
isError,
LiquidDocDefinition,
makeFileExists,
makeGetDefaultSchemaTranslations,
makeGetDefaultTranslations,
makeGetMetafieldDefinitions,
makeGetLiquidDocDefinitions,
memoize,
parseJSON,
path,
Expand Down Expand Up @@ -171,6 +173,23 @@ export function startServer(
return getDefaultSchemaTranslations();
};

const getLiquidDocDefinitionsForURI = async (
uri: string,
snippetName: string,
): Promise<LiquidDocDefinition> => {
const rootUri = await findThemeRootURI(uri);
const snippetURI = path.join(rootUri, 'snippets', `${snippetName}.liquid`);
const snippet = documentManager.get(snippetURI);

if (!snippet || snippet.type !== SourceCodeType.LiquidHtml || isError(snippet.ast)) {
return { name: snippetName };
}

const getLiquidDocDefinitions = makeGetLiquidDocDefinitions(snippet.ast, snippetName);

return getLiquidDocDefinitions();
};

const snippetFilter = ([uri]: FileTuple) => /\.liquid$/.test(uri) && /snippets/.test(uri);
const getSnippetNamesForURI: GetSnippetNamesForURI = async (uri: string) => {
const rootUri = await findThemeRootURI(uri);
Expand Down Expand Up @@ -251,6 +270,7 @@ export function startServer(
getMetafieldDefinitions,
getTranslationsForURI,
getThemeSettingsSchemaForURI,
getLiquidDocDefinitionsForURI,
);

const executeCommandProvider = new ExecuteCommandProvider(
Expand Down

0 comments on commit d7b4b61

Please sign in to comment.