@@ -38,28 +38,40 @@ class SignatureProvider {
3838 }
3939 }
4040
41- pushSignature ( activeParameter , signatures , docs , callback , activeCallbackParameter , callbackDocumentation ) {
41+ pushSignature ( hasSelf , activeParameter , signatures , docs , callback , activeCallbackParameter , callbackDocumentation ) {
4242 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+ }
4451 docArguments = docs [ docArguments ] ;
4552
46- let arg_count = docArguments . length ;
53+ let arg_count = docArguments . length + ( hasSelf ? 1 : 0 ) ;
4754 let arg_pos = Math . min ( activeParameter , arg_count - 1 ) ;
4855 if (
4956 ( activeParameter < arg_count || docArguments [ arg_count - 1 ] [ "TYPE" ] === "vararg" ) &&
5057 ( ! callback || ! ( "CALLBACK" in docArguments [ arg_pos ] ) || ( docArguments [ arg_pos ] [ "TYPE" ] === "function" ) )
5158 ) {
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 ) ) ;
5360 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 ++ ) {
5567 let arg = docArguments [ i ] ;
5668
5769 let param = new vscode . ParameterInformation ( this . generateTypeSignature ( arg ) , "DESCRIPTION" in arg ? this . GLua . WikiProvider . resolveDocumentation ( arg ) . appendMarkdown ( sigInfo . documentation ? "\n\n---" : "" ) : undefined ) ;
5870 if ( "ENUM" in arg ) param . ENUM = arg [ "ENUM" ] ;
5971
6072 if ( callback && arg_pos === i ) {
6173 let paramSignatures = [ ] ;
62- this . pushSignature ( activeCallbackParameter , paramSignatures , arg , undefined , undefined , sigInfo . documentation ) ;
74+ this . pushSignature ( hasSelf , activeCallbackParameter , paramSignatures , arg , undefined , undefined , sigInfo . documentation ) ;
6375
6476 param . CALLBACK_SIGNATURES = new vscode . SignatureHelp ( ) ;
6577 param . CALLBACK_SIGNATURES . signatures = paramSignatures ;
@@ -72,9 +84,9 @@ class SignatureProvider {
7284 }
7385 }
7486
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 ) ;
7890 }
7991
8092 provideSignatureHelp ( document , pos , cancel , ctx ) {
@@ -85,7 +97,7 @@ class SignatureProvider {
8597 if ( tokenized . invalidLua || tokenized . openParanthesis . length === 0 ) return ;
8698
8799 let func = tokenized . openParanthesis [ tokenized . openParanthesis . length - 1 ] ;
88- if ( func === false ) return ;
100+ if ( func == false ) return ;
89101
90102 let activeCallbackParameter ;
91103 let callback = false ;
@@ -111,7 +123,7 @@ class SignatureProvider {
111123
112124 // Show globals only
113125 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 ) ;
115127 }
116128 } else {
117129 let full_call = func_parse [ 0 ] ;
@@ -122,28 +134,29 @@ class SignatureProvider {
122134 if ( func_call === ":" && this . GLua . CompletionProvider . completions . hook [ library_or_meta ] ) {
123135 // Show hooks only
124136 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 ) ;
126138 }
127139 continue ;
128140 }
129141
130142 // Show libraries
131143 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 ) ;
134146 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 ] ) ;
136149 continue ;
137150 }
138151 }
139152
140- this . pushSignatures ( activeParameter , signatures , signatureProvider . functions [ full_call ] , callback , activeCallbackParameter ) ;
153+ this . pushSignatures ( false , activeParameter , signatures , signatureProvider . functions [ full_call ] , callback , activeCallbackParameter ) ;
141154 continue ;
142155 }
143156
144157 // Show meta functions
145158 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 ) ;
147160 continue ;
148161 }
149162 }
@@ -154,7 +167,7 @@ class SignatureProvider {
154167 if ( signatures . length > 0 ) {
155168 if ( callback ) {
156169 let activeParam = signatures [ 0 ] . parameters [ activeParameter ] ;
157- if ( "CALLBACK_SIGNATURES" in activeParam ) {
170+ if ( activeParam && "CALLBACK_SIGNATURES" in activeParam ) {
158171 return activeParam . CALLBACK_SIGNATURES ;
159172 }
160173 }
0 commit comments