@@ -38,28 +38,40 @@ class SignatureProvider {
38
38
}
39
39
}
40
40
41
- pushSignature ( activeParameter , signatures , docs , callback , activeCallbackParameter , callbackDocumentation ) {
41
+ pushSignature ( hasSelf , activeParameter , signatures , docs , callback , activeCallbackParameter , callbackDocumentation ) {
42
42
let docArguments = "ARGUMENTS" in docs ? "ARGUMENTS" : ( "CALLBACK" in docs ? "CALLBACK" : undefined ) ;
43
- if ( ! docArguments ) return ;
43
+ if ( ! docArguments ) {
44
+ if ( ! hasSelf || activeParameter > 0 ) return ;
45
+ let sigInfo = new vscode . SignatureInformation ( this . generateSignatureString ( [ { NAME : "self" } ] ) , callbackDocumentation ? callbackDocumentation : ( "SEARCH" in docs ? this . GLua . WikiProvider . resolveDocumentation ( docs , docs [ "SEARCH" ] , true ) : undefined ) ) ;
46
+ sigInfo . activeParameter = 0 ;
47
+ sigInfo . parameters . push ( new vscode . ParameterInformation ( this . generateTypeSignature ( { NAME : "self" } ) ) ) ;
48
+ signatures . push ( sigInfo ) ;
49
+ return ;
50
+ }
44
51
docArguments = docs [ docArguments ] ;
45
52
46
- let arg_count = docArguments . length ;
53
+ let arg_count = docArguments . length + ( hasSelf ? 1 : 0 ) ;
47
54
let arg_pos = Math . min ( activeParameter , arg_count - 1 ) ;
48
55
if (
49
56
( activeParameter < arg_count || docArguments [ arg_count - 1 ] [ "TYPE" ] === "vararg" ) &&
50
57
( ! callback || ! ( "CALLBACK" in docArguments [ arg_pos ] ) || ( docArguments [ arg_pos ] [ "TYPE" ] === "function" ) )
51
58
) {
52
- let sigInfo = new vscode . SignatureInformation ( this . generateSignatureString ( docArguments ) , callbackDocumentation ? callbackDocumentation : ( "SEARCH" in docs ? this . GLua . WikiProvider . resolveDocumentation ( docs , docs [ "SEARCH" ] , true ) : undefined ) ) ;
59
+ let sigInfo = new vscode . SignatureInformation ( this . generateSignatureString ( hasSelf ? [ { NAME : "self" } , ... docArguments ] : docArguments ) , callbackDocumentation ? callbackDocumentation : ( "SEARCH" in docs ? this . GLua . WikiProvider . resolveDocumentation ( docs , docs [ "SEARCH" ] , true ) : undefined ) ) ;
53
60
sigInfo . activeParameter = arg_pos ;
54
- for ( let i = 0 ; i < arg_count ; i ++ ) {
61
+
62
+ if ( ! callback && hasSelf ) {
63
+ sigInfo . parameters . push ( new vscode . ParameterInformation ( this . generateTypeSignature ( { NAME : "self" } ) ) ) ;
64
+ }
65
+
66
+ for ( let i = 0 ; i < arg_count - ( hasSelf ? 1 : 0 ) ; i ++ ) {
55
67
let arg = docArguments [ i ] ;
56
68
57
69
let param = new vscode . ParameterInformation ( this . generateTypeSignature ( arg ) , "DESCRIPTION" in arg ? this . GLua . WikiProvider . resolveDocumentation ( arg ) . appendMarkdown ( sigInfo . documentation ? "\n\n---" : "" ) : undefined ) ;
58
70
if ( "ENUM" in arg ) param . ENUM = arg [ "ENUM" ] ;
59
71
60
72
if ( callback && arg_pos === i ) {
61
73
let paramSignatures = [ ] ;
62
- this . pushSignature ( activeCallbackParameter , paramSignatures , arg , undefined , undefined , sigInfo . documentation ) ;
74
+ this . pushSignature ( hasSelf , activeCallbackParameter , paramSignatures , arg , undefined , undefined , sigInfo . documentation ) ;
63
75
64
76
param . CALLBACK_SIGNATURES = new vscode . SignatureHelp ( ) ;
65
77
param . CALLBACK_SIGNATURES . signatures = paramSignatures ;
@@ -72,9 +84,9 @@ class SignatureProvider {
72
84
}
73
85
}
74
86
75
- pushSignatures ( activeParameter , signatures , docs , callback , activeCallbackParameter ) {
76
- if ( Array . isArray ( docs ) ) for ( let i = 0 ; i < docs . length ; i ++ ) this . pushSignature ( activeParameter , signatures , docs [ i ] , callback , activeCallbackParameter , undefined ) ;
77
- else this . pushSignature ( activeParameter , signatures , docs , callback , activeCallbackParameter , undefined ) ;
87
+ pushSignatures ( hasSelf , activeParameter , signatures , docs , callback , activeCallbackParameter ) {
88
+ if ( Array . isArray ( docs ) ) for ( let i = 0 ; i < docs . length ; i ++ ) this . pushSignature ( hasSelf , activeParameter , signatures , docs [ i ] , callback , activeCallbackParameter , undefined ) ;
89
+ else this . pushSignature ( hasSelf , activeParameter , signatures , docs , callback , activeCallbackParameter , undefined ) ;
78
90
}
79
91
80
92
provideSignatureHelp ( document , pos , cancel , ctx ) {
@@ -85,7 +97,7 @@ class SignatureProvider {
85
97
if ( tokenized . invalidLua || tokenized . openParanthesis . length === 0 ) return ;
86
98
87
99
let func = tokenized . openParanthesis [ tokenized . openParanthesis . length - 1 ] ;
88
- if ( func === false ) return ;
100
+ if ( func == false ) return ;
89
101
90
102
let activeCallbackParameter ;
91
103
let callback = false ;
@@ -111,7 +123,7 @@ class SignatureProvider {
111
123
112
124
// Show globals only
113
125
if ( func_name in signatureProvider . globals ) {
114
- this . pushSignatures ( activeParameter , signatures , signatureProvider . globals [ func_name ] , callback , activeCallbackParameter ) ;
126
+ this . pushSignatures ( false , activeParameter , signatures , signatureProvider . globals [ func_name ] , callback , activeCallbackParameter ) ;
115
127
}
116
128
} else {
117
129
let full_call = func_parse [ 0 ] ;
@@ -122,28 +134,29 @@ class SignatureProvider {
122
134
if ( func_call === ":" && this . GLua . CompletionProvider . completions . hook [ library_or_meta ] ) {
123
135
// Show hooks only
124
136
if ( full_call in signatureProvider . metaFunctions ) {
125
- this . pushSignatures ( activeParameter , signatures , signatureProvider . metaFunctions [ full_call ] , callback , activeCallbackParameter ) ;
137
+ this . pushSignatures ( false , activeParameter , signatures , signatureProvider . metaFunctions [ full_call ] , callback , activeCallbackParameter ) ;
126
138
}
127
139
continue ;
128
140
}
129
141
130
142
// Show libraries
131
143
if ( full_call in signatureProvider . functions ) {
132
- if ( callback && full_call == "hook.Add" ) {
133
- let hookDocTag = "GM:" + func [ 1 ] ;
144
+ if ( callback && full_call == "hook.Add" && func [ 1 ] [ 0 ] === "\"" ) {
145
+ let hookDocTag = "GM:" + func [ 1 ] . substr ( 1 , func [ 1 ] . length - 2 ) ;
134
146
if ( hookDocTag in signatureProvider . metaFunctions ) {
135
- this . pushSignatures ( activeCallbackParameter , signatures , signatureProvider . metaFunctions [ hookDocTag ] ) ;
147
+ const hasSelf = func [ 2 ] [ 0 ] !== "\"" ;
148
+ this . pushSignatures ( hasSelf , activeCallbackParameter , signatures , signatureProvider . metaFunctions [ hookDocTag ] ) ;
136
149
continue ;
137
150
}
138
151
}
139
152
140
- this . pushSignatures ( activeParameter , signatures , signatureProvider . functions [ full_call ] , callback , activeCallbackParameter ) ;
153
+ this . pushSignatures ( false , activeParameter , signatures , signatureProvider . functions [ full_call ] , callback , activeCallbackParameter ) ;
141
154
continue ;
142
155
}
143
156
144
157
// Show meta functions
145
158
if ( meta_func in signatureProvider . metaFunctions ) {
146
- this . pushSignatures ( activeParameter , signatures , signatureProvider . metaFunctions [ meta_func ] , callback , activeCallbackParameter ) ;
159
+ this . pushSignatures ( false , activeParameter , signatures , signatureProvider . metaFunctions [ meta_func ] , callback , activeCallbackParameter ) ;
147
160
continue ;
148
161
}
149
162
}
@@ -154,7 +167,7 @@ class SignatureProvider {
154
167
if ( signatures . length > 0 ) {
155
168
if ( callback ) {
156
169
let activeParam = signatures [ 0 ] . parameters [ activeParameter ] ;
157
- if ( "CALLBACK_SIGNATURES" in activeParam ) {
170
+ if ( activeParam && "CALLBACK_SIGNATURES" in activeParam ) {
158
171
return activeParam . CALLBACK_SIGNATURES ;
159
172
}
160
173
}
0 commit comments