fsprojects / FSharp.Formatting

F# tools for generating documentation (Markdown processor and F# code formatter)
https://fsprojects.github.io/FSharp.Formatting/
Other
465 stars 156 forks source link

Use FSharpVSPowerTools.Core to syntactically colorize F# code snippets #255

Closed vasily-kirichenko closed 9 years ago

vasily-kirichenko commented 9 years ago

After I changed the color scheme used for code snippets to match VS light theme (mostly), I'll get the very boring result:

image

It's identical to what we have in VS without VFPT installed. We publish FSharpVSPowerTools.Core NuGet package which includes IDE-agnostic functionality. In particular, https://github.com/fsprojects/VisualFSharpPowerTools/blob/master/src/FSharpVSPowerTools.Core/SourceCodeClassifier.fs#L265 could be used to syntactically classify F# code to the following categories:

type Category =
    | ReferenceType
    | ValueType
    | PatternCase
    | Function
    | MutableVar
    | Quotation
    | Module
    | Unused
    | Printf
    | Escaped
    | Other

/cc @dungpa

dungpa commented 9 years ago

:+1:

vasily-kirichenko commented 9 years ago

@dungpa FSharpVSPowerTools.Core is compiled with .net 4.5 as target framework. FSharp.CodeFormat is .net 4.0 :( It seems we should compile our Core for 4.0 and include it into the package...

tpetricek commented 9 years ago

Doing this would be pretty neat!

I suspect that this may need a larger change in FSharp.CodeFormat though. Currently, it uses the line tokenizer to run the lexer and then it uses the IDE tools to get tooltip information (see this part of source).

I suspect that if we want to use the symbol classifier, then we should create a proper project context, parse & type-check the source code and then format the tokens. Also, there is a slightly ugly piece of code that pre-processes the token stream and handles some special commands - see this bit of code.

Any PR that improves this would be very welcome! (Are you planning to look into this, or should I mark it as up-for-grabs for others?)

tpetricek commented 9 years ago

As for the .NET 4.5 vs .NET 4.0 mismatch, I would not mind updating F# Formatting to .NET 4.5 - if it is hard for you to create 4.0 version of FSharpVSPowerTools.Core, then just update F# Formatting to .NET 4.5. I think @matthid wanted this too for new RazorEngine features....

vasily-kirichenko commented 9 years ago

image

matthid commented 9 years ago

Just to clarify: There wont be more features from RazorEngine because of updating (That's fixed since I re-introduced net40 support).

But there are some bugs in Microsoft.AspNet.Razor-2 so I definitely recommend upgrading to net45 and using the RazorEngine.dll in the net45 folder and Razor-3 (just make sure to use both or you will run into pain)!

That said I don't think FSharp.Formatting runs into any of those bugs, and I'm not sure if we have users that customize the templates enough to run into those bugs :)

vasily-kirichenko commented 9 years ago

@tpetricek OK, I'll update FSharp.Formatting to .net 4.5. I've already basically implemented this feature. Will make PR soon.

vasily-kirichenko commented 9 years ago

@tpetricek I'm making a light theme (style.css) for code snippets as I go. What's the best way to ship it as an alternative to the dark theme?

tpetricek commented 9 years ago

@vasily-kirichenko Commented on this in #254 - I think having an alternative CSS file in the NuGet package. Does that sound reasonable to you?

vasily-kirichenko commented 9 years ago

@tpetricek I'm confused a bit. Is the following pic uses the standard style.css?

image

I mean, is the background not black anymore? As I can see, everyone uses black background. What am I missing?

tpetricek commented 9 years ago

Hmm, this looks like an older style that I used before. A quick search found it here: https://github.com/tpetricek/FSharp.Formatting/blob/7febe66cd84889914a2d425d4374e9b749db62ce/src/FSharp.CodeFormat/files/style.css. I think we're not using this anywhere anymore (and it could be deleted).

Though perhaps we should keep this around in case people want an example of minimal CSS that they need (when not using the rest of ProjectScaffold).

vasily-kirichenko commented 9 years ago

Implemented in https://github.com/tpetricek/FSharp.Formatting/pull/256