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

Commit

Permalink
feat: remove deno.enable & deno.disable command (#48)
Browse files Browse the repository at this point in the history
* feat: remove `deno.enable` and `deno.disable` command

* update

* docs: update readme
  • Loading branch information
axetroy authored Feb 14, 2020
1 parent e872d1c commit 8ecae2c
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 157 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ This extension also provides Deno's formatting tools, settings are in `.vscode/s

This extension contributes the following commands to the Command palette:

- `deno.enable` - Enable this extension.
- `deno.disable` - Disable this extension.
- `deno.restart_server` - Restart Deno Language Server.

## Contribute
Expand Down
146 changes: 11 additions & 135 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
ExtensionContext,
StatusBarAlignment,
TextEditor,
WorkspaceFolder,
QuickPickItem,
WorkspaceConfiguration,
Uri,
StatusBarItem,
Expand All @@ -29,27 +27,25 @@ import getport from "get-port";
import execa from "execa";
import { init, localize } from "vscode-nls-i18n";

import { pathExists } from "./util";

const TYPESCRIPT_EXTENSION_NAME = "vscode.typescript-language-features";
const TYPESCRIPT_DENO_PLUGIN_ID = "typescript-deno-plugin";

interface WorkspaceFolderItem extends QuickPickItem {
folder: WorkspaceFolder;
}

interface SynchronizedConfiguration {
type SynchronizedConfiguration = {
enable?: boolean;
dtsFilepaths?: string[];
import_map?: string;
}
};

interface TypescriptAPI {
type TypescriptAPI = {
configurePlugin(
pluginId: string,
configuration: SynchronizedConfiguration
): void;
}
};

interface DenoInfo {
type DenoInfo = {
DENO_DIR: string;
version: {
deno: string;
Expand All @@ -59,18 +55,11 @@ interface DenoInfo {
};
executablePath: string;
dtsFilepath: string;
}
};

interface ImportMap {
type ImportMap = {
imports: { [key: string]: string };
}

function exists(filepath: string): Promise<boolean> {
return fs
.stat(filepath)
.then(() => Promise.resolve(true))
.catch(() => Promise.resolve(false));
}
};

async function getImportMaps(importMapFilepath: string, workspaceDir: string) {
let importMaps: ImportMap = {
Expand All @@ -83,7 +72,7 @@ async function getImportMaps(importMapFilepath: string, workspaceDir: string) {
? importMapFilepath
: path.resolve(workspaceDir || process.cwd(), importMapFilepath);

if (await exists(importMapsFilepath)) {
if (await pathExists(importMapsFilepath)) {
const importMapContent = await fs.readFile(importMapsFilepath);

try {
Expand Down Expand Up @@ -113,30 +102,6 @@ function resolveModuleFromImportMap(
return moduleName;
}

async function pickFolder(
folders: WorkspaceFolder[],
placeHolder: string,
multipleWorkspaces: boolean
): Promise<WorkspaceFolder> {
if (!multipleWorkspaces && folders.length === 1) {
return folders[0];
}
const selected = await window.showQuickPick(
folders.map<WorkspaceFolderItem>(folder => {
return {
label: folder.name,
description: folder.uri.fsPath,
folder: folder
};
}),
{ placeHolder: placeHolder }
);
if (!selected) {
return undefined;
}
return selected.folder;
}

// get typescript api from build-in extension
// https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/src/api.ts
async function getTypescriptAPI(): Promise<TypescriptAPI> {
Expand Down Expand Up @@ -417,93 +382,6 @@ Executable ${this.denoInfo.executablePath}`;

this.statusBar.show();
}
// enable Deno Extension
private enable() {
const folders = workspace.workspaceFolders;

if (!folders) {
window.showWarningMessage(
"Deno can only be enabled if VS Code is opened on a workspace folder."
);
return;
}

const disabledFolders = folders.filter(
folder =>
!workspace
.getConfiguration(this.configurationSection, folder.uri)
.get("enable", true)
);

if (disabledFolders.length === 0) {
if (folders.length === 1) {
window.showInformationMessage(
"Deno is already enabled in the workspace."
);
} else {
window.showInformationMessage(
"Deno is already enabled on all workspace folders."
);
}
return;
}

pickFolder(
disabledFolders,
"Select a workspace folder to enable Deno for",
folders.length > 1
).then(folder => {
if (!folder) {
return;
}
workspace
.getConfiguration(this.configurationSection, folder.uri)
.update("enable", true);
});
}
// disable Deno Extension
private disable() {
const folders = workspace.workspaceFolders;

if (!folders) {
window.showErrorMessage(
"Deno can only be disabled if VS Code is opened on a workspace folder."
);
return;
}

const enabledFolders = folders.filter(folder =>
workspace
.getConfiguration(this.configurationSection, folder.uri)
.get("enable", true)
);

if (enabledFolders.length === 0) {
if (folders.length === 1) {
window.showInformationMessage(
"Deno is already disabled in the workspace."
);
} else {
window.showInformationMessage(
"Deno is already disabled on all workspace folders."
);
}
return;
}

pickFolder(
enabledFolders,
"Select a workspace folder to disable Deno for",
folders.length > 1
).then(folder => {
if (!folder) {
return;
}
workspace
.getConfiguration(this.configurationSection, folder.uri)
.update("enable", false);
});
}
// register quickly fix code action
private registerQuickFix(map: {
[command: string]: (
Expand Down Expand Up @@ -564,8 +442,6 @@ Executable ${this.denoInfo.executablePath}`;
})
);

this.registerCommand("enable", this.enable.bind(this));
this.registerCommand("disable", this.disable.bind(this));
this.registerCommand(
"restart_server",
this.StartDenoLanguageServer.bind(this)
Expand Down
17 changes: 17 additions & 0 deletions client/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { promises as fs, statSync } from "fs";

export function pathExistsSync(filepath: string) {
try {
return statSync(filepath);
} catch (err) {
return false;
}
}

export function pathExists(filepath: string) {
try {
return fs.stat(filepath);
} catch (err) {
return false;
}
}
2 changes: 0 additions & 2 deletions package.de-de.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"deno.displayName": "Deno",
"deno.description": "Deno unterstützung für VSCode",
"deno.command.enable": "Aktiviere Deno",
"deno.command.disable": "Deaktiviere Deno",
"deno.command.restart_server": "Starte den Deno Language Server neu",
"deno.config.enabled": "Steuert, ob Deno aktiviert ist oder nicht.\n\n**In der globalen Konfiguration nicht empfohlen**",
"deno.config.dtsFilepaths": "Der Dateipfad der Deno TypeScript-Deklarationsdatei (.d.ts).\n\nDies kann ein Pfad sein, der relativ zum Projektpfad ist, oder ein absoluter Pfad.\n\n**Wird in der globalen Konfiguration nicht empfohlen, ausser wenn Sie einen absoluten Pfad verwenden.**",
Expand Down
10 changes: 0 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@
}
],
"commands": [
{
"command": "deno.enable",
"title": "%deno.command.enable%",
"category": "deno"
},
{
"command": "deno.disable",
"title": "%deno.command.disable%",
"category": "deno"
},
{
"command": "deno.restart_server",
"title": "%deno.command.restart_server%",
Expand Down
2 changes: 0 additions & 2 deletions package.nl-nl.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"deno.displayName": "Deno",
"deno.description": "Deno ondersteuning voor VSCode",
"deno.command.enable": "Schakel Deno aan",
"deno.command.disable": "Schakel Deno uit",
"deno.command.restart_server": "Start Deno Language Server opnieuw",
"deno.config.enabled": "Bepaalt of Deno is ingeschakeld of niet.\n\n**Niet aanbevolen in globale configuratie**",
"deno.config.dtsFilepaths": "Het bestandspad van het Deno TypeScript-declaratiebestand (.d.ts).\n\nHet kan een pad zijn dat relatief is aan het projectpad, of een absoluut pad.\n\n**Niet aanbevolen in globale configuratie tenzij u een absoluut pad gebruikt.**",
Expand Down
2 changes: 0 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"deno.displayName": "Deno",
"deno.description": "Deno support for VSCode",
"deno.command.enable": "Enable Deno",
"deno.command.disable": "Disable Deno",
"deno.command.restart_server": "Restart Deno Language Server",
"deno.config.enabled": "Controls whether Deno is enabled or not.\n\n**Not recommended in global configuration**",
"deno.config.dtsFilepaths": "The file path of the Deno TypeScript declaration file (.d.ts).\n\nIt can be a path that is relative to the project root, or an absolute path.\n\n**Not recommended in global configuration unless you are using an absolute path.**",
Expand Down
2 changes: 0 additions & 2 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"deno.displayName": "Deno",
"deno.description": "Deno support for VSCode",
"deno.command.enable": "启用 Deno",
"deno.command.disable": "禁用 Deno",
"deno.command.restart_server": "重启 Deno 语言服务器",
"deno.config.enabled": "是否启用 Deno。\n\n**不推荐在全局配置中设置**",
"deno.config.dtsFilepaths": "Typescript 的声明文件(.d.ts)路径。\n\n它可以是相对于项目目录的相对路径或者是绝对路径。\n\n**不推荐在全局配置中设置**",
Expand Down
2 changes: 0 additions & 2 deletions package.nls.zh-tw.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"deno.displayName": "Deno",
"deno.description": "Deno support for VSCode",
"deno.command.enable": "啟用 Deno",
"deno.command.disable": "禁用 Deno",
"deno.command.restart_server": "重啟 Deno 語言服務器",
"deno.config.enabled": "是否啟用 Deno。\n\n**不推薦在全局配置中設置**",
"deno.config.dtsFilepaths": "Typescript 的聲明文件(.d.ts)路徑。\n\n它可以是相對於項目目錄的相對路徑或者是絕對路徑。\n\n**不推薦在全局配置中設置**",
Expand Down

0 comments on commit 8ecae2c

Please sign in to comment.