pyright
pyright copied to clipboard
[WIP] add a new 'compactSignatureDisplay' option for hover and completions.…
… Currently its defaulted to false so that we insert newline between function parameters, but in tests we enable compact mode so that we don't need to re-write every test when we want to change the display format.
This time i dont modify printType
and restrict the formatting to a higher level in hoverProvider
and completionProvider
.
todo:
- [x] add some actual tests around the new non-compact hover/completion layouts
- [ ] HeeJae also suggested we re-rewrite
printType
to use aDisplayStruct
under the hood, with a list of string and token kind, so that we can do proper formatting outside of printType. similar togetFuncitonParts
but something likegetTypeParts
One important note.
this doesn't currently handle the case of a function or overloaded function being assigned to a variable, and then having the variables hover show nicely formatted overloads with parameters separated on an individual line. Variables use 'printType()' and not getFunctionParts()
so I dont have access to the separate parts. I probably could get the variables alias type and see if its a function/overload. Will investigate
example
class constructors
functions
currently if there is only 1 parameter will wont separate out the parens to new lines. Also note I considered 2 options for the closing parens and decided to place the closing paren on a new line, in order to give return type annotations more horizontal space.
I think our current approach of printType actually returning hard coded format of string representation of the type is okay but more flexible way to do it would be it returning some structured data that other formatter can run over to create string format whatever way they want. like how printFunctionParts or how roslyn does - https://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/SymbolDisplay/SymbolDisplay.cs,109
this kind of infrastructure will provide PTVS (pylance in VS) to use VS LSP extension which let one does much richer user experience such as colorization in find all reference
window or workspace symbol
window.
which works by returning encoded string of each part of type signature (ex, markdown between parts) rather than plain text such as one returned by printType.
ex) if we have a way to return parts, printType will simple do something like this https://sourceroslyn.io/#Microsoft.CodeAnalysis.Workspaces/SymbolDisplayPartExtensions.cs,12
@bschnurr, is this PR still valid, or should it be closed?
I need to update it to fix the latest conflicts, sorry.
going to create a new PR.