UNPKG

@shopify/theme-language-server-common

Version:

<h1 align="center" style="position: relative;" > <br> <img src="https://github.com/Shopify/theme-check-vscode/blob/main/images/shopify_glyph.png?raw=true" alt="logo" width="141" height="160"> <br> Theme Language Server </h1>

53 lines (47 loc) 1.87 kB
import { check, findRoot, makeFileExists } from '@shopify/theme-check-common'; import { DocumentManager } from '../documents'; import { Dependencies } from '../types'; import { DiagnosticsManager } from './DiagnosticsManager'; export function makeRunChecks( documentManager: DocumentManager, diagnosticsManager: DiagnosticsManager, { fs, loadConfig, themeDocset, jsonValidationSet, }: Pick<Dependencies, 'fs' | 'loadConfig' | 'themeDocset' | 'jsonValidationSet'>, ) { return async function runChecks(triggerURIs: string[]): Promise<void> { // This function takes an array of triggerURIs so that we can correctly // recheck on file renames that came from out of bounds in a // workspaces. // // e.g. if a user renames // theme1/snippets/a.liquid to // theme1/snippets/b.liquid // // then we recheck theme1 const fileExists = makeFileExists(fs); const rootURIs = await Promise.all(triggerURIs.map((uri) => findRoot(uri, fileExists))); const deduplicatedRootURIs = new Set(rootURIs); await Promise.all([...deduplicatedRootURIs].map(runChecksForRoot)); return; async function runChecksForRoot(configFileRootUri: string) { const config = await loadConfig(configFileRootUri, fs); const theme = documentManager.theme(config.rootUri); const offenses = await check(theme, config, { jsonValidationSet, themeDocset, fs, }); // We iterate over the theme files (as opposed to offenses) because if // there were offenses before, we need to send an empty array to clear // them. for (const sourceCode of theme) { const sourceCodeOffenses = offenses.filter((offense) => offense.uri === sourceCode.uri); diagnosticsManager.set(sourceCode.uri, sourceCode.version, sourceCodeOffenses); } } }; }