UNPKG

alm

Version:

The best IDE for TypeScript

58 lines (57 loc) 2.66 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var lsh = require("./languageServiceHost"); var typescriptDir = require("../server/workers/lang/core/typeScriptDir"); var fs = require("fs"); /** * Similar to the base, just adds stuff that uses `require.resolve` to load lib.d.ts */ var LanguageServiceHost = /** @class */ (function (_super) { __extends(LanguageServiceHost, _super); function LanguageServiceHost() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.getDefaultLibFileName = function () { /** TypeScript doesn't handle `undefined` here gracefully, but it handles an empty string just fine */ return typescriptDir.getDefaultLibFilePaths(_this.compilerOptions)[0] || ''; }; /** alm demo service */ _this.addAlmDemo = function () { _this.addScript('alm.d.ts', fs.readFileSync(__dirname + '/alm.d.ts').toString()); return _this; }; return _this; } LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) { var snap = _super.prototype.getScriptSnapshot.call(this, fileName); if (!snap) { // This script should be a part of the project if it exists // But we only do this in the server if (typeof process !== "undefined" && typeof require !== "undefined") { if (require('fs').existsSync(fileName)) { try { /** Just because the file exists doesn't mean we can *read* it. Hence the try */ var contents = require('fs').readFileSync(fileName, 'utf8'); this.addScript(fileName, contents); snap = _super.prototype.getScriptSnapshot.call(this, fileName); this.incrementallyAddedFile.emit({ filePath: fileName }); } catch (e) { } } } } return snap; }; return LanguageServiceHost; }(lsh.LanguageServiceHost)); exports.LanguageServiceHost = LanguageServiceHost;