@@ -11,81 +11,69 @@ import (
11
11
12
12
func textDocumentCompletion (context * glsp.Context , params * protocol.CompletionParams ) (interface {}, error ) {
13
13
rc := NewReqContextAtPosition (& params .TextDocumentPositionParams )
14
- sourceFile := rc .textDocumentEntry .sourceFile
15
- if sourceFile == nil {
16
- return nil , nil
17
- }
18
- globalDeclarations := sourceFile .Declarations
19
- for _ , sameModuleFile := range rc .textDocumentEntry .module .Files {
20
- fileUrl := "file://" + sameModuleFile
21
- if rc .item .URI == fileUrl {
22
- continue
23
- }
24
- docEntry := langserver .documentCache .documents [fileUrl ]
25
- if docEntry == nil || docEntry .sourceFile == nil {
26
- continue
27
- }
28
-
29
- globalDeclarations = append (globalDeclarations , docEntry .sourceFile .ExportedDeclarations ()... )
30
- }
31
14
32
15
completionItems := []protocol.CompletionItem {}
33
- for _ , decl := range globalDeclarations {
34
- insertText := insertTextForDecl ( decl )
16
+ for _ , imported := range rc . globalDeclarations ( context ) {
17
+ insertText := insertTextForImportedDecl ( imported )
35
18
var detail string
36
- if decl .Meta ().ModuleName != "" {
37
- detail = string (decl .Meta ().ModuleName ) +
19
+ if imported . decl .Meta ().ModuleName != "" {
20
+ detail = string (imported . decl .Meta ().ModuleName ) +
38
21
"." +
39
- string (decl .DeclName ())
22
+ string (imported . decl .DeclName ())
40
23
}
41
24
completionItems = append (completionItems , protocol.CompletionItem {
42
- Label : string (decl .DeclName ()),
43
- Kind : completionItemKindForDecl (decl ),
25
+ Label : string (imported . decl .DeclName ()),
26
+ Kind : completionItemKindForDecl (imported . decl ),
44
27
InsertText : & insertText ,
45
28
Detail : & detail ,
46
- Documentation : documentationMarkupContentForDecl (decl ),
29
+ Documentation : documentationMarkupContentForDecl (imported . decl ),
47
30
})
48
31
}
49
32
return & completionItems , nil
50
33
}
51
34
52
- func insertTextForDecl (decl ast.Decl ) string {
53
- switch decl := decl .(type ) {
35
+ func insertTextForImportedDecl (imported importedDecl ) string {
36
+ var importPrefix string
37
+ if imported .importDecl != nil {
38
+ importPrefix = fmt .Sprintf ("%s." , imported .importDecl .DeclName ())
39
+ }
40
+
41
+ switch decl := imported .decl .(type ) {
54
42
case ast.DeclFunc :
55
- return insertTextForCallableDeclParams (decl , decl .Impl .Parameters )
43
+ return insertTextForCallableDeclParams (decl , importPrefix , decl .Impl .Parameters )
56
44
case ast.DeclExternFunc :
57
- return insertTextForCallableDeclParams (decl , decl .Parameters )
45
+ return insertTextForCallableDeclParams (decl , importPrefix , decl .Parameters )
58
46
case ast.DeclData :
59
- return insertTextForCallableDeclFields (decl , decl .Fields )
47
+ return insertTextForCallableDeclFields (decl , importPrefix , decl .Fields )
60
48
default :
61
49
return string (decl .DeclName ())
62
50
}
63
51
}
64
52
65
- func insertTextForCallableDeclParams (decl ast.Decl , parameters []ast.DeclParameter ) string {
53
+ func insertTextForCallableDeclParams (decl ast.Decl , importPrefix string , parameters []ast.DeclParameter ) string {
66
54
paramNames := make ([]string , len (parameters ))
67
55
for i , param := range parameters {
68
56
paramNames [i ] = string (param .DeclName ())
69
57
}
70
- return insertTextForCallableDecl (decl , paramNames )
58
+ return insertTextForCallableDecl (decl , importPrefix , paramNames )
71
59
}
72
60
73
- func insertTextForCallableDeclFields (decl ast.Decl , fields []ast.DeclField ) string {
61
+ func insertTextForCallableDeclFields (decl ast.Decl , importPrefix string , fields []ast.DeclField ) string {
74
62
fieldNames := make ([]string , len (fields ))
75
63
for i , param := range fields {
76
64
fieldNames [i ] = string (param .DeclName ())
77
65
}
78
- return insertTextForCallableDecl (decl , fieldNames )
66
+ return insertTextForCallableDecl (decl , importPrefix , fieldNames )
79
67
}
80
68
81
- func insertTextForCallableDecl (decl ast.Decl , parameters []string ) string {
69
+ func insertTextForCallableDecl (decl ast.Decl , importPrefix string , parameters []string ) string {
82
70
if len (parameters ) == 0 {
83
71
return string (decl .DeclName ())
84
72
}
85
73
if len (parameters ) == 1 {
86
- return fmt .Sprintf ("%s %s" , decl .DeclName (), parameters [0 ])
74
+ return fmt .Sprintf ("%s%s %s" , importPrefix , decl .DeclName (), parameters [0 ])
87
75
}
88
- return fmt .Sprintf ("(%s %s)" , decl .DeclName (), strings .Join (parameters , ", " ))
76
+ return fmt .Sprintf ("(%s%s %s)" , importPrefix , decl .DeclName (), strings .Join (parameters , ", " ))
89
77
}
90
78
91
79
func documentationMarkupContentForDecl (decl ast.Decl ) * protocol.MarkupContent {
0 commit comments