-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathbuilding.ts
43 lines (38 loc) · 1.59 KB
/
building.ts
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
import project = require('../core/project');
import mkdirp = require('mkdirp');
import path = require('path');
import fs = require('fs');
import {makeAbsoluteIfNeeded} from "../../../disk/workingDir";
import {consistentPath} from "../../../utils/fsu";
import { createMap } from "../../../../common/utils";
import * as types from '../../../../common/types';
export function diagnosticToCodeError(diagnostic: ts.Diagnostic): types.CodeError {
let preview = '';
let filePath = '';
let startPosition = { line: 0, character: 0 };
let endPosition = { line: 0, character: 0 };
if (diagnostic.file) {
filePath = diagnostic.file.fileName;
startPosition = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
endPosition = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start + diagnostic.length);
preview = diagnostic.file.text.substr(diagnostic.start, diagnostic.length)
}
return {
source: 'projectService',
filePath,
from: { line: startPosition.line, ch: startPosition.character },
to: { line: endPosition.line, ch: endPosition.character },
message: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
preview,
level: 'error'
};
}
/**
* Raw signifies the fact that the output is not being written anywhere
* WARNING: only call if proj contains the filePath
*/
export function getRawOutput(proj: project.Project, filePath: string): ts.EmitOutput {
let services = proj.languageService;
let output: ts.EmitOutput = services.getEmitOutput(filePath);
return output;
}