Skip to content

Commit 94aee9b

Browse files
committed
--wip-- [skip ci]
1 parent f6775ad commit 94aee9b

2 files changed

Lines changed: 67 additions & 28 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { memo } from '@shopify/theme-check-common';
2+
import { Dependencies } from '@shopify/theme-language-server-browser';
3+
import { Connection } from 'vscode-languageserver/browser';
4+
5+
/**
6+
* These are replaced at build time by the contents of
7+
* @shopify/theme-check-docs-updater's DocsManager
8+
*/
9+
declare global {
10+
export const WEBPACK_TAGS: any[];
11+
export const WEBPACK_FILTERS: any[];
12+
export const WEBPACK_OBJECTS: any[];
13+
export const WEBPACK_SYSTEM_TRANSLATIONS: any;
14+
export const WEBPACK_SCHEMAS: any;
15+
}
16+
17+
const tags = WEBPACK_TAGS;
18+
const filters = WEBPACK_FILTERS;
19+
const objects = WEBPACK_OBJECTS;
20+
const systemTranslations = WEBPACK_SYSTEM_TRANSLATIONS;
21+
const schemas = WEBPACK_SCHEMAS;
22+
23+
type ThemeDocset = Dependencies['themeDocset'];
24+
type JsonValidationSet = Dependencies['jsonValidationSet'];
25+
26+
const fetchDeps = memo(async () => {
27+
return fetch('https://vs-code-for-web.shop.dev/deps.json').then((response) => {
28+
if (!response.ok) {
29+
console.error(response);
30+
throw new Error(`Failed to fetch dependencies: ${response.statusText}`);
31+
}
32+
return response.json();
33+
});
34+
});
35+
36+
export class ThemeDocsetManager implements ThemeDocset, JsonValidationSet {
37+
constructor(private connection: Connection) {}
38+
39+
// Liquid documentation
40+
filters = memo(async () => this.fetchUpdatedData('filters', filters));
41+
tags = memo(async () => this.fetchUpdatedData('tags', tags));
42+
objects = memo(async () => this.fetchUpdatedData('objects', objects));
43+
liquidDrops = memo(async () => this.fetchUpdatedData('objects', objects));
44+
45+
// prettier-ignore
46+
systemTranslations = memo(async () => this.fetchUpdatedData('systemTranslations', systemTranslations));
47+
48+
// JSON validation data
49+
schemas = memo(async () => this.fetchUpdatedData('schemas', schemas));
50+
51+
fetchUpdatedData = async <T>(
52+
dependency: 'filters' | 'tags' | 'objects' | 'systemTranslations' | 'schemas',
53+
fallback: T,
54+
): Promise<T> => {
55+
return fetchDeps()
56+
.then((deps) => deps[dependency] ?? fallback)
57+
.then((data) => {
58+
console.error(`data received! ${dependency}`, data);
59+
return data as T;
60+
})
61+
.catch(() => fallback);
62+
};
63+
}

packages/vscode-extension/src/browser/server.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,12 @@ import {
66
startServer,
77
} from '@shopify/theme-language-server-browser';
88
import { VsCodeFileSystem } from '../common/VsCodeFileSystem';
9-
10-
/**
11-
* These are replaced at build time by the contents of
12-
* @shopify/theme-check-docs-updater's DocsManager
13-
*/
14-
declare global {
15-
export const WEBPACK_TAGS: any[];
16-
export const WEBPACK_FILTERS: any[];
17-
export const WEBPACK_OBJECTS: any[];
18-
export const WEBPACK_SYSTEM_TRANSLATIONS: any;
19-
export const WEBPACK_SCHEMAS: any;
20-
}
21-
22-
const tags = WEBPACK_TAGS;
23-
const filters = WEBPACK_FILTERS;
24-
const objects = WEBPACK_OBJECTS;
25-
const systemTranslations = WEBPACK_SYSTEM_TRANSLATIONS;
26-
const schemas = WEBPACK_SCHEMAS;
9+
import { ThemeDocsetManager } from './ThemeDocset';
2710

2811
const worker = self as any as Worker;
2912
const connection = getConnection(worker);
3013
const fileSystem = new VsCodeFileSystem(connection, {});
14+
const themeDocset = new ThemeDocsetManager(connection);
3115
const dependencies: Dependencies = {
3216
fs: fileSystem,
3317
log: console.info.bind(console),
@@ -45,16 +29,8 @@ const dependencies: Dependencies = {
4529
rootUri,
4630
};
4731
},
48-
themeDocset: {
49-
filters: async () => filters,
50-
objects: async () => objects,
51-
liquidDrops: async () => objects,
52-
tags: async () => tags,
53-
systemTranslations: async () => systemTranslations,
54-
},
55-
jsonValidationSet: {
56-
schemas: async () => schemas,
57-
},
32+
themeDocset: themeDocset,
33+
jsonValidationSet: themeDocset,
5834
};
5935

6036
startServer(worker, dependencies, connection);

0 commit comments

Comments
 (0)