Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit 240bc53

Browse files
authored
Deep merge (#12)
* set `printWidth` to 100 * deep merge both project and plugin's config * remove examples * release v1.2.5 * fix lint
1 parent 4f281e2 commit 240bc53

14 files changed

+156
-145
lines changed

.prettierrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"trailingComma": "all",
3+
"printWidth": 100,
4+
"overrides": [
5+
{
6+
"files": ".prettierrc",
7+
"options": { "parser": "json" }
8+
}
9+
]
10+
}

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.2.5 - 2019-06-05
4+
5+
- deep merge `compilerOptions` [#34](https://github.com/justjavac/vscode-deno/issues/34)
6+
37
## 1.2.2 - 1.2.3 - 2019-04-19
48

59
- fix typescript not found bug

examples/.vscode/settings.json

-5
This file was deleted.

examples/package.json

-10
This file was deleted.

examples/src/deno.ts

-9
This file was deleted.

examples/src/hello.ts

-1
This file was deleted.

examples/src/world.ts

-4
This file was deleted.

examples/tsconfig.json

-14
This file was deleted.

examples/yarn.lock

-70
This file was deleted.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-deno-plugin",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "Deno language service plugin for TypeScript",
55
"main": "out/index.js",
66
"scripts": {
@@ -19,6 +19,7 @@
1919
"url": "https://github.com/justjavac/typescript-deno-plugin.git"
2020
},
2121
"dependencies": {
22+
"merge-deep": "^3.0.2",
2223
"mock-require": "^3.0.3"
2324
},
2425
"devDependencies": {

src/index.ts

+28-30
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import * as fs from "fs";
33
import * as path from "path";
44

5-
import * as mockRequire from "mock-require";
6-
import * as ts_module from "typescript/lib/tsserverlibrary";
5+
import merge from "merge-deep";
6+
import mockRequire from "mock-require";
7+
import ts_module from "typescript/lib/tsserverlibrary";
78

89
import { Logger } from "./logger";
910
import { getDenoDir } from "./shared";
1011

1112
let logger: Logger;
1213

13-
export = function init({ typescript }: { typescript: typeof ts_module }) {
14+
module.exports = function init({ typescript }: { typescript: typeof ts_module }) {
1415
// Make sure Deno imports the correct version of TS
1516
mockRequire("typescript", typescript);
1617

@@ -27,7 +28,7 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
2728
resolveJsonModule: true,
2829
sourceMap: true,
2930
target: typescript.ScriptTarget.ESNext,
30-
typeRoots: []
31+
typeRoots: [],
3132
};
3233

3334
return {
@@ -47,36 +48,34 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
4748
moduleNames: string[],
4849
containingFile: string,
4950
reusedNames?: string[],
50-
redirectedReference?: ts_module.ResolvedProjectReference
51+
redirectedReference?: ts_module.ResolvedProjectReference,
5152
) => {
52-
moduleNames = moduleNames
53-
.map(stripExtNameDotTs)
54-
.map(convertRemoteToLocalCache);
53+
moduleNames = moduleNames.map(stripExtNameDotTs).map(convertRemoteToLocalCache);
5554

5655
return resolveModuleNames.call(
5756
info.languageServiceHost,
5857
moduleNames,
5958
containingFile,
6059
reusedNames,
61-
redirectedReference
60+
redirectedReference,
6261
);
6362
};
6463

65-
const projectSetting = info.project.getCompilationSettings();
64+
const getCompilationSettings = info.languageServiceHost.getCompilationSettings;
65+
6666
info.languageServiceHost.getCompilationSettings = () => {
67-
return { ...OPTIONS, ...projectSetting };
67+
const projectConfig = getCompilationSettings.call(info.languageServiceHost);
68+
const compilationSettings = merge(OPTIONS, projectConfig);
69+
logger.info(`compilationSettings:${JSON.stringify(compilationSettings)}`);
70+
return compilationSettings;
6871
};
6972

7073
const getScriptFileNames = info.languageServiceHost.getScriptFileNames!;
7174
info.languageServiceHost.getScriptFileNames = () => {
72-
const scriptFileNames = getScriptFileNames.call(
73-
info.languageServiceHost
74-
);
75+
const scriptFileNames = getScriptFileNames.call(info.languageServiceHost);
7576

7677
const denoDtsPath =
77-
getDtsPathForVscode(info) ||
78-
getGlobalDtsPath() ||
79-
getLocalDtsPath(info);
78+
getDtsPathForVscode(info) || getGlobalDtsPath() || getLocalDtsPath(info);
8079

8180
if (denoDtsPath) {
8281
scriptFileNames.push(denoDtsPath);
@@ -94,16 +93,16 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
9493
name: string,
9594
formatOptions?: ts_module.FormatCodeOptions | ts_module.FormatCodeSettings,
9695
source?: string,
97-
preferences?: ts_module.UserPreferences) => {
98-
96+
preferences?: ts_module.UserPreferences,
97+
) => {
9998
const details = getCompletionEntryDetails.call(
10099
info.languageService,
101100
fileName,
102101
position,
103102
name,
104103
formatOptions,
105104
source,
106-
preferences
105+
preferences,
107106
);
108107

109108
if (details) {
@@ -112,7 +111,10 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
112111
for (const change of ca.changes) {
113112
if (!change.isNewFile) {
114113
for (const tc of change.textChanges) {
115-
tc.newText = tc.newText.replace(/^(import .* from ['"])(\..*)(['"];\n)/i, "$1$2.ts$3");
114+
tc.newText = tc.newText.replace(
115+
/^(import .* from ['"])(\..*)(['"];\n)/i,
116+
"$1$2.ts$3",
117+
);
116118
}
117119
}
118120
}
@@ -128,7 +130,7 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
128130

129131
onConfigurationChanged(config: any) {
130132
logger.info(`onConfigurationChanged: ${JSON.stringify(config)}`);
131-
}
133+
},
132134
};
133135
};
134136

@@ -166,17 +168,15 @@ interface IDenoModuleHeaders {
166168
* If moduleName is not found, recursively search for headers and "redirect_to" property.
167169
*/
168170
function fallbackHeader(modulePath: string): string {
169-
const validPath = modulePath.endsWith(".ts")
170-
? modulePath
171-
: `${modulePath}.ts`;
171+
const validPath = modulePath.endsWith(".ts") ? modulePath : `${modulePath}.ts`;
172172
if (fs.existsSync(validPath)) {
173173
return modulePath;
174174
}
175175

176176
const headersPath = `${validPath}.headers.json`;
177177
if (fs.existsSync(headersPath)) {
178178
const headers: IDenoModuleHeaders = JSON.parse(
179-
fs.readFileSync(headersPath, { encoding: "utf-8" })
179+
fs.readFileSync(headersPath, { encoding: "utf-8" }),
180180
);
181181
logger.info(`redirect "${modulePath}" to "${headers.redirect_to}".`);
182182
// TODO: avoid Circular
@@ -185,9 +185,7 @@ function fallbackHeader(modulePath: string): string {
185185
return modulePath;
186186
}
187187

188-
function getDtsPathForVscode(
189-
info: ts_module.server.PluginCreateInfo
190-
): string | undefined {
188+
function getDtsPathForVscode(info: ts_module.server.PluginCreateInfo): string | undefined {
191189
const bundledDtsPath = info.config.dtsPath;
192190

193191
if (bundledDtsPath && fs.existsSync(bundledDtsPath)) {
@@ -214,7 +212,7 @@ function getLocalDtsPath(info: ts.server.PluginCreateInfo): string | undefined {
214212
"node_modules",
215213
"typescript-deno-plugin",
216214
"lib",
217-
"lib.deno_runtime.d.ts"
215+
"lib.deno_runtime.d.ts",
218216
);
219217

220218
if (fs.existsSync(localDtsPath)) {

tsconfig.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"noImplicitAny": true,
88
"noUnusedParameters": true,
99
"noUnusedLocals": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
1012
"lib": ["es6"],
1113
"strict": true,
1214
"baseUrl": "./src"
1315
},
14-
"include": ["./src/**/*.ts"]
16+
"include": ["./src/**/*.ts", "types/**/*.d.ts"]
1517
}

types/merge-deep.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "merge-deep" {
2+
export default function merge<T>(value1: T, value2: T): T;
3+
}

0 commit comments

Comments
 (0)