Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve F# signature formatting #106

Closed
7sharp9 opened this issue Jan 21, 2014 · 17 comments
Closed

Improve F# signature formatting #106

7sharp9 opened this issue Jan 21, 2014 · 17 comments

Comments

@7sharp9
Copy link
Member

7sharp9 commented Jan 21, 2014

Take the following signature:

Signature: (untypedParse:ParseFileResults * filename * source * options * isResultObsolete * textSnapshotInfo:obj option) -> Async<CheckFileOption>

Once it gets to a certain width it becomes hard to read especially if it is forced to break lines in the middle. Perhaps some formatting like this might be nice:

screen shot 2014-01-21 at 09 57 44

colourising type names and the -> could also improve legibility

@dungpa
Copy link
Contributor

dungpa commented Jan 21, 2014

Nice one. It might be a good idea to follow what has been done in FSharpBinding.

@ovatsus
Copy link

ovatsus commented Jan 21, 2014

👍

@forki
Copy link
Member

forki commented Jan 21, 2014

This looks really interesting. +1

@7sharp9
Copy link
Member Author

7sharp9 commented Jan 21, 2014

@dungpa The F# binding needs this addressing too

I think it would be fairly easy to format like the above when the line length exceeds x characters, indenting to align the first item.

I could possibly look at a PR for this at some point if its of interest ...

@7sharp9
Copy link
Member Author

7sharp9 commented Jan 21, 2014

This is what the F# binding does currently:

screen shot 2014-01-21 at 10 38 21

@dungpa
Copy link
Contributor

dungpa commented Jan 21, 2014

It would look nice using the proposed format above. This proposal also benefits FSharp.Compiler.Service API docs where there are lots of long type signatures. +1

@sergey-tihon
Copy link
Member

Also will be really nice to colorize signature tip. I think it will be much easier to read.

@7sharp9
Copy link
Member Author

7sharp9 commented Jan 22, 2014

I built something to format long tips (over 80 characters) to break on * and ->

so

let ratherlongfunction2 a b c d e f g h i j k l m n o p q r s t u v w x y z = 
    a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z

Would be rendered like:

val ratherlongfunction2 : a:int -> b:int -> c:int -> d:int -> e:int -> f:int
                          -> g:int -> h:int -> i:int -> j:int -> k:int
                          -> l:int -> m:int -> n:int -> o:int -> p:int
                          -> q:int -> r:int -> s:int -> t:int -> u:int
                          -> v:int -> w:int -> x:int -> y:int -> z:int -> int

a tuple version is much the same:

val ratherlongfunction : a:int * b:int * c:int * d:int * e:int * f:int * g:int *
                         h:int * i:int * j:int * k:int * l:int * m:int * n:int *
                         o:int * p:int * q:int * r:int * s:int * t:int * u:int *
                         v:int * w:int * x:int * y:int * z:int -> int

@ghost
Copy link

ghost commented Jan 23, 2014

I personally think it is better to show signatures via a sample use, e.g. something like this:

M.ratherlongfunction2(a, b, c, d, e, f, g, h) : int 

with hover-over or button to show alternative views, e.g. hover-over parameters can give docs and types. It is much less daunting (especially for curried functions) and in practice conveys much the same information.

Cheers
Don

p.s. In some far-flung future version of F# we could even consider allowing an alternative signature signature something like this. I believe it's the right direction to give a more intuitive, readable signature syntax. For F# code, the focus is so much on expressions rather than types, that showing a signature by using expression syntax where possible (though there must of course be enough information to define the types). But that's all a separate conversation, and far off.

@7sharp9
Copy link
Member Author

7sharp9 commented Jan 23, 2014

Im not sure I understand, you would prefer a smaller example to demonstrate?

val ratherlongfunction2 : a:int -> b:int -> c:int -> d:int -> e:int -> f:int
                          -> g:int -> h:int -> int

In the example above the original signature would be:

val ratherlongfunction2 : a:int -> b:int -> c:int -> d:int -> e:int -> f:int -> g:int -> h:int -> i:int -> j:int -> k:int -> l:int -> 
m:int -> n:int -> o:int -> p:int -> q:int -> r:int -> s:int -> t:int -> u:int -> v:int -> w:int -> x:int -> y:int -> z:int -> int

I think that even indenting to the start of the definition makes this clearer.

Its beyond the scope of a simple change to add colouring, or adding alternative views etc. Although valid I would rather spend some time elsewhere, plus I would have to spend a lot more time immersed in the code, possibly adding to the DSL that currently describes tooltips.

@7sharp9
Copy link
Member Author

7sharp9 commented Jan 23, 2014

I agree the current tips quite a bit of concentration to use at times, the monodevelop tooltip shown above is an example of something quite difficult to read. Some of the issues in monodevelop is that the current code assumes only the first line will be the tooltip and everything else is a summary document, thats why the signature spills over.

@7sharp9
Copy link
Member Author

7sharp9 commented Jan 23, 2014

As an aside, a double popup tooltip could achieve contextual highlighting:

pop up a tooltip with type information omitted:

val ratherlongfunction2 : a -> b -> c -> d -> e -> f -> g -> h -> int

and when you hover on the a you could show another pop up

                              a:int

@tpetricek
Copy link
Member

In any case, I think this would be best done in F# Compiler Services - that way, other consumers (including Xamarin studio and F# Formatting) can benefit from a single implementation?

@7sharp9
Copy link
Member Author

7sharp9 commented Jan 28, 2014

Well I can certainly send the PR to compiler services instead, I would of thought FSharp.Formatting would of been the place for formatting though.

@tpetricek
Copy link
Member

Does the F.C.S expose the data for tool tips in some nice discriminated union, or as a plain string? If it is a DU, then we can certainly format it nicely. Otherwise, I'd wait until we can get data in a nicer format.

@7sharp9
Copy link
Member Author

7sharp9 commented Feb 7, 2014

This is what I did for the language service in the XS addin:

fsprojects/zarchive-fsharpbinding#323

@dsyme
Copy link
Contributor

dsyme commented Aug 1, 2020

This is fixed for now

@dsyme dsyme closed this as completed Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants