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

Commit

Permalink
feat: auto detect ./vscode/settings.json in typescript plugin #60
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Feb 24, 2020
1 parent 57647d9 commit 95d73c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion typescript-deno-plugin/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type DenoPluginConfig = {

export class ConfigurationManager {
private static readonly defaultConfiguration: DenoPluginConfig = {
enable: true,
enable: false,
dts_file: [],
import_map: ""
};
Expand Down
27 changes: 26 additions & 1 deletion typescript-deno-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from "path";
import * as fs from "fs";

import merge from "deepmerge";
import ts_module from "typescript/lib/tsserverlibrary";
Expand Down Expand Up @@ -54,10 +55,34 @@ export class DenoPlugin implements ts_module.server.PluginModule {
this.configurationManager.onUpdatedConfig(() => {
info.project.refreshDiagnostics();
info.project.updateGraph();
info.languageService.getProgram()?.emit();
});

this.logger = Logger.forPlugin(DenoPlugin.PLUGIN_NAME, info);

const vscodeSettingsFile = path.join(directory, ".vscode", "settings.json");

// Try to read configuration from vscode
if (pathExistsSync(vscodeSettingsFile) === true) {
const content = fs.readFileSync(vscodeSettingsFile, { encoding: "utf8" });

try {
const settings = JSON.parse(content);

const isEnable = !!settings["deno.enable"];
const dts_file = settings["deno.dts_file"] || [];
const import_map = settings["deno.import_map"] || undefined;

const configurationInProjectFolder = {
enable: isEnable,
dts_file,
import_map
};

this.configurationManager.update(configurationInProjectFolder);
} catch {}
}

this.logger.info(`Create typescript-deno-plugin`);
const getCompilationSettings = info.languageServiceHost.getCompilationSettings.bind(
info.languageServiceHost
Expand Down Expand Up @@ -115,7 +140,7 @@ export class DenoPlugin implements ts_module.server.PluginModule {
: path.resolve(info.project.getCurrentDirectory(), filepath);
return absoluteFilepath;
})
.filter(v => v.endsWith(".d.ts"));
.filter(v => v.endsWith(this.typescript.Extension.Dts));

const iterator = new Set(dtsFilepaths).entries();

Expand Down

0 comments on commit 95d73c6

Please sign in to comment.