Ensure signature help label contains parameter substrings per LSP spec - #728
Open
SoulSniper-V2 wants to merge 1 commit into
Open
SoulSniper-V2 wants to merge 1 commit into
SoulSniper-V2 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When signature help is requested for callable objects whose docstring header does not explicitly list the parameter signature (for example, callable class instances or C-extensions/ufuncs),
pylspcould return a truncated label likeMyCallable()orufunc()whileparameterslists parameter names like['a', 'b']or['args', 'kwargs'].According to the LSP 3.17 specification:
Because parameter labels were not substrings of the signature
label, strict LSP clients (such as YouCompleteMe) report a protocol error / invalid signature message.Reported in #678.
Root cause
In
pylsp/plugins/signature.py:function_sigwas parsed by splittings.docstring()on\n\nand taking the first line/paragraph. For callable instances or objects whose docstring begins with a class or type header without parameter names (e.g.ufunc()), this produced a header without parameters.s.paramswas populated with parameter objects whose names (p.name) were not contained in the truncated label.Fix
s.to_string()to obtain the canonical signature string (e.g.MyCallable(a, b=1)), falling back to docstring parsing ifto_string()is empty or unavailable.s.paramsis present and any parameter name is not a substring offunction_sig, construct the label asf"{name}({param_list})"so that all parameter names are guaranteed to be substrings of the signature label.sig["parameters"]are only included if their label is a substring of the containing signature label per the LSP specification.Test
Added unit tests in
test/plugins/test_signature.py:test_callable_instance_signature: Verifies that signature help for a callable class instance includes its parameters in the signature label and that all parameter labels are substrings of the signature label.test_signature_fallback_when_label_missing_params: Verifies fallback formatting when a signature label would otherwise omit parameter names.Fixes #678