1
1
from .logging import debug
2
2
from .protocol import SignatureHelp
3
- from .protocol import SignatureHelpContext
4
3
from .protocol import SignatureInformation
5
4
from .registry import LspTextCommand
6
5
from .typing import Optional , List
@@ -66,26 +65,18 @@ def render(self, view: sublime.View) -> str:
66
65
except IndexError :
67
66
return ""
68
67
formatted = [] # type: List[str]
69
- intro = self ._render_intro ()
70
- if intro :
71
- formatted .append (intro )
68
+ if self .has_multiple_signatures ():
69
+ formatted .append (self ._render_intro ())
72
70
formatted .extend (self ._render_label (view , signature ))
73
71
formatted .extend (self ._render_docs (view , signature ))
74
72
return "" .join (formatted )
75
73
76
- def context (self , trigger_kind : int , trigger_character : str , is_retrigger : bool ) -> SignatureHelpContext :
74
+ def active_signature_help (self ) -> SignatureHelp :
77
75
"""
78
76
Extract the state out of this state machine to send back to the language server.
79
-
80
- XXX: Currently unused. Revisit this some time in the future.
81
77
"""
82
78
self ._state ["activeSignature" ] = self ._active_signature_index
83
- return {
84
- "triggerKind" : trigger_kind ,
85
- "triggerCharacter" : trigger_character ,
86
- "isRetrigger" : is_retrigger ,
87
- "activeSignatureHelp" : self ._state
88
- }
79
+ return self ._state
89
80
90
81
def has_multiple_signatures (self ) -> bool :
91
82
"""Does the current signature help state contain more than one overload?"""
@@ -96,18 +87,13 @@ def select_signature(self, forward: bool) -> None:
96
87
new_index = self ._active_signature_index + (1 if forward else - 1 )
97
88
self ._active_signature_index = max (0 , min (new_index , len (self ._signatures ) - 1 ))
98
89
99
- def active_signature (self ) -> SignatureInformation :
100
- return self ._signatures [self ._active_signature_index ]
101
-
102
- def _render_intro (self ) -> Optional [str ]:
103
- if len (self ._signatures ) > 1 :
104
- fmt = '<p><div style="font-size: 0.9rem"><b>{}</b> of <b>{}</b> overloads ' + \
105
- "(use ↑ ↓ to navigate, press Esc to hide):</div></p>"
106
- return fmt .format (
107
- self ._active_signature_index + 1 ,
108
- len (self ._signatures ),
109
- )
110
- return None
90
+ def _render_intro (self ) -> str :
91
+ fmt = '<p><div style="font-size: 0.9rem"><b>{}</b> of <b>{}</b> overloads ' + \
92
+ "(use ↑ ↓ to navigate, press Esc to hide):</div></p>"
93
+ return fmt .format (
94
+ self ._active_signature_index + 1 ,
95
+ len (self ._signatures ),
96
+ )
111
97
112
98
def _render_label (self , view : sublime .View , signature : SignatureInformation ) -> List [str ]:
113
99
formatted = [] # type: List[str]
@@ -118,6 +104,7 @@ def _render_label(self, view: sublime.View, signature: SignatureInformation) ->
118
104
parameters = signature .get ("parameters" )
119
105
if parameters :
120
106
prev , start , end = 0 , 0 , 0
107
+ active_parameter_index = signature .get ("activeParameter" , self ._active_parameter_index )
121
108
for i , param in enumerate (parameters ):
122
109
rawlabel = param ["label" ]
123
110
if isinstance (rawlabel , list ):
@@ -136,7 +123,7 @@ def _render_label(self, view: sublime.View, signature: SignatureInformation) ->
136
123
end = start + len (rawlabel )
137
124
if prev < start :
138
125
formatted .append (_function (view , label [prev :start ]))
139
- formatted .append (_parameter (view , label [start :end ], i == self . _active_parameter_index ))
126
+ formatted .append (_parameter (view , label [start :end ], i == active_parameter_index ))
140
127
prev = end
141
128
if end < len (label ):
142
129
formatted .append (_function (view , label [end :]))
@@ -164,7 +151,7 @@ def _parameter_documentation(self, view: sublime.View, signature: SignatureInfor
164
151
if not parameters :
165
152
return None
166
153
try :
167
- parameter = parameters [self ._active_parameter_index ]
154
+ parameter = parameters [signature . get ( "activeParameter" , self ._active_parameter_index ) ]
168
155
except IndexError :
169
156
return None
170
157
documentation = parameter .get ("documentation" )
@@ -186,7 +173,8 @@ def _function(view: sublime.View, content: str) -> str:
186
173
187
174
188
175
def _parameter (view : sublime .View , content : str , emphasize : bool ) -> str :
189
- return _wrap_with_scope_style (view , content , "variable.parameter.sighelp.lsp" , emphasize )
176
+ scope = "variable.parameter.sighelp.active.lsp" if emphasize else "variable.parameter.sighelp.lsp"
177
+ return _wrap_with_scope_style (view , content , scope , emphasize )
190
178
191
179
192
180
def _wrap_with_scope_style (view : sublime .View , content : str , scope : str , emphasize : bool ) -> str :
0 commit comments