@@ -10,6 +10,7 @@ import { detectedRange, detectInDoc } from "@src/support/parser";
10
10
import { wordMatchRegex } from "@src/support/patterns" ;
11
11
import { relativePath } from "@src/support/project" ;
12
12
import { contract , facade } from "@src/support/util" ;
13
+ import { AutocompleteParsingResult } from "@src/types" ;
13
14
import * as vscode from "vscode" ;
14
15
import { FeatureTag , HoverProvider , LinkProvider } from ".." ;
15
16
@@ -30,18 +31,35 @@ const toFind: FeatureTag = [
30
31
} ,
31
32
] ;
32
33
33
- const getDefault = ( translation : TranslationItem ) => {
34
- const langDefault = getTranslations ( ) . items . default ;
34
+ const getLang = ( item : AutocompleteParsingResult . MethodCall ) : string | undefined => {
35
+ let lang = undefined ;
35
36
36
- return translation [ langDefault ] ?? translation [ Object . keys ( translation ) [ 0 ] ] ;
37
+ const children = item . arguments . children ;
38
+ const locale = ( children as AutocompleteParsingResult . Argument [ ] ) . find (
39
+ ( arg ) => arg . name === "locale" ,
40
+ ) ;
41
+
42
+ if ( locale && locale . children . length ) {
43
+ lang = ( locale . children as AutocompleteParsingResult . StringValue [ ] ) [ 0 ] . value ;
44
+ }
45
+
46
+ return lang ;
47
+ } ;
48
+
49
+ const getTranslationItem = ( translation : TranslationItem , lang ?: string ) => {
50
+ if ( ! lang ) {
51
+ lang = getTranslations ( ) . items . default ;
52
+ }
53
+
54
+ return translation [ lang ] ?? translation [ Object . keys ( translation ) [ 0 ] ] ;
37
55
} ;
38
56
39
57
export const linkProvider : LinkProvider = ( doc : vscode . TextDocument ) => {
40
58
return detectInDoc < vscode . DocumentLink , "string" > (
41
59
doc ,
42
60
toFind ,
43
61
getTranslations ,
44
- ( { param, index } ) => {
62
+ ( { param, index, item } ) => {
45
63
if ( index !== 0 ) {
46
64
return null ;
47
65
}
@@ -53,7 +71,10 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
53
71
return null ;
54
72
}
55
73
56
- const def = getDefault ( translation ) ;
74
+ const def = getTranslationItem (
75
+ translation ,
76
+ getLang ( item as AutocompleteParsingResult . MethodCall )
77
+ ) ;
57
78
58
79
return new vscode . DocumentLink (
59
80
detectedRange ( param ) ,
@@ -157,7 +178,7 @@ export const completionProvider = {
157
178
if ( totalTranslationItems < 200 ) {
158
179
// This will bomb if we have too many translations,
159
180
// 200 is an arbitrary but probably safe number
160
- completionItem . detail = getDefault ( translations ) . value ;
181
+ completionItem . detail = getTranslationItem ( translations ) . value ;
161
182
}
162
183
163
184
return completionItem ;
@@ -182,7 +203,7 @@ export const completionProvider = {
182
203
return Object . entries ( getTranslations ( ) . items . translations )
183
204
. filter ( ( [ key , value ] ) => key === result . param ( 0 ) . value )
184
205
. map ( ( [ key , value ] ) => {
185
- return getDefault ( value )
206
+ return getTranslationItem ( value )
186
207
. params . filter ( ( param ) => {
187
208
return true ;
188
209
// TODO: Fix this....
0 commit comments