haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.65k stars 355 forks source link

[Feature request] Support for code complexity measurements #1849

Open srid opened 3 years ago

srid commented 3 years ago

https://gitlab.com/migamake/homplexity is a tool that spits out measurements on "code complexity" at the function level. I thought it would be nice to integrate it to HLS so in VSCode I can see these measurement warnings adjacent to individual functions.

Running it on neuron code base, I see measurement warnings like this:

[...]
Warning:/prj/src/Neuron/Backend.hs:SrcLoc "/prj/src/Neuron/Backend.hs" 33 1: function serve has 22 lines of code should be kept below 20 lines of code.
Warning:/prj/src/Neuron/Plugin.hs:SrcLoc "/prj/src/Neuron/Plugin.hs" 128 1: type signature for routePluginData has 7 arguments should be less than 5
Warning:/prj/src/Neuron/Zettelkasten/Graph/Build.hs:SrcLoc "/prj/src/Neuron/Zettelkasten/Graph/Build.hs" 38 1: function buildZettelkasten has 23 lines of code should be kept below 20 lines of code.
Warning:/prj/src/Neuron/Zettelkasten/Zettel/Parser.hs:SrcLoc "/prj/src/Neuron/Zettelkasten/Zettel/Parser.hs" 27 1: type signature for parseZettel has 6 arguments should be less than 5
Warning:/prj/src/Neuron/Zettelkasten/Zettel/Parser.hs:SrcLoc "/prj/src/Neuron/Zettelkasten/Zettel/Parser.hs" 34 1: function parseZettel has 22 lines of code should be kept below 20 lines of code.
Warning:/prj/src/Neuron/Zettelkasten/Zettel.hs:SrcLoc "/prj/src/Neuron/Zettelkasten/Zettel.hs" 133 18: data ZettelT has record fields count of 8 should be less than 6
Warning:/prj/src/Neuron/CLI/Query.hs:SrcLoc "/prj/src/Neuron/CLI/Query.hs" 32 1: function runQuery has 34 lines of code should be kept below 20 lines of code.
Critical:/prj/src/Neuron/CLI/Parser.hs:SrcLoc "/prj/src/Neuron/CLI/Parser.hs" 39 1: function commandParser has 103 lines of code this function exceeds 40 lines of code.
Critical:/prj/src/Neuron/CLI/New.hs:SrcLoc "/prj/src/Neuron/CLI/New.hs" 39 1: function newZettelFile has 41 lines of code this function exceeds 40 lines of code.
Warning:/prj/src/Neuron/CLI/App.hs:SrcLoc "/prj/src/Neuron/CLI/App.hs" 59 1: function runAppCommand has 22 lines of code should be kept below 20 lines of code.
Warning:/prj/src/Data/Structured/OpenGraph/Render.hs:SrcLoc "/prj/src/Data/Structured/OpenGraph/Render.hs" 20 1: function renderOpenGraph has 28 lines of code should be kept below 20 lines of code.
Warning:/prj/src/Data/Structured/OpenGraph.hs:SrcLoc "/prj/src/Data/Structured/OpenGraph.hs" 21 18: data OpenGraph has record fields count of 7 should be less than 6
srid commented 3 years ago

https://github.com/rubik/argon is another tool which specifically measures cyclomatic complexity of functions.

image