Skip to content

Commit

Permalink
Extension name changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mustafa Kuru committed Mar 14, 2022
1 parent 33a8128 commit 02a9990
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 52 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Akinon CodeLens
# i18n CodeLens

Akinon CodeLens makes it easy to find missing language resources, provides various Code Actions, Hover Information, and tips for you to add or edit the language resources.
i18n CodeLens makes it easy to find missing language resources, provides various Code Actions, Hover Information, and tips for you to add or edit the language resources.

It can be made to work in various projects by changing the regex information and glob pattern.




# Extension link
VS Code Extension: [Akinon CodeLens](https://marketplace.visualstudio.com/items?itemName=mustafa-kuru.akinon-codelens)


## Demo
![Demo](/demo.gif)

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "akinon-codelens",
"displayName": "Akinon CodeLens",
"description": "Akinon CodeLens makes it easy to find missing language resources, provides various Code Actions, Hover Information, and tips for you to add or edit the language resources.",
"name": "i18n-codelens",
"displayName": "i18n CodeLens",
"description": "i18n CodeLens makes it easy to find missing language resources, provides various Code Actions, Hover Information, and tips for you to add or edit the language resources.",
"version": "1.0.0",
"publisher": "mustafa-kuru",
"author": {
Expand All @@ -18,7 +18,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/hepter/akinon-codelens"
"url": "https://github.com/hepter/i18n-codelens"
},
"activationEvents": [
"onLanguage:typescript",
Expand All @@ -31,49 +31,49 @@
"commands": [
{
"title": "Enable CodeLens",
"command": "akinon-codelens.enableCodeLens",
"category": "Akinon CodeLens"
"command": "i18n-codelens.enableCodeLens",
"category": "i18n CodeLens"
},
{
"title": "Disable Codelens",
"command": "akinon-codelens.disableCodeLens",
"category": "Akinon CodeLens"
"command": "i18n-codelens.disableCodeLens",
"category": "i18n CodeLens"
},
{
"title": "Refresh Language Resources",
"command": "akinon-codelens.refreshLanguageResources",
"category": "Akinon CodeLens"
"command": "i18n-codelens.refreshLanguageResources",
"category": "i18n CodeLens"
}
],
"configuration": {
"properties": {
"akinon-codelens.enableCodeLens": {
"i18n-codelens.enableCodeLens": {
"type": "boolean",
"default": true,
"description": "Enable or disable the CodeLens for missing resource code."
},
"akinon-codelens.enableResourceAutoSaveInsertOrUpdate": {
"i18n-codelens.enableResourceAutoSaveInsertOrUpdate": {
"type": "boolean",
"default": true,
"description": "Enable auto save for resource file(s) that saves files after inserted or updated resource data."
},
"akinon-codelens.enableUnderlineResourceDecorator": {
"i18n-codelens.enableUnderlineResourceDecorator": {
"type": "boolean",
"default": true,
"description": "Enable or disable the underline decorator for missing resource code(s)."
},
"akinon-codelens.enableAutoFocusDocumentAfterAltered": {
"i18n-codelens.enableAutoFocusDocumentAfterAltered": {
"type": "boolean",
"default": false,
"description": "Enable auto focus document after inserted or updated target resource file(s)."
},
"akinon-codelens.languageGlobPattern": {
"i18n-codelens.languageGlobPattern": {
"type": "string",
"description": "Language file glob patterns. (Language resource files must be key value object files.)",
"editPresentation": "singlelineText",
"default": "**/locales/*.json"
},
"akinon-codelens.languageTranslatorRegex": {
"i18n-codelens.languageTranslatorRegex": {
"type": "string",
"description": "Regex to detect hover or codeLenses for Language",
"editPresentation": "singlelineText",
Expand Down
6 changes: 3 additions & 3 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const generateLanguageResource = (fsPath: string) => {
export async function getLanguageResourcesFiles(clearCache = false, fileFsPath?: string): Promise<LanguageResource> {

const response: LanguageResource = [];
const globPattern = vscode.workspace.getConfiguration("akinon-codelens").get("languageGlobPattern", "**/locales/*.json");
const globPattern = vscode.workspace.getConfiguration("i18n-codelens").get("languageGlobPattern", "**/locales/*.json");
if (languageResourcesFilesCache?.length && !clearCache) {
return languageResourcesFilesCache;
}
Expand Down Expand Up @@ -77,8 +77,8 @@ async function applyEditByFilePath(filePath: string, nearestResourceKey: string,
const lineRegex = /([\t ]*?)(["']).*?(,?)(\r?\n)/;// 4 RegExp groups
const resourceLineRegex = new RegExp(`(?<=["'])${nearestResourceKey}(?=["']).*\r?(?:\n|$)`);
const matchGroups = rawData.match(lineRegex);
const isAutoSaveEnabled = vscode.workspace.getConfiguration("akinon-codelens").get("enableResourceAutoSaveInsertOrUpdate", true);
const isAutoFocusEnabled = vscode.workspace.getConfiguration("akinon-codelens").get("enableAutoFocusDocumentAfterAltered", false);
const isAutoSaveEnabled = vscode.workspace.getConfiguration("i18n-codelens").get("enableResourceAutoSaveInsertOrUpdate", true);
const isAutoFocusEnabled = vscode.workspace.getConfiguration("i18n-codelens").get("enableAutoFocusDocumentAfterAltered", false);

let newLine = `\n "${resourceKey}": "${resourceData}",`;
if (matchGroups?.length == 5) { // 4 groups + 1 for the whole match
Expand Down
2 changes: 1 addition & 1 deletion src/actions/ActionEnableDisableCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
import { workspace } from 'vscode';

export default (actionStatus: boolean) => () => {
workspace.getConfiguration("akinon-codelens").update("enableCodeLens", actionStatus, true);
workspace.getConfiguration("i18n-codelens").update("enableCodeLens", actionStatus, true);
};
8 changes: 4 additions & 4 deletions src/codeAction/ResourceEditCodeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export class ResourceEditCodeAction implements vscode.CodeActionProvider {
constructor(context: vscode.ExtensionContext) {
this.refreshRegexFromConfig();
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("akinon-codelens.languageTranslatorRegex")) {
if (e.affectsConfiguration("i18n-codelens.languageTranslatorRegex")) {
this.refreshRegexFromConfig();
}
}, null, context.subscriptions);
}

private refreshRegexFromConfig() {
const hoverRegex = vscode.workspace.getConfiguration("akinon-codelens").get("languageTranslatorRegex", "");
const hoverRegex = vscode.workspace.getConfiguration("i18n-codelens").get("languageTranslatorRegex", "");
this.regex = new RegExp(hoverRegex, "g");
}

Expand Down Expand Up @@ -51,7 +51,7 @@ export class ResourceEditCodeAction implements vscode.CodeActionProvider {
const actionAdd = new vscode.CodeAction(titleAdd, vscode.CodeActionKind.Refactor);
actionAdd.command = {
title: titleAdd,
command: "akinon-codelens.codelensActionAddLanguageResource",
command: "i18n-codelens.codelensActionAddLanguageResource",
tooltip: 'This will open the input-box for every target language.',
arguments: [resourceKey]
};
Expand All @@ -63,7 +63,7 @@ export class ResourceEditCodeAction implements vscode.CodeActionProvider {
const actionEdit = new vscode.CodeAction(titleEdit, vscode.CodeActionKind.Refactor);
actionEdit.command = {
title: titleEdit,
command: "akinon-codelens.codeActionEditLanguageResource",
command: "i18n-codelens.codeActionEditLanguageResource",
tooltip: 'This will open the input-box for every target language.',
arguments: [resourceKey]
};
Expand Down
12 changes: 6 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export function activate(context: ExtensionContext) {
disposables.push(languages.registerCodeActionsProvider(['javascript', 'typescript'], codeActionsProvider));


disposables.push(commands.registerCommand("akinon-codelens.enableCodeLens", ActionEnableDisableCodeLens(true)));
disposables.push(commands.registerCommand("akinon-codelens.disableCodeLens", ActionEnableDisableCodeLens(false)));
disposables.push(commands.registerCommand("akinon-codelens.refreshLanguageResources", ActionRefreshLanguageResource));
disposables.push(commands.registerCommand("akinon-codelens.codelensActionAddLanguageResource", ActionAddLanguageResource, ''));
disposables.push(commands.registerCommand("akinon-codelens.codeActionEditLanguageResource", ActionEditLanguageResource, ''));
disposables.push(commands.registerCommand("i18n-codelens.enableCodeLens", ActionEnableDisableCodeLens(true)));
disposables.push(commands.registerCommand("i18n-codelens.disableCodeLens", ActionEnableDisableCodeLens(false)));
disposables.push(commands.registerCommand("i18n-codelens.refreshLanguageResources", ActionRefreshLanguageResource));
disposables.push(commands.registerCommand("i18n-codelens.codelensActionAddLanguageResource", ActionAddLanguageResource, ''));
disposables.push(commands.registerCommand("i18n-codelens.codeActionEditLanguageResource", ActionEditLanguageResource, ''));



context.subscriptions.push(...disposables);

new DecoratorProvider(context);

console.log('Congratulations, extension "akinon-codelens" is now active!');
console.log('Congratulations, extension "i18n-codelens" is now active!');
}

// this method is called when your extension is deactivated
Expand Down
10 changes: 5 additions & 5 deletions src/providers/CodelensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ export class CodelensProvider implements vscode.CodeLensProvider {

vscode.workspace.onDidChangeConfiguration((e) => {
this._onDidChangeCodeLenses.fire();
if (e.affectsConfiguration("akinon-codelens.languageTranslatorRegex")) {
if (e.affectsConfiguration("i18n-codelens.languageTranslatorRegex")) {
this.refreshRegexFromConfig();
}
}, null, context.subscriptions);
}

private refreshRegexFromConfig() {
const hoverRegex = vscode.workspace.getConfiguration("akinon-codelens").get("languageTranslatorRegex", "");
const hoverRegex = vscode.workspace.getConfiguration("i18n-codelens").get("languageTranslatorRegex", "");
this.regex = new RegExp(hoverRegex, "g");
}
public provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {

if (vscode.workspace.getConfiguration("akinon-codelens").get("enableCodeLens", true)) {
if (vscode.workspace.getConfiguration("i18n-codelens").get("enableCodeLens", true)) {
return getLanguageResourcesFiles().then((languageResources) => {

this.codeLenses = [];
Expand Down Expand Up @@ -70,11 +70,11 @@ export class CodelensProvider implements vscode.CodeLensProvider {

const codeLensState = this.codeLensKeyWeakMap.get(codeLens);

if (vscode.workspace.getConfiguration("akinon-codelens").get("enableCodeLens", true)) {
if (vscode.workspace.getConfiguration("i18n-codelens").get("enableCodeLens", true)) {
codeLens.command = {
title: `Missing translation key! ('${codeLensState!.languageKey}')`,
tooltip: `Add missing language translations key ('${codeLensState!.languageKey}' -> ${codeLensState!.missingTranslationList.join(', ')})`,
command: "akinon-codelens.codelensActionAddLanguageResource",
command: "i18n-codelens.codelensActionAddLanguageResource",
arguments: [codeLensState!.languageKey, codeLensState!.missingTranslationList]
};

Expand Down
6 changes: 3 additions & 3 deletions src/providers/CompletionItemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export default class CompletionItemProvider implements vscode.CompletionItemProv

this.refreshRegexFromConfig();
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("akinon-codelens.languageTranslatorRegex")) {
if (e.affectsConfiguration("i18n-codelens.languageTranslatorRegex")) {
this.refreshRegexFromConfig();
}
}, null, context.subscriptions);
this.refreshResourceList();

const resourceGlobPattern = vscode.workspace.getConfiguration("akinon-codelens").get("languageGlobPattern", "**/locales/*.json");
const resourceGlobPattern = vscode.workspace.getConfiguration("i18n-codelens").get("languageGlobPattern", "**/locales/*.json");
const watcher = vscode.workspace.createFileSystemWatcher(resourceGlobPattern, false, false, true);
watcher.onDidChange((e) => {
this.refreshResourceList();
Expand All @@ -28,7 +28,7 @@ export default class CompletionItemProvider implements vscode.CompletionItemProv
this.resourceList = resources;
}
private refreshRegexFromConfig() {
const hoverRegex = vscode.workspace.getConfiguration("akinon-codelens").get("languageTranslatorRegex", "");
const hoverRegex = vscode.workspace.getConfiguration("i18n-codelens").get("languageTranslatorRegex", "");
this.regex = new RegExp(hoverRegex, "g");
}

Expand Down
8 changes: 4 additions & 4 deletions src/providers/DecoratorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class DecoratorProvider {

vscode.workspace.onDidChangeConfiguration((e) => {
this._onDidChangeCodeLenses.fire();
if (e.affectsConfiguration("akinon-codelens.languageTranslatorRegex")) {
if (e.affectsConfiguration("i18n-codelens.languageTranslatorRegex")) {
this.refreshRegexFromConfig();
}
}, this.context.subscriptions);
Expand Down Expand Up @@ -67,7 +67,7 @@ export class DecoratorProvider {
}
}, null, this.context.subscriptions);

const resourceGlobPattern = vscode.workspace.getConfiguration("akinon-codelens").get("languageGlobPattern", "**/locales/*.json");
const resourceGlobPattern = vscode.workspace.getConfiguration("i18n-codelens").get("languageGlobPattern", "**/locales/*.json");
const watcher = vscode.workspace.createFileSystemWatcher(resourceGlobPattern, false, false, true);
watcher.onDidChange((e) => {
this.triggerUpdateDecorations(true);
Expand All @@ -76,14 +76,14 @@ export class DecoratorProvider {
}

private refreshRegexFromConfig = () => {
const hoverRegex = vscode.workspace.getConfiguration("akinon-codelens").get("languageTranslatorRegex", "");
const hoverRegex = vscode.workspace.getConfiguration("i18n-codelens").get("languageTranslatorRegex", "");
this.regex = new RegExp(hoverRegex, "g");
}


public updateDecorations = async (textEditor?: vscode.TextEditor) => {
const activeEditor = textEditor || this.activeEditor;
const isDecorationEnabled = vscode.workspace.getConfiguration("akinon-codelens").get("enableUnderlineResourceDecorator", true);
const isDecorationEnabled = vscode.workspace.getConfiguration("i18n-codelens").get("enableUnderlineResourceDecorator", true);
if (!activeEditor || !isDecorationEnabled) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/HoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export class HoverProvider implements vscode.HoverProvider {
this.refreshRegexFromConfig();

vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("akinon-codelens.languageTranslatorRegex")) {
if (e.affectsConfiguration("i18n-codelens.languageTranslatorRegex")) {
this.refreshRegexFromConfig();
}
}, null, context.subscriptions);
}

private refreshRegexFromConfig() {
const hoverRegex = vscode.workspace.getConfiguration("akinon-codelens").get("languageTranslatorRegex", "");
const hoverRegex = vscode.workspace.getConfiguration("i18n-codelens").get("languageTranslatorRegex", "");
this.regex = new RegExp(hoverRegex, "g");
}

Expand Down
2 changes: 1 addition & 1 deletion src/watcher/ResourceWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionRefreshLanguageResource from '../actions/ActionRefreshLanguageResou


export default function ResourceWatcher() {
const resourceGlobPattern = vscode.workspace.getConfiguration("akinon-codelens").get("languageGlobPattern", "**/locales/*.json");
const resourceGlobPattern = vscode.workspace.getConfiguration("i18n-codelens").get("languageGlobPattern", "**/locales/*.json");

const watcher = vscode.workspace.createFileSystemWatcher(resourceGlobPattern, false, false, true);

Expand Down

0 comments on commit 02a9990

Please sign in to comment.