1111
1212
1313#: Regexp for parsing a single Lua identifier.
14- _OBJECT_NAME_RE = re .compile (r"^\s*(?P<name>[\w-]+)" )
14+ _OBJECT_NAME_RE = re .compile (r"^\s*(?P<name>[\w-]+)\s* " )
1515
1616#: A single function parameter name.
1717_PARAM_NAME_RE = re .compile (r"^\s*[\w-]+\s*$" )
@@ -29,7 +29,7 @@ def fn(self, sig: str, signode: addnodes.desc_signature):
2929 sig ,
3030 e ,
3131 type = "lua-ls" ,
32- location = ( signode . source , signode . line ) ,
32+ location = signode ,
3333 )
3434 raise
3535
@@ -49,7 +49,7 @@ def separate_name_prefix(sig: str) -> tuple[str, str]:
4949 name_components .append (f"[{ normalize_type (name )} ]" )
5050 elif match := _OBJECT_NAME_RE .match (sig ):
5151 name_components .append (match .group ("name" ))
52- sig = sig [match .span ()[ 1 ] :]
52+ sig = sig [match .end () :]
5353 else :
5454 if seen_dot_prefix :
5555 raise ValueError ("incorrect object name" )
@@ -230,32 +230,33 @@ def parse_types(sig: str, parsingFunctionParams: bool = False) -> list[tuple[str
230230 # Ident not followed by an open brace, semicolon, etc.
231231 # Example: `module.Type`.
232232 # Doesn't match: `name?: ...`, `name( ...`, etc.
233- (?P<ident>\w[\w-]*(?:\.\w[\w-]*)*)
234- \s* (?P<ident_qm>\??) \s*
235- (?![:(\w.? -])
233+ (?P<ident>\w[\w-]*\s* (?:\.\s*\ w[\w-]*\s *)*)
234+ (?P<ident_qm>(?:\? \s*)*)
235+ (?![:(\w.-])
236236 |
237237 # Built-in type not followed by an open brace, semicolon, etc.
238238 # Example: `string`, `string?`.
239239 # Doesn't match: `string?: ...`, `string( ...`, etc.
240240 (?P<type>nil|any|boolean|string|number|integer|function|table|thread|userdata|lightuserdata)
241- \b\s*(?P<type_qm>\??) \s*
242- (?![:(\w.? -])
241+ \b\s*(?P<type_qm>(?:\? \s*)*)
242+ (?![:(\w.-])
243243 |
244244 # Name component, only matches when `ident` and `type` didn't match.
245245 # Example: `string: ...`.
246- (?P<name>\w[\w.-] *)
246+ (?P<name>\w[\w-]*\s*(?:\.\s*\w[\w-]*\s*) *)
247247 |
248248 # Punctuation that we separate with spaces.
249249 (?P<punct>[=:,|&])
250250 |
251251 # Braces.
252- (?P<brace>[()[\]{}])
252+ # Match them separately, otherwise greedy `other_punct` might eat functional arrow.
253+ (?P<brace>[()[\]{}<>])
253254 |
254255 # Functional arrow (will be replaced with semicolon).
255256 (?P<arrow>->)
256257 |
257258 # Punctuation that we copy as-is, without adding spaces.
258- (?P<other_punct>[-!#$%*+/\\;<>?@[\]^_{} ~]+)
259+ (?P<other_punct>[-!#$%*+/\\;?@^_ ~]+)
259260 |
260261 # Anything else is copied as-is.
261262 (?P<other>.)
@@ -285,6 +286,7 @@ def type_to_nodes(typ: str, inliner) -> list[nodes.Node]:
285286 elif text := match .group ("type" ):
286287 res .append (addnodes .desc_sig_keyword_type (text , text ))
287288 if qm := match .group ("type_qm" ):
289+ qm = re .sub (r"\s" , "" , qm )
288290 res .append (addnodes .desc_sig_punctuation (qm , qm ))
289291 elif text := match .group ("string" ):
290292 res .append (addnodes .desc_sig_literal_string (text , text ))
@@ -293,14 +295,17 @@ def type_to_nodes(typ: str, inliner) -> list[nodes.Node]:
293295 elif text := match .group ("ident" ):
294296 import sphinx_lua_ls .domain
295297
298+ text = re .sub (r"\s" , "" , text )
296299 ref_nodes , warn_nodes = sphinx_lua_ls .domain .LuaXRefRole ()(
297300 "lua:_auto" , text , text , 0 , inliner
298301 )
299302 res .extend (ref_nodes )
300303 res .extend (warn_nodes )
301304 if qm := match .group ("ident_qm" ):
305+ qm = re .sub (r"\s" , "" , qm )
302306 res .append (addnodes .desc_sig_punctuation (qm , qm ))
303307 elif text := match .group ("name" ):
308+ text = re .sub (r"\s" , "" , text )
304309 res .append (addnodes .desc_sig_name (text , text ))
305310 elif text := match .group ("punct" ):
306311 if text in "=|&" :
@@ -315,7 +320,10 @@ def type_to_nodes(typ: str, inliner) -> list[nodes.Node]:
315320 elif text := match .group ("other_punct" ):
316321 res .append (addnodes .desc_sig_punctuation (text , text ))
317322 elif text := match .group ("other" ):
318- res .append (nodes .Text (text ))
323+ if res and isinstance (res [- 1 ], nodes .Text ):
324+ res [- 1 ] += text
325+ else :
326+ res .append (nodes .Text (text ))
319327
320328 return res
321329
@@ -339,17 +347,17 @@ def normalize_type(typ: str) -> str:
339347 elif text := match .group ("type" ):
340348 res += text
341349 if qm := match .group ("type_qm" ):
342- res += qm
350+ res += re . sub ( r"\s" , "" , qm )
343351 elif text := match .group ("string" ):
344352 res += text
345353 elif text := match .group ("number" ):
346354 res += text
347355 elif text := match .group ("ident" ):
348- res += text
356+ res += re . sub ( r"\s" , "" , text )
349357 if qm := match .group ("ident_qm" ):
350- res += qm
358+ res += re . sub ( r"\s" , "" , qm )
351359 elif text := match .group ("name" ):
352- res += text
360+ res += re . sub ( r"\s" , "" , text )
353361 elif text := match .group ("punct" ):
354362 if text in "=|" :
355363 res += " "
0 commit comments