Pipeline introspection tool

On many occasions, whenever I’m trying to debug a pipeline that refuses to cooperate in some manner, I find myself writing the return signatures as side comments to get the feel for it, as below

response -- Value
  |> decodeAndParsePage -- Page
  |> Page.star lineNumber -- Page
  |> SavePage (Star lineNumber) -- Model
  |> attachCmd -- (Model, Cmd Msg)

This makes it easier for me to see what’s going on and how I can improve it.

Then I noticed the excellent GitLens tool that silently sits there and gives me context whenever I need it. (For those who don’t know, it shows git commit data for the line your cursor is in)

This got me thinking. What if there was this type introspection tool that showed the return type of each line as you went over it? Do you think it would be helpful?

3 Likes

elm-intellij shows you the type of an expression if you press ctrl+shift+p


Is this what you had in mind?

4 Likes

There was also a PR that was started for the IntelliJ plugin, and one portion was to add type hints specifically for pipelines. Details here: Add parameter inlays by dillonkearns · Pull Request #674 · klazuka/intellij-elm · GitHub.

1 Like

Almost exactly :slight_smile:

I wonder if it resolves the next line in that example.

I’m wondering if it’s hard to build something similar for VSCode

The F# VSCode extension has this feature so it should be doable for Elm in VSCode too, I think.

Yup. The type inference is fairly robust.
image

That feature exists in the language server for rust so it should be doable with type inference in the elm language server. Here is an extract of the code that detects tests in elm-test-rs. You can see type annotated in blue right next to each pipe (successive method call but that’s the same).

While it is possible, it’s not standardized (and buggy in my short testing with rust analyzer). See: Feature: Inlay Hints · Issue #956 · microsoft/language-server-protocol · GitHub

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.