UNPKG

778 BPlain TextView Raw
1import { tsUtils } from '@neo-one/ts-utils';
2import ts from 'typescript';
3import { compileForDiagnostics } from './compile';
4import { createContextForLanguageService } from './createContext';
5
6export const getSemanticDiagnostics = ({
7 filePath,
8 smartContractDir,
9 languageService,
10}: {
11 readonly filePath: string;
12 readonly smartContractDir: string;
13 readonly languageService: ts.LanguageService;
14}): ReadonlyArray<ts.Diagnostic> => {
15 const context = createContextForLanguageService(languageService, smartContractDir);
16 try {
17 compileForDiagnostics({
18 sourceFile: tsUtils.file.getSourceFileOrThrow(context.program, filePath),
19 context,
20 sourceMaps: {},
21 });
22 } catch {
23 // do nothing, should never happen
24 }
25
26 return context.diagnostics;
27};