-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
46 lines (36 loc) · 1.23 KB
/
index.ts
File metadata and controls
46 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as fs from "fs";
import * as ts from "typescript/lib/tsserverlibrary";
import { TailwindErrorChecker } from "./src/TailwindErrorChecker";
import { getTailwindConfigPath } from "./src/getTailwindConfigPath";
const factory: ts.server.PluginModuleFactory = () => ({
create({ project, languageService: parent }) {
const checker = new TailwindErrorChecker(project);
checker.loadCss();
fs.watch(getTailwindConfigPath(project), () => {
checker.loadCss();
});
return {
...parent,
getSemanticDiagnostics(fileName: string) {
const diagnostics = parent.getSemanticDiagnostics(fileName);
if (TailwindErrorChecker.isPending) {
return diagnostics;
}
const program = parent.getProgram();
if (!program) {
throw new Error("language service host does not have program!");
}
const source = program.getSourceFile(fileName);
if (!source) {
throw new Error("No source file: " + fileName);
}
const tailwindDiagnostics = checker.getTailwindDiagnostics(source);
return [...tailwindDiagnostics, ...diagnostics];
},
dispose() {
checker.stop();
},
};
},
});
export = factory;