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