Skip to content

Commit 9afe6c8

Browse files
committed
Fixups
1 parent c296ff5 commit 9afe6c8

File tree

3 files changed

+51
-56
lines changed

3 files changed

+51
-56
lines changed

packages/theme-language-server-common/src/css/CSSLanguageService.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ export class CSSLanguageService {
9595
// Which means that the completions will be at the same line number in the Liquid document
9696
const stylesheetString =
9797
Array(schemaLineNumber).fill('\n').join('') +
98-
stylesheetTag.source.slice(
99-
stylesheetTag.blockStartPosition.end,
100-
stylesheetTag.blockEndPosition.start,
101-
);
98+
stylesheetTag.source
99+
.slice(stylesheetTag.blockStartPosition.end, stylesheetTag.blockEndPosition.start)
100+
.replace(/\n$/, ''); // Remove trailing newline so parsing errors don't show up on `{% endstylesheet %}`
102101
const stylesheetTextDocument = TextDocument.create(
103102
textDocument.uri,
104103
'json',

packages/theme-language-server-common/src/diagnostics/runChecks.ts

+47-41
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import {
2-
ThemeBlockSchema,
32
check,
43
findRoot,
54
makeFileExists,
5+
Offense,
66
path,
77
SectionSchema,
8-
SourceCodeType,
9-
Offense,
108
Severity,
9+
SourceCodeType,
10+
ThemeBlockSchema,
1111
} from '@shopify/theme-check-common';
1212

13-
import { DocumentManager } from '../documents';
13+
import { CSSLanguageService } from '../css/CSSLanguageService';
14+
import { AugmentedSourceCode, DocumentManager } from '../documents';
1415
import { Dependencies } from '../types';
1516
import { DiagnosticsManager } from './DiagnosticsManager';
16-
import { CSSLanguageService } from '../css/CSSLanguageService';
1717
import { offenseSeverity } from './offenseToDiagnostic';
1818

1919
export function makeRunChecks(
@@ -51,42 +51,13 @@ export function makeRunChecks(
5151
async function runChecksForRoot(configFileRootUri: string) {
5252
const config = await loadConfig(configFileRootUri, fs);
5353
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+
9061
const themeOffenses = await check(theme, config, {
9162
fs,
9263
themeDocset,
@@ -124,3 +95,38 @@ export function makeRunChecks(
12495
}
12596
};
12697
}
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+
}

yarn.lock

+1-11
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,6 @@
517517
"@jridgewell/sourcemap-codec" "^1.4.10"
518518
"@jridgewell/trace-mapping" "^0.3.9"
519519

520-
"@jridgewell/[email protected]":
521-
version "3.1.0"
522-
resolved "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz"
523-
integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==
524-
525520
"@jridgewell/resolve-uri@^3.0.3", "@jridgewell/resolve-uri@^3.1.0":
526521
version "3.1.2"
527522
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz#7a0ee601f60f99a20c7c7c5ff0c80388c1189bd6"
@@ -540,11 +535,6 @@
540535
"@jridgewell/gen-mapping" "^0.3.0"
541536
"@jridgewell/trace-mapping" "^0.3.9"
542537

543-
"@jridgewell/[email protected]":
544-
version "1.4.14"
545-
resolved "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz"
546-
integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==
547-
548538
"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14", "@jridgewell/sourcemap-codec@^1.5.0":
549539
version "1.5.0"
550540
resolved "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz#3188bcb273a414b0d215fd22a58540b989b9409a"
@@ -5816,7 +5806,7 @@ sockjs@^0.3.24:
58165806
uuid "^8.3.2"
58175807
websocket-driver "^0.7.4"
58185808

5819-
source-map-js@^1.2.0, source-map-js@^1.2.1:
5809+
source-map-js@^1.2.1:
58205810
version "1.2.1"
58215811
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.1.tgz#1ce5650fddd87abc099eda37dcff024c2667ae46"
58225812
integrity sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==

0 commit comments

Comments
 (0)