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

Commit fc2c197

Browse files
committed
feat: enable/disable typescript-deno-plugin in extension scope
1 parent 56d1be0 commit fc2c197

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/extension.ts

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ function synchronizeConfiguration(api: TypescriptAPI) {
160160
config.dtsPath = getDenoDtsFilepath();
161161
}
162162

163+
if ("enable" in config === false) {
164+
config.enable = true;
165+
}
166+
163167
api.configurePlugin(pluginId, config);
164168
}
165169

typescript-deno-plugin/src/index.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ function existsSync(filepath: string) {
1818
}
1919
}
2020

21+
interface IConfig {
22+
enable: boolean;
23+
dtsFilepath?: string;
24+
}
25+
26+
let config: IConfig = {
27+
enable: true
28+
};
29+
2130
module.exports = function init({
2231
typescript
2332
}: {
@@ -65,6 +74,15 @@ module.exports = function init({
6574
reusedNames?: string[],
6675
redirectedReference?: ts_module.ResolvedProjectReference
6776
) => {
77+
if (!config.enable) {
78+
return resolveModuleNames(
79+
moduleNames,
80+
containingFile,
81+
reusedNames,
82+
redirectedReference,
83+
{}
84+
);
85+
}
6886
moduleNames = moduleNames
6987
.map(stripExtNameDotTs)
7088
.map(convertRemoteToLocalCache);
@@ -81,6 +99,10 @@ module.exports = function init({
8199
info.languageServiceHost.getCompilationSettings = () => {
82100
const projectConfig = getCompilationSettings();
83101

102+
if (!config.enable) {
103+
return projectConfig;
104+
}
105+
84106
// Solve the problem that `import.meta.url` is not parsed correctly
85107
const mustOverwriteOptions: ts_module.CompilerOptions = {
86108
module: OPTIONS.module,
@@ -101,6 +123,10 @@ module.exports = function init({
101123
info.languageServiceHost.getScriptFileNames = () => {
102124
const scriptFileNames = getScriptFileNames();
103125

126+
if (!config.enable) {
127+
return scriptFileNames;
128+
}
129+
104130
const denoDtsPath = getDtsPathForVscode(info) || getGlobalDtsPath();
105131

106132
if (denoDtsPath) {
@@ -131,6 +157,10 @@ module.exports = function init({
131157
preferences
132158
);
133159

160+
if (!config.enable) {
161+
return details;
162+
}
163+
134164
if (details) {
135165
if (details.codeActions && details.codeActions.length) {
136166
for (const ca of details.codeActions) {
@@ -154,8 +184,9 @@ module.exports = function init({
154184
return info.languageService;
155185
},
156186

157-
onConfigurationChanged(config: any) {
158-
logger.info(`onConfigurationChanged: ${JSON.stringify(config)}`);
187+
onConfigurationChanged(c: IConfig) {
188+
config = merge(config, c);
189+
logger.info(`onConfigurationChanged: ${JSON.stringify(c)}`);
159190
}
160191
};
161192
};

0 commit comments

Comments
 (0)