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

add identifier analysis script #13486

Merged
merged 2 commits into from
Jul 11, 2022
Merged

add identifier analysis script #13486

merged 2 commits into from
Jul 11, 2022

Conversation

dsyme
Copy link
Contributor

@dsyme dsyme commented Jul 11, 2022

Discussing codebase regularity with @psfinaki , here's a script to print a report by analysing all identifiers in an F# project by type.

Sample reports here:

Run using:

dotnet fsi tests/scripts/identifierAnalysisByType.fsx src/FSharp.Build/FSharp.Build.fsproj
dotnet fsi tests/scripts/identifierAnalysisByType.fsx src/Compiler/FSharp.Compiler.Service.fsproj

For example this section of the output shows all the names used for ValReprInfo https://gist.github.com/dsyme/d47f113d7423e3cdc45a2f658c68a1a0

I sometimes think F# should have a feature where you can put an attribute on a type saying "if you have a value of this type, it must be named according to this regular expression". I guess we could adjust this script easily to implement that as a check (so the tool reports warnings based on attributes)

@dsyme
Copy link
Contributor Author

dsyme commented Jul 11, 2022

Note the formulation in tests\scripts\identifierAnalysisByType.fsx can easily be adjusted to write other analyses. Please adapt, copy, play.

The FCS API is far from perfect and things like formatting of types are a bit messy (type abbreviations and other features make that a bit tricky). But we can still extract a lot of useful information from adhoc tools like this.

printfn " %s" (vUse.ToString())
printfn "")

(*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. I hacked it across from https://github.com/fsprojects/FSharp.Formatting/blob/main/src/fsdocs-tool/ProjectCracker.fs and I think it was all a workaround for something, I'm not sure. Or else maybe it was there to cope with non-standard install locations for dotnet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW Ionide.ProjInfo is here: https://github.com/ionide/proj-info

It's the project cracking code used by the Ionide tooling for F# in VSCode

@dsyme dsyme merged commit de49e2f into dotnet:main Jul 11, 2022
@dsyme dsyme mentioned this pull request Jul 11, 2022
KevinRansom pushed a commit that referenced this pull request Jul 12, 2022
* ValRepInfoForDisplay added for improved quick info for functions defined in expressions

* Update

* Update QuickInfoTests.fs

* Update QuickInfoTests.fs

* Update

* add identifier analysis script (#13486)

* add identifier analysis script

* add identifier analysis script

* Update fantomas alpha 11 (#13481)

Co-authored-by: Don Syme <donsyme@fastmail.fm>
Co-authored-by: Peter Semkin <petersemkin@duck.com>
Co-authored-by: Don Syme <dsyme@users.noreply.github.com>
Co-authored-by: Florian Verdonck <florian.verdonck@outlook.com>
Co-authored-by: Petr Semkin <psfinaki@users.noreply.github.com>
vzarytovskii added a commit that referenced this pull request Jul 12, 2022
* ValRepInfoForDisplay added for improved quick info for functions defined in expressions

* Update

* Update QuickInfoTests.fs

* Update QuickInfoTests.fs

* Update

* add identifier analysis script (#13486)

* add identifier analysis script

* add identifier analysis script

* Update fantomas alpha 11 (#13481)

* Allow lower-case DU cases when RequireQualifiedAccess is specified (#13432)

* Allow lower-case DU cases when RequireQualifiedAccess is specified

* Fix PR suggestions and Add more testing

* Protect feature under preview version

* Add a NotUpperCaseConstructorWithoutRQA warning to be raised in lang version preview

* Fix formatting

* regularize some names (#13489)

* normalize some names

* format code

* fix build

* Subtraction of two chars, new conversions, and fixes for dynamic operator invocations and QuotationToExpression (#11681)

Co-authored-by: Vlad Zarytovskii <vzaritovsky@hotmail.com>
Co-authored-by: Don Syme <dsyme@users.noreply.github.com>

* Mark backing fields as CompilerGenerated (fixes serialization of fields in FSI multiemit) (#13494)

Co-authored-by: Don Syme <donsyme@fastmail.fm>
Co-authored-by: Peter Semkin <petersemkin@duck.com>
Co-authored-by: Don Syme <dsyme@users.noreply.github.com>
Co-authored-by: Florian Verdonck <florian.verdonck@outlook.com>
Co-authored-by: Petr Semkin <psfinaki@users.noreply.github.com>
Co-authored-by: Edgar Gonzalez <edgar.gonzalez@fundourselves.com>
Co-authored-by: Hadrian Tang <hadrianwttang@outlook.com>
Co-authored-by: Vlad Zarytovskii <vzaritovsky@hotmail.com>
Co-authored-by: Kevin Ransom (msft) <codecutter@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants