Skip to content

Commit 826c3c4

Browse files
committed
refactoring
1 parent b31e15a commit 826c3c4

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/features/translation.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,17 @@ const toFind: FeatureTag = [
3131
},
3232
];
3333

34-
const getLangKey = (item: AutocompleteParsingResult.MethodCall): string | undefined => {
35-
let langKey = undefined;
36-
34+
const getLang = (item: AutocompleteParsingResult.MethodCall): string | undefined => {
3735
const locale = (item.arguments.children as AutocompleteParsingResult.Argument[]).find(
3836
(arg) => arg.name === "locale",
3937
);
4038

41-
if (locale && locale.children.length) {
42-
langKey = (locale.children as AutocompleteParsingResult.StringValue[])[0].value;
43-
}
44-
45-
return langKey;
39+
return locale?.children.length ?
40+
(locale.children as AutocompleteParsingResult.StringValue[])[0].value : undefined;
4641
};
4742

48-
const getTranslationItem = (translation: TranslationItem, langKey?: string) => {
49-
return translation[langKey ?? getTranslations().items.default] ?? translation[Object.keys(translation)[0]];
43+
const getTranslationItemByLang = (translation: TranslationItem, lang?: string) => {
44+
return translation[lang ?? getTranslations().items.default] ?? translation[Object.keys(translation)[0]];
5045
};
5146

5247
export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
@@ -66,9 +61,9 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
6661
return null;
6762
}
6863

69-
const def = getTranslationItem(
64+
const def = getTranslationItemByLang(
7065
translation,
71-
getLangKey(item as AutocompleteParsingResult.MethodCall)
66+
getLang(item as AutocompleteParsingResult.MethodCall)
7267
);
7368

7469
return new vscode.DocumentLink(
@@ -173,7 +168,7 @@ export const completionProvider = {
173168
if (totalTranslationItems < 200) {
174169
// This will bomb if we have too many translations,
175170
// 200 is an arbitrary but probably safe number
176-
completionItem.detail = getTranslationItem(translations).value;
171+
completionItem.detail = getTranslationItemByLang(translations).value;
177172
}
178173

179174
return completionItem;
@@ -198,7 +193,7 @@ export const completionProvider = {
198193
return Object.entries(getTranslations().items.translations)
199194
.filter(([key, value]) => key === result.param(0).value)
200195
.map(([key, value]) => {
201-
return getTranslationItem(value)
196+
return getTranslationItemByLang(value)
202197
.params.filter((param) => {
203198
return true;
204199
// TODO: Fix this....

0 commit comments

Comments
 (0)