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

Commit

Permalink
feat: fully i18n supported. #31
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Feb 6, 2020
1 parent b67ff06 commit 04e3938
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 80 deletions.
81 changes: 45 additions & 36 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from "vscode-languageclient";
import getport from "get-port";
import execa from "execa";
import { init, localize } from "vscode-nls-i18n";

const TYPESCRIPT_EXTENSION_NAME = "vscode.typescript-language-features";
const TYPESCRIPT_DENO_PLUGIN_ID = "typescript-deno-plugin";
Expand Down Expand Up @@ -60,7 +61,7 @@ interface DenoInfo {
}

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

function exists(filepath: string): Promise<boolean> {
Expand All @@ -86,7 +87,8 @@ async function getImportMaps(importMapFilepath: string, workspaceDir: string) {

try {
importMaps = JSON.parse(importMapContent.toString() || "{}");
} catch {}
} catch {
}
}
}

Expand Down Expand Up @@ -197,8 +199,7 @@ class Extension {
return;
}

outConfig[key] =
configSetting.workspaceFolderValue ??
outConfig[key] = configSetting.workspaceFolderValue ??
configSetting.workspaceValue ??
configSetting.globalValue;
}
Expand Down Expand Up @@ -254,8 +255,11 @@ class Extension {
await this.client.stop();
this.client = null;
}
const statusbar = window.createStatusBarItem(StatusBarAlignment.Left, -100);
statusbar.text = "$(loading) Initializing Deno Language Server";
const statusbar = window.createStatusBarItem(
StatusBarAlignment.Left,
-100
);
statusbar.text = `$(loading) ${localize("deno.initializing")}`;
statusbar.show();

try {
Expand All @@ -273,14 +277,24 @@ class Extension {
run: {
module: serverModule,
transport: TransportKind.ipc,
options: { cwd: process.cwd() }
options: {
cwd: process.cwd(),
env: {
VSCODE_DENO_EXTENSION_PATH_PATH: this.context.extensionPath,
VSCODE_NLS_CONFIG: process.env.VSCODE_NLS_CONFIG
}
}
},
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: {
cwd: process.cwd(),
execArgv: ["--nolazy", `--inspect=${port}`]
execArgv: ["--nolazy", `--inspect=${port}`],
env: {
VSCODE_DENO_EXTENSION_PATH_PATH: this.context.extensionPath,
VSCODE_NLS_CONFIG: process.env.VSCODE_NLS_CONFIG
}
}
}
};
Expand Down Expand Up @@ -341,8 +355,9 @@ class Extension {
});
client.onNotification("error", window.showErrorMessage);

client.onRequest("getWorkspaceFolder", async (uri: string) =>
workspace.getWorkspaceFolder(Uri.parse(uri))
client.onRequest(
"getWorkspaceFolder",
async (uri: string) => workspace.getWorkspaceFolder(Uri.parse(uri))
);

client.onRequest("getWorkspaceConfig", async (uri: string) => {
Expand Down Expand Up @@ -401,8 +416,7 @@ class Extension {
this.statusBar.tooltip = `Deno ${this.denoInfo.version.deno}
TypeScript ${this.denoInfo.version.typescript}
V8 ${this.denoInfo.version.v8}
Executable ${this.denoInfo.executablePath}
`;
Executable ${this.denoInfo.executablePath}`;

this.statusBar.show();
}
Expand All @@ -418,10 +432,9 @@ Executable ${this.denoInfo.executablePath}
}

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

if (disabledFolders.length === 0) {
Expand Down Expand Up @@ -461,11 +474,9 @@ Executable ${this.denoInfo.executablePath}
return;
}

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

if (enabledFolders.length === 0) {
if (folders.length === 1) {
Expand Down Expand Up @@ -495,11 +506,8 @@ Executable ${this.denoInfo.executablePath}
}
// register quickly fix code action
private registerQuickFix(map: {
[command: string]: (
editor: TextEditor,
text: string,
range: Range
) => void | Promise<void>;
[command: string]: (editor: TextEditor, text: string, range: Range) => void
| Promise<void>;
}) {
for (let command in map) {
const handler = map[command];
Expand Down Expand Up @@ -529,6 +537,7 @@ Executable ${this.denoInfo.executablePath}
}
// activate function for vscode
public async activate(context: ExtensionContext) {
init(context.extensionPath);
this.context = context;
this.tsAPI = await getTypescriptAPI();

Expand Down Expand Up @@ -609,7 +618,8 @@ Executable ${this.denoInfo.executablePath}

if (extName === "") {
this.output.appendLine(
`Cannot create module \`${text}\` without specifying extension name`
`Cannot create module \`${text
}\` without specifying extension name`
);
this.output.show();
return;
Expand Down Expand Up @@ -639,15 +649,13 @@ Executable ${this.denoInfo.executablePath}
this.updateDiagnostic(editor.document.uri);
},
_lock_std_version: (editor, text, range) => {
editor.edit(e =>
e.replace(
range,
text.replace(
"https://deno.land/std/",
`https://deno.land/std@v${this.denoInfo.version.deno}/`
)
editor.edit(e => e.replace(
range,
text.replace(
"https://deno.land/std/",
`https://deno.land/std@v${this.denoInfo.version.deno}/`
)
);
));
}
});

Expand Down Expand Up @@ -680,7 +688,8 @@ Executable ${this.denoInfo.executablePath}

await this.StartDenoLanguageServer();

console.log(`Congratulations, your extension "vscode-deno" is now active!`);
console
.log(`Congratulations, your extension "vscode-deno" is now active!`);
}
// deactivate function for vscode
public async deactivate(context: ExtensionContext) {
Expand Down
32 changes: 25 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
"engines": {
"vscode": "^1.41.0"
},
"categories": ["Programming Languages", "Other"],
"keywords": ["deno"],
"categories": [
"Programming Languages",
"Other"
],
"keywords": [
"deno"
],
"activationEvents": [
"onLanguage:typescript",
"onLanguage:typescriptreact",
Expand Down Expand Up @@ -62,7 +67,10 @@
"default": false,
"markdownDescription": "%deno.config.enabled%",
"scope": "resource",
"examples": [true, false]
"examples": [
true,
false
]
},
"deno.dtsFilepaths": {
"type": "array",
Expand All @@ -72,13 +80,19 @@
"default": [],
"markdownDescription": "%deno.config.dtsFilepaths%",
"scope": "resource",
"examples": ["./deno.d.ts", "/absolute/path/to/deno.d.ts"]
"examples": [
"./deno.d.ts",
"/absolute/path/to/deno.d.ts"
]
},
"deno.import_map": {
"type": "string",
"markdownDescription": "%deno.config.import_map%",
"scope": "resource",
"examples": ["./import_map.json", "/absolute/path/to/import_map.json"]
"examples": [
"./import_map.json",
"/absolute/path/to/import_map.json"
]
}
}
}
Expand All @@ -98,7 +112,10 @@
}
},
"lint-staged": {
"**/*.{js,ts,json,md}": ["yarn format", "git add"]
"**/*.{js,ts,json,md}": [
"yarn format",
"git add"
]
},
"devDependencies": {
"@types/node": "12.12.26",
Expand All @@ -109,6 +126,7 @@
},
"dependencies": {
"deepmerge": "^4.2.2",
"typescript-deno-plugin": "./typescript-deno-plugin"
"typescript-deno-plugin": "./typescript-deno-plugin",
"vscode-nls-i18n": "^0.2.0"
}
}
15 changes: 13 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
"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.enabled": "Controls whether Deno is enabled or not.\n\n**Not recommended in global configuration**",
"deno.config.dtsFilepaths": "The file paths of the TypeScript declaration file(.d.ts).\n\nIt can be a relative which path relative to the project directory or an absolute path.\n\n**Not recommended in global configuration**",
"deno.config.import_map": "The file paths of Import Map.\n\nIt can be a relative which path relative to the project directory or an absolute path.\n\n**Not recommended in global configuration**"
"deno.config.import_map": "The file paths of Import Map.\n\nIt can be a relative which path relative to the project directory or an absolute path.\n\n**Not recommended in global configuration**",
"deno.initializing": "Initializing Deno Language Server...",
"err.not_install_deno": "Can not found deno in $PATH. Please restart the extension after setting.",
"diagnostic.fix.add_ext_name": "Add `.ts` extension.",
"diagnostic.fix.use_HTTPS_module": "Use HTTPS module.",
"diagnostic.fix.create_module": "Create module.",
"diagnostic.fix.fetch_module": "Fetch module.",
"diagnostic.fix.lock_std_version": "Lock Deno standard library version.",
"diagnostic.report.mssing_ext_name": "Please specify valid extension name of the imported module.",
"diagnostic.report.use_HTTPS_module": "For security, we recommend using the HTTPS module.",
"diagnostic.report.lock_std_version": "We recommend you use a locked Deno standard library version.",
"diagnostic.report.can_not_found_module": "Cannot found module `{0}`."
}
13 changes: 12 additions & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@
"deno.command.restart_server": "重启 Deno 语言服务器",
"deno.config.enabled": "是否启用 Deno。\n\n**不推荐在全局配置中设置**",
"deno.config.dtsFilepaths": "Typescript 的声明文件(.d.ts)路径。\n\n它可以是相对于项目目录的相对路径或者是绝对路径。\n\n**不推荐在全局配置中设置**",
"deno.config.import_map": "Import Map 的文件路径。\n\n它可以是相对于项目目录的相对路径或者是绝对路径。\n\n**不推荐在全局配置中设置**"
"deno.config.import_map": "Import Map 的文件路径。\n\n它可以是相对于项目目录的相对路径或者是绝对路径。\n\n**不推荐在全局配置中设置**",
"deno.initializing": "正在初始化 Deno 语言服务器...",
"err.not_install_deno": "在 $PATH 变量中找不到 Deno。请在设置后重新启动扩展。",
"diagnostic.fix.add_ext_name": "添加 `.ts` 扩展名。",
"diagnostic.fix.use_HTTPS_module": "使用 HTTPS 模块。",
"diagnostic.fix.create_module": "创建模块。",
"diagnostic.fix.fetch_module": "拉取模块。",
"diagnostic.fix.lock_std_version": "锁定 Deno 标准库版本号。",
"diagnostic.report.mssing_ext_name": "请指定合法的文件扩展名。",
"diagnostic.report.use_HTTPS_module": "出于安全考虑, 我们推荐您使用 HTTPS 模块。",
"diagnostic.report.lock_std_version": "我们推荐您锁定 Deno 标准库版本号。",
"diagnostic.report.can_not_found_module": "找不到模块 `{0}`。"
}
13 changes: 12 additions & 1 deletion package.nls.zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@
"deno.command.restart_server": "重啟 Deno 語言服務器",
"deno.config.enabled": "是否啟用 Deno。\n\n**不推薦在全局配置中設置**",
"deno.config.dtsFilepaths": "Typescript 的聲明文件(.d.ts)路徑。\n\n它可以是相對於項目目錄的相對路徑或者是絕對路徑。\n\n**不推薦在全局配置中設置**",
"deno.config.import_map": "Import Map 的文件路徑。\n\n它可以是相對於項目目錄的相對路徑或者是絕對路徑。\n\n**不推薦在全局配置中設置**"
"deno.config.import_map": "Import Map 的文件路徑。\n\n它可以是相對於項目目錄的相對路徑或者是絕對路徑。\n\n**不推薦在全局配置中設置**",
"deno.initializing": "正在初始化 Deno 語言服務器...",
"err.not_install_deno": "在 $PATH 變量中找不到 Deno。請在設置後重新啟動擴展。",
"diagnostic.fix.add_ext_name": "添加 `.ts` 擴展名。",
"diagnostic.fix.use_HTTPS_module": "使用 HTTPS 模塊。",
"diagnostic.fix.create_module": "创建模块。",
"diagnostic.fix.fetch_module": "創建模塊。",
"diagnostic.fix.lock_std_version": "鎖定 Deno 標準庫版本號。",
"diagnostic.report.mssing_ext_name": "請指定合法的文件擴展名。",
"diagnostic.report.use_HTTPS_module": "出於安全考慮, 我們推薦您使用 HTTPS 模塊。",
"diagnostic.report.lock_std_version": "我們推薦您鎖定 Deno 標準庫版本號。",
"diagnostic.report.can_not_found_module": "找不到模塊 `{0}`。"
}
24 changes: 10 additions & 14 deletions server/src/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { promises as fs } from "fs";
import * as ts from "typescript";
import execa from "execa";
import which from "which";
import { localize } from "vscode-nls-i18n";

