Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: circular reference #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions kiwi-linter/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as _ from 'lodash';
import * as fs from 'fs-extra';
import { UI } from './ui';
import { getSuggestLangObj } from './getLangData';
import { DIR_ADAPTOR, KiwiSearchTypes } from './const';
import { DIR_ADAPTOR, I18N_GLOB, KiwiSearchTypes } from './const';
import { findAllI18N, findI18N } from './findAllI18N';
import { triggerUpdateDecorations } from './chineseCharDecorations';
import { TargetStr, TranslateAPiEnum } from './define';
Expand Down Expand Up @@ -53,7 +53,7 @@ export function activate(context: vscode.ExtensionContext) {

vscode.commands.registerCommand('vscode-i18n-linter.searchI18N', () => {
vscode.window.showQuickPick(KiwiSearchTypes).then(val => {
if (val.label === '在当前文件中搜索') {
if (val?.label === '在当前文件中搜索') {
findI18N();
} else {
findAllI18N();
Expand Down Expand Up @@ -346,7 +346,8 @@ export function activate(context: vscode.ExtensionContext) {
path
.split('.')
.slice(1)
.join('.')
.join('.'),
I18N_GLOB
);
const virtualMemory = {};
finalLangObj = getSuggestLangObj();
Expand Down
9 changes: 4 additions & 5 deletions kiwi-linter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as globby from 'globby';
import { pinyin } from 'pinyin-pro';
import { TranslateAPiEnum } from './define';
import { getObjectLiteralExpression } from './astUtils';
import { I18N_GLOB } from './const';

/**
* 将对象拍平
Expand Down Expand Up @@ -337,8 +336,8 @@ export function getTranslateAPiList() {
}

/** 获取语言文件名称 */
export function getI18NFileNames() {
const _I18N_GLOB = getCurrentProjectLangPath() || I18N_GLOB;
export function getI18NFileNames(DEFAULT_I18N_GLOB?:string) {
const _I18N_GLOB = getCurrentProjectLangPath() || DEFAULT_I18N_GLOB;
const paths = globby.sync(_I18N_GLOB);
return (paths || [])
.map(i => {
Expand All @@ -351,11 +350,11 @@ export function getI18NFileNames() {
}

/** 纠正path中文件名称的方法 */
export function getSafePath(path: string) {
export function getSafePath(path: string, DEFAULT_I18N_GLOB?:string) {
if (!path) {
return path;
}
const fileNames = getI18NFileNames();
const fileNames = getI18NFileNames(DEFAULT_I18N_GLOB);
const [filename, ...restPath] = path.split('.');
const sameFileNameIndex = fileNames.map(i => i.toLowerCase()).findIndex(i => i === filename.toLowerCase());
if (sameFileNameIndex > -1) {
Expand Down