Skip to content

Commit ef399e2

Browse files
authored
Merge pull request #719 from Shopify/jm/liquid_doc_hover_caching
[LiquidDoc] Cache liquidDoc definitions in DocumentManager
2 parents a167761 + 9fa9b47 commit ef399e2

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

.changeset/dry-donkeys-behave.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/theme-language-server-common': minor
3+
'@shopify/theme-check-common': minor
4+
---
5+
6+
Cache liquidDoc fetch results

packages/theme-language-server-common/src/documents/DocumentManager.ts

+8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import {
1212
IsValidSchema,
1313
memo,
1414
Mode,
15+
isError,
1516
} from '@shopify/theme-check-common';
1617
import { Connection } from 'vscode-languageserver';
1718
import { TextDocument } from 'vscode-languageserver-textdocument';
1819
import { ClientCapabilities } from '../ClientCapabilities';
1920
import { percent, Progress } from '../progress';
2021
import { AugmentedSourceCode } from './types';
22+
import { getSnippetDefinition } from '../liquidDoc';
2123

2224
export class DocumentManager {
2325
/**
@@ -171,6 +173,12 @@ export class DocumentManager {
171173
const mode = await this.getModeForUri!(uri);
172174
return toSchema(mode, uri, sourceCode, this.isValidSchema);
173175
}),
176+
/** Lazy and only computed once per file version */
177+
liquidDoc: memo(async (snippetName: string) => {
178+
if (isError(sourceCode.ast)) return { name: snippetName };
179+
180+
return getSnippetDefinition(sourceCode.ast, snippetName);
181+
}),
174182
};
175183
default:
176184
return assertNever(sourceCode);

packages/theme-language-server-common/src/documents/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AppBlockSchema,
77
} from '@shopify/theme-check-common';
88
import { TextDocument } from 'vscode-languageserver-textdocument';
9+
import { SnippetDefinition } from '../liquidDoc';
910

1011
/** Util type to add the common `textDocument` property to the SourceCode. */
1112
type _AugmentedSourceCode<SCT extends SourceCodeType = SourceCodeType> = SourceCode<SCT> & {
@@ -23,6 +24,7 @@ export type AugmentedJsonSourceCode = _AugmentedSourceCode<SourceCodeType.JSON>;
2324
*/
2425
export type AugmentedLiquidSourceCode = _AugmentedSourceCode<SourceCodeType.LiquidHtml> & {
2526
getSchema: () => Promise<SectionSchema | ThemeBlockSchema | AppBlockSchema | undefined>;
27+
liquidDoc: (snippetName: string) => Promise<SnippetDefinition>;
2628
};
2729

2830
/**

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function startServer(
185185
return { name: snippetName };
186186
}
187187

188-
return getSnippetDefinition(snippet.ast, snippetName);
188+
return snippet.liquidDoc(snippetName);
189189
};
190190

191191
const snippetFilter = ([uri]: FileTuple) => /\.liquid$/.test(uri) && /snippets/.test(uri);

0 commit comments

Comments
 (0)