1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const tsserverlibrary_1 = __importDefault(require("typescript/lib/tsserverlibrary"));
|
7 | const merge_deep_1 = __importDefault(require("merge-deep"));
|
8 | const utils_1 = require("./utils");
|
9 |
|
10 | const OPTIONS = {
|
11 | allowJs: true,
|
12 | checkJs: true,
|
13 | esModuleInterop: true,
|
14 | module: tsserverlibrary_1.default.ModuleKind.ESNext,
|
15 | moduleResolution: tsserverlibrary_1.default.ModuleResolutionKind.NodeJs,
|
16 | jsx: tsserverlibrary_1.default.JsxEmit.React,
|
17 | noEmit: true,
|
18 | strict: true,
|
19 | outDir: "$deno$",
|
20 | removeComments: true,
|
21 | stripComments: true,
|
22 | resolveJsonModule: true,
|
23 | sourceMap: true,
|
24 | target: tsserverlibrary_1.default.ScriptTarget.ESNext,
|
25 | typeRoots: [],
|
26 | };
|
27 | const OPTIONS_OVERWRITE_BY_DENO = {
|
28 | allowNonTsExtensions: false,
|
29 | jsx: OPTIONS.jsx,
|
30 | module: OPTIONS.module,
|
31 | moduleResolution: OPTIONS.moduleResolution,
|
32 | resolveJsonModule: OPTIONS.resolveJsonModule,
|
33 | strict: OPTIONS.strict,
|
34 | noEmit: OPTIONS.noEmit,
|
35 | noEmitHelpers: OPTIONS.noEmitHelpers,
|
36 | target: tsserverlibrary_1.default.ScriptTarget.ESNext,
|
37 | paths: {
|
38 | abc: ["./c.ts"],
|
39 | "abc.ts": ["./c.ts"],
|
40 | },
|
41 | };
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | class TypeScriptServiceHost {
|
49 | constructor(tsLsHost,
|
50 | // private readonly tsLS: ts_module.LanguageService,
|
51 | logger) {
|
52 | this.tsLsHost = tsLsHost;
|
53 | this.logger = logger;
|
54 | }
|
55 | getCompilationSettings() {
|
56 | this.logger.info("getCompilationSettings");
|
57 | const projectConfig = this.tsLsHost.getCompilationSettings();
|
58 | const compilationSettings = merge_deep_1.default(merge_deep_1.default(OPTIONS, projectConfig), OPTIONS_OVERWRITE_BY_DENO);
|
59 | compilationSettings.baseUrl = this.tsLsHost.getCurrentDirectory();
|
60 | this.logger.info(`compilationSettings:${JSON.stringify(compilationSettings)}`);
|
61 | return compilationSettings;
|
62 | }
|
63 | resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, options) {
|
64 | if (!this.tsLsHost.resolveModuleNames) {
|
65 | this.logger.info("resolveModuleNames is undefined.");
|
66 | return [];
|
67 | }
|
68 | this.logger.info("resolvedModule:\n" + JSON.stringify(moduleNames, null, " "));
|
69 | const resolvedModule = this.tsLsHost.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, options);
|
70 | return resolvedModule;
|
71 | }
|
72 | getScriptFileNames() {
|
73 | const scriptFileNames = this.tsLsHost.getScriptFileNames();
|
74 | const denoDtsPath = utils_1.getDenoDtsPath(this.tsLsHost, "lib.deno.d.ts");
|
75 | if (denoDtsPath) {
|
76 | scriptFileNames.push(denoDtsPath);
|
77 | }
|
78 | return scriptFileNames;
|
79 | }
|
80 |
|
81 | resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, options) {
|
82 | if (!this.tsLsHost.resolveTypeReferenceDirectives) {
|
83 | return [];
|
84 | }
|
85 | return this.tsLsHost.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, options);
|
86 | }
|
87 | }
|
88 | exports.TypeScriptServiceHost = TypeScriptServiceHost;
|
89 |
|
\ | No newline at end of file |