|
1 | 1 | import {
|
2 |
| - ThemeBlockSchema, |
3 | 2 | check,
|
4 | 3 | findRoot,
|
5 | 4 | makeFileExists,
|
| 5 | + Offense, |
6 | 6 | path,
|
7 | 7 | SectionSchema,
|
8 |
| - SourceCodeType, |
9 |
| - Offense, |
10 | 8 | Severity,
|
| 9 | + SourceCodeType, |
| 10 | + ThemeBlockSchema, |
11 | 11 | } from '@shopify/theme-check-common';
|
12 | 12 |
|
13 |
| -import { DocumentManager } from '../documents'; |
| 13 | +import { CSSLanguageService } from '../css/CSSLanguageService'; |
| 14 | +import { AugmentedSourceCode, DocumentManager } from '../documents'; |
14 | 15 | import { Dependencies } from '../types';
|
15 | 16 | import { DiagnosticsManager } from './DiagnosticsManager';
|
16 |
| -import { CSSLanguageService } from '../css/CSSLanguageService'; |
17 | 17 | import { offenseSeverity } from './offenseToDiagnostic';
|
18 | 18 |
|
19 | 19 | export function makeRunChecks(
|
@@ -51,42 +51,13 @@ export function makeRunChecks(
|
51 | 51 | async function runChecksForRoot(configFileRootUri: string) {
|
52 | 52 | const config = await loadConfig(configFileRootUri, fs);
|
53 | 53 | const theme = documentManager.theme(config.rootUri);
|
54 |
| - let cssOffenses: Offense[] = []; |
55 |
| - if (cssLanguageService) { |
56 |
| - for (const sourceCode of theme) { |
57 |
| - if (sourceCode.type !== SourceCodeType.LiquidHtml) continue; |
58 |
| - cssOffenses.push( |
59 |
| - ...( |
60 |
| - await cssLanguageService.diagnostics({ |
61 |
| - textDocument: { |
62 |
| - uri: sourceCode.uri, |
63 |
| - }, |
64 |
| - }) |
65 |
| - ) |
66 |
| - .map( |
67 |
| - (diagnostic) => |
68 |
| - ({ |
69 |
| - check: 'css', |
70 |
| - message: diagnostic.message, |
71 |
| - end: { |
72 |
| - index: sourceCode.textDocument.offsetAt(diagnostic.range.end), |
73 |
| - line: diagnostic.range.end.line, |
74 |
| - character: diagnostic.range.end.character, |
75 |
| - }, |
76 |
| - start: { |
77 |
| - index: sourceCode.textDocument.offsetAt(diagnostic.range.start), |
78 |
| - line: diagnostic.range.start.line, |
79 |
| - character: diagnostic.range.start.character, |
80 |
| - }, |
81 |
| - severity: offenseSeverity(diagnostic), |
82 |
| - uri: sourceCode.uri, |
83 |
| - type: SourceCodeType.LiquidHtml, |
84 |
| - } satisfies Offense), |
85 |
| - ) |
86 |
| - .filter((offense) => offense.severity !== Severity.INFO), |
87 |
| - ); |
88 |
| - } |
89 |
| - } |
| 54 | + |
| 55 | + const cssOffenses = cssLanguageService |
| 56 | + ? await Promise.all( |
| 57 | + theme.map((sourceCode) => getCSSDiagnostics(cssLanguageService, sourceCode)), |
| 58 | + ).then((offenses) => offenses.flat()) |
| 59 | + : []; |
| 60 | + |
90 | 61 | const themeOffenses = await check(theme, config, {
|
91 | 62 | fs,
|
92 | 63 | themeDocset,
|
@@ -124,3 +95,38 @@ export function makeRunChecks(
|
124 | 95 | }
|
125 | 96 | };
|
126 | 97 | }
|
| 98 | + |
| 99 | +async function getCSSDiagnostics( |
| 100 | + cssLanguageService: CSSLanguageService, |
| 101 | + sourceCode: AugmentedSourceCode, |
| 102 | +): Promise<Offense[]> { |
| 103 | + if (sourceCode.type !== SourceCodeType.LiquidHtml) { |
| 104 | + return []; |
| 105 | + } |
| 106 | + |
| 107 | + const diagnostics = await cssLanguageService.diagnostics({ |
| 108 | + textDocument: { uri: sourceCode.uri }, |
| 109 | + }); |
| 110 | + |
| 111 | + return diagnostics |
| 112 | + .map( |
| 113 | + (diagnostic): Offense => ({ |
| 114 | + check: 'css', |
| 115 | + message: diagnostic.message, |
| 116 | + end: { |
| 117 | + index: sourceCode.textDocument.offsetAt(diagnostic.range.end), |
| 118 | + line: diagnostic.range.end.line, |
| 119 | + character: diagnostic.range.end.character, |
| 120 | + }, |
| 121 | + start: { |
| 122 | + index: sourceCode.textDocument.offsetAt(diagnostic.range.start), |
| 123 | + line: diagnostic.range.start.line, |
| 124 | + character: diagnostic.range.start.character, |
| 125 | + }, |
| 126 | + severity: offenseSeverity(diagnostic), |
| 127 | + uri: sourceCode.uri, |
| 128 | + type: SourceCodeType.LiquidHtml, |
| 129 | + }), |
| 130 | + ) |
| 131 | + .filter((offense) => offense.severity !== Severity.INFO); |
| 132 | +} |
0 commit comments