# Is anyone working on an VSCode extension for Julia that can show the inferred types? Koka has something like this. Would be fun to work on

**URL:** <https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323>\
**Category:** VS Code\
**Created:** [September 12, 2024, 12:44pm UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323 "2024-09-12T12:44:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [September 12, 2024, 12:44pm UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/1 "2024-09-12T12:44:04Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/a/c/aca2b831fd7d726f4bc8d30732ef18e3c42cfd6e.png)

The above is from Koka’s website and show how the inferred type can be shown to the user. Theoretically, we can do the same in Julia。 Wonder if anyone’s working on this?

It would be fun to work on.

Eg. one can add annotation on the type of functions like `#' infer fn(2, 2)` and when you hover over that, the function below called `fn` will have the inferred type shown next to the variables as above in screenshot.

---

<div class="post-metadata">

**Author:** ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Post date:** [September 12, 2024, 1:00pm UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/2 "2024-09-12T13:00:14Z")

</div>

Already works partially like [VS Code Plugin for Julia now automatically shows computed type information : r/Julia (reddit.com)](https://www.reddit.com/r/Julia/comments/1ao5hxu/vs_code_plugin_for_julia_now_automatically_shows/) . [Cthulhu in vscode is great : r/Julia (reddit.com)](https://www.reddit.com/r/Julia/comments/1792u0e/cthulhu_in_vscode_is_great/)

julia.inlayHints.static.enabled is default to false that you may want to change.

---

<div class="post-metadata">

**Author:** ![xiaoxi](https://avatars.discourse-cdn.com/v4/letter/x/a9adbd/32.png) [@xiaoxi](https://discourse.julialang.org/u/xiaoxi)\
**Post date:** [September 12, 2024, 1:08pm UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/3 "2024-09-12T13:08:54Z")

</div>

Zentrik added this functionality last year.

> <https://github.com/JuliaDebug/Cthulhu.jl/pull/469>
>
> Depends on https://github.com/julia-vscode/julia-vscode/pull/3328 for showing ty…pes inline, however can be merged in before.
> 
> This pr show types in the source code when using the repl in VSCode, e.g. \`@descend f(1)\` with warnings on gives
> !\[image\](https://github.com/JuliaDebug/Cthulhu.jl/assets/19725290/77fd3e0a-7554-46ab-98d1-2ec3593b3e9e)
> And without warnings 
> !\[image\](https://github.com/JuliaDebug/Cthulhu.jl/assets/19725290/dd12a9a5-6dc1-4cf1-8ccb-0638a96db7fa)
> 
> There a couple improvements I still want to make to this pr: 
> 
> \- \[x\] Adding a way to toggle the vscode integration (should this be implemented the same way the warn toggle works?)
> \- \[x\] Removing the duplication of tests in TypedSyntax (I tried putting the tests into a separate file and using \`include\` but then the \`m = @which TSN.unnamedargs(Matrix{Float32}, Int; a="hello")\` test started failing claiming \`mi\` was \`nothing\`) 
> \- \[x\] Adding a way to automatically show types in VSCode for any called functions in an open file without having to descend into them.
> 
> As an example of how to change the colour of the hints in VSCode, I'm using the Monokai theme with the following in my \`settings.json\`
> \`\`\`json
> "workbench.colorCustomizations": {
> // Name of the theme you are currently using
> "\[Monokai\]": {
> // Overrides for specific kinds of inlay hints
> "editorInlayHint.typeForeground": "#66D9EF",
> "editorInlayHint.typeBackground": "#00000000",
> "editorInlayHint.parameterForeground": "#f8f8f2", // defaults from https://github.com/microsoft/vscode/blob/2e335d2df2001439b09483e7fcff8379ac1a7a16/extensions/theme-monokai/themes/monokai-color-theme.json#L41-L42
> "editorInlayHint.parameterBackground": "#75715E",
> // Colours for unstable types when warnings are on
> "editorInlayHint.foreground": "#e13030",
> "editorInlayHint.background": "#00000000",
> }
> }
> \`\`\`

---

<div class="post-metadata">

**Author:** ![Zentrik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zentrik/32/35409_2.png) [@Zentrik](https://discourse.julialang.org/u/Zentrik)\
**Post date:** [September 12, 2024, 5:10pm UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/4 "2024-09-12T17:10:45Z")

</div>

There is some previous discussion about making this more automatic and user friendly at [Towards Rust-level feedback on type stability](https://discourse.julialang.org/t/towards-rust-level-feedback-on-type-stability/113497).

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 13, 2024, 4:51am UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/5 "2024-09-13T04:51:33Z")

</div>

Julia’s inferred types requires one to actually run the code, doesn’t it? Most other languages like python/typescript display inferred types statically without having to run the code. IMO this makes coding significantly simpler

I haven’t kept up with the developments in the vscode plugin lately

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [September 13, 2024, 5:35am UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/6 "2024-09-13T05:35:47Z")

</div>

> [@jishnub](#):
>
> Julia’s inferred types requires one to actually run the code, doesn’t it?

No. Just needs someone to provide a specific type for the argument and run part of the compilation process up to the point where types r inferred. Based on the post I think Cthulhu just infers the type where possible

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 13, 2024, 5:56am UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/7 "2024-09-13T05:56:00Z")

</div>

> [@xiaodai](#):
>
> run part of the compilation process up to the point where types r inferred

But how does one do that without running code? Type-inference for a method happens when it is compiled, and that happens when some code is run where the method is reachable.

My impression was that the devs were unwilling to run user code by themselves to infer types

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [September 13, 2024, 7:20am UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/8 "2024-09-13T07:20:42Z")

</div>

I think that `Jet` or `Cthullu` does that without running the code. You “just” look which types are returned by functions. Type inference also does not run the code, otherwise it would not be able to deal with recursive functions.

This is why to use this, the type of arguments has to be known.

---

<div class="post-metadata">

**Author:** ![Zentrik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zentrik/32/35409_2.png) [@Zentrik](https://discourse.julialang.org/u/Zentrik)\
**Post date:** [September 13, 2024, 9:10am UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/9 "2024-09-13T09:10:24Z")

</div>

I believe you’re correct in that loading user code is not something the language server devs want to do

---

<div class="post-metadata">

**Author:** ![xiaoxi](https://avatars.discourse-cdn.com/v4/letter/x/a9adbd/32.png) [@xiaoxi](https://discourse.julialang.org/u/xiaoxi)\
**Post date:** [September 13, 2024, 11:04am UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/10 "2024-09-13T11:04:50Z")

</div>

Is inferring types statically in Julia more difficult than in other programming languages? If so, why?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 13, 2024, 11:33am UTC](https://discourse.julialang.org/t/is-anyone-working-on-an-vscode-extension-for-julia-that-can-show-the-inferred-types-koka-has-something-like-this-would-be-fun-to-work-on/119323/11 "2024-09-13T11:33:24Z")

</div>

I imagine a couple of factors make this more challenging. Firstly, code-generation using macros, so without macro-expansion, one doesn’t know what code one is running. Secondly, julia methods are often written to accept abstract types, so inferring the return type is difficult in general. Static type checking in python usually requires the user to add appropriate type-hints, which Julia doesn’t have.