interface Version {
deno: string;
Expand All @@ -20,11 +21,10 @@ interface DenoModule {
}

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

export type FormatableLanguages =
| "typescript"
export type FormatableLanguages = "typescript"
| "typescriptreact"
| "javascript"
| "javascriptreact"
Expand Down Expand Up @@ -55,9 +55,7 @@ class Deno {
this.executablePath = await this.getExecutablePath();

if (!this.executablePath) {
throw new Error(
"Can not found deno in $PATH. Please restart the extension after setting."
);
throw new Error(localize("err.not_install_deno"));
}

this.version = await this.getDenoVersion();
Expand Down Expand Up @@ -193,7 +191,8 @@ class Deno {

try {
importMaps = JSON.parse(importMapContent || "{}");
} catch {}
} catch {
}
}
}

Expand Down Expand Up @@ -252,12 +251,10 @@ class Deno {
}
}
}
}
// absolute filepath
} // absolute filepath
else if (moduleName.indexOf("/") === 0) {
moduleName = moduleName;
}
// relative filepath
} // relative filepath
else {
moduleName = this.resolveModuleFromImportMap(importMaps, moduleName);

Expand Down Expand Up @@ -298,9 +295,8 @@ class Deno {
return denoDir;
}
private async getExecutablePath(): Promise<string | undefined> {
const denoPath = await which("deno").catch(() =>
Promise.resolve(undefined)
);
const denoPath = await which("deno")
.catch(() => Promise.resolve(undefined));

return denoPath;
}
Expand Down
Loading

0 comments on commit 04e3938

Please sign in to comment.