{"id":33080,"date":"2021-05-26T08:00:16","date_gmt":"2021-05-26T15:00:16","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=33080"},"modified":"2021-05-26T15:30:18","modified_gmt":"2021-05-26T22:30:18","slug":"f-and-f-tools-update-for-visual-studio-16-10","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/f-and-f-tools-update-for-visual-studio-16-10\/","title":{"rendered":"F# and F# tools update for Visual Studio 16.10"},"content":{"rendered":"<p>We&#8217;re excited to announce updates to the F# tools for Visual Studio 16.10. For this release, we&#8217;re continuing our trend of improving the F# experience in Visual Studio to build upon what was released in the <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/f-and-f-tools-update-for-visual-studio-16-9\/\">VS 16.9 update last February<\/a>.<\/p>\n<ul>\n<li>Support for Go to Definition on external symbols<\/li>\n<li>Better support for mixing C# and F# projects in a solution<\/li>\n<li>More quick fixes and refactorings<\/li>\n<li>More tooling performance and responsiveness improvements<\/li>\n<li>More core compiler improvements<\/li>\n<\/ul>\n<p>Let&#8217;s dive in!<\/p>\n<h2>Go to Definition on external symbols<\/h2>\n<p>This one&#8217;s been a long time coming. We&#8217;ve had a feature request <a href=\"https:\/\/github.com\/dotnet\/fsharp\/issues\/1939\">since 2016<\/a> and several trial implementations throughout the years. Now it&#8217;s here!<\/p>\n<p><iframe title=\"F# support for Go To Definition on external symbols\" width=\"500\" height=\"375\" src=\"https:\/\/www.youtube.com\/embed\/56yqVkWS0BY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>As shown in the video, you can either use the <code>f12<\/code> key or <code>ctrl+click<\/code> to navigate to a declaration, just like in source code in your own solution.<\/p>\n<p>When you navigate, Visual Studio generates a complete <a href=\"https:\/\/docs.microsoft.com\/dotnet\/fsharp\/language-reference\/signature-files\">F# Signature File<\/a> that represents the module or namespace that the symbol lives under, with XML documentation if it is present. This allows colorization, tooltips, and further navigation to work exactly as if they had been declared as signature files in your own codebase.<\/p>\n<h2>Better mixing of C# and F# projects in your solution<\/h2>\n<p>One of the biggest annoyances when working with C# and F# projects that interoperate in the same codebase is that you need to rebuild projects to see updates in other projects if they cross the C# &lt;-&gt; F# boundary.<\/p>\n<p>Starting with the VS 16.10 release, if you make a change to a C# project, you don&#8217;t need to rebuild it to see changes in an F# project!<\/p>\n<p><iframe title=\"F# and C# interop improvements for VS 16.10\" width=\"500\" height=\"375\" src=\"https:\/\/www.youtube.com\/embed\/zvuVPe11cGE?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>As shown in the video, I can make any modification and immediately see changes in the F# project.<\/p>\n<p>The inverse is still not true today, and there remains more work to be done to make the C# &lt;-&gt; F# interop boundaries clean from a tooling standpoint. To summarize the current state of things, here&#8217;s a checklist:<\/p>\n<ul>\n<li>\u2714\ufe0f F# projects can &#8220;see&#8221; changes in C# projects without rebuilding<\/li>\n<li>\u2714\ufe0f You can Go to Definition on any C# symbol from F# and navigate to that spot in a C# codebase<\/li>\n<li>\u274c C# projects cannot &#8220;see&#8221; changes in an F# project without rebuilding<\/li>\n<li>\u274c You cannot Go to Definition on any F# symbol from C# and navigate to that spot in the F# codebase<\/li>\n<\/ul>\n<p>We&#8217;re doing more work to turn the remaining crosses into green check marks. The work is quite low-level and starts with some changes to the F# compiler and will likely also involve changes in the C# tooling as well.<\/p>\n<h2>XML documentation scaffolding<\/h2>\n<p>At the start of Visual Studio 2019, we disabled a feature that allowed you to scaffold XML documentation in source due to performance concerns. The implementation was found to be a significant source of UI delays, which could be detrimental to an overall Visual Studio experience, especially if combined with large memory consumption.<\/p>\n<p>Over the span of Visual Studio 2019, we&#8217;ve made big strides in performance for the F# tools, including changing the implementation of the XML documentation scaffolding feature so it doesn&#8217;t impact UI delays anymore. So it&#8217;s now re-enabled!<\/p>\n<p>You can trigger it by typing the <code>&lt;<\/code> character within a triple-slash comment at the top of a construct, like the following video will demonstrate.<\/p>\n<p><iframe title=\"F# support for scaffolding XML docs\" width=\"500\" height=\"375\" src=\"https:\/\/www.youtube.com\/embed\/oNXSfoBeEnw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h2>More quick fixes and refactorings<\/h2>\n<p>Like the last release, we&#8217;re bringing in some more quick fixes and refactorings for the VS 16.10 release!<\/p>\n<h3>Remove unused binding quick fix<\/h3>\n<p>If you have an unused binding in any scope, we&#8217;ll offer to remove it for you if it&#8217;s considered removable:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/05\/fsharp-1.png\" alt=\"Remove unused binding code fix\" \/><\/p>\n<h3>Use proper inequality operator quick fix<\/h3>\n<p>Some beginners from other languages might use <code>!=<\/code> and get confused by the error it produces. This quick fix will correct their operator usage to use <code>&lt;&gt;<\/code>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/05\/fsharp-2.png\" alt=\"Use proper inequality operator code fix\" \/><\/p>\n<h3>Add type annotation to object of indeterminate type quick fix<\/h3>\n<p>The F# compiler can give a confusing error, where code technically doesn&#8217;t compile, but the <em>F# tools<\/em> can actually infer a type that the compiler can&#8217;t. This quick fix will bring that known type into a suggestion:<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/05\/fsharp-3.png\" alt=\"Add type annotation to object of indeterminate type quick fix, F# and F# tools update for Visual Studio 16.10\" width=\"1130\" height=\"477\" \/><\/p>\n<h3>Add type annotation refactoring<\/h3>\n<p>Finally, we&#8217;ve added the first refactoring in the F# tools for Visual Studio. Refactorings are different from quick fixes in that they aren&#8217;t triggered by warnings or errors. Instead, lightbulbs (with no error icon next to them) indicate that a code refactoring is available at your cursor position.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/05\/fsharp-4.png\" alt=\"Add type annotation refactoring\" \/><\/p>\n<h2>Even more tooling performance and responsiveness<\/h2>\n<p>Just like the past several Visual Studio releases, we&#8217;re continuing to chip away at tooling performance and responsiveness for larger codebases.<\/p>\n<h3>Reduced memory usage<\/h3>\n<p>We identified another &#8220;win&#8221; for memory usage for large solutions. When Visual Studio colors constructs in an open document, this is actually the result of a process known as &#8220;classification&#8221;. Classification runs in two passes:<\/p>\n<ol>\n<li>Syntactical classification<\/li>\n<li>Semantic classification<\/li>\n<\/ol>\n<p>Syntactical classification can do things like identify keywords from non-keyworks. It&#8217;s very lightweight because it doesn&#8217;t require typechecking anything. You may notice for a very, very large file that keywords are colored before types are colored.<\/p>\n<p>Semantic classification is an expensive operation. It does things like distinguish classes, structs, enums, methods, properties, etc. The end result is more nuanced colorization in a document. However, since it is typically the first semantic operation kicked off by a language service, it also fills caches.<\/p>\n<p>One of the caches used by semantic classification is the actual classification information itself. This information used to be stored in one big array. This could consume significant RAM over time (especially if you have a lot of large documents open). To address this, we backed the data with a memory-mapped file, an approach we&#8217;ve taken for several other large stores of data in the F# tools for Visual Studio. This has lead to savings of up to 200MB in the F# codebase, depending on how many files are open in a Visual Studio session.<\/p>\n<p>This change was contributed by <a href=\"https:\/\/github.com\/dr0pdb\">Saurav Tiwary<\/a>. Thanks, Saurav!<\/p>\n<h3>More IDE features respond immediately<\/h3>\n<p>Last release, we started some work in the F# language service to <a href=\"http:\/\/(https:\/\/devblogs.microsoft.com\/dotnet\/f-and-f-tools-update-for-visual-studio-16-9\/#improved-responsiveness-for-most-ide-features\" rel=\"noopener\" target=\"_blank\">make requests for semantic information no longer serial<\/a>. As a refresher, the machinery involved serializes requests that require semantic information because there may be a circumstance where a typechecking operation can have downstream effects. It uses a queue to process requests in order. In practice, however, this approach is rarely necessary. In this release, we&#8217;ve pulled even more operations off of this queue.<\/p>\n<p>With these changes, you should notice that tooling features in larger codebases react to your inputs faster than before, especially in larger codebases.<\/p>\n<h2>Core compiler improvements<\/h2>\n<p>Finally, we&#8217;ve got some more compiler improvements to share!<\/p>\n<h3>Support for WarnOn in project files<\/h3>\n<p>Prior to this release, if you wanted to introduce warnings for specific compiler codes, you&#8217;d have to use <code>--warnon:number<\/code> in an <code>OtherFlags<\/code> property in your project file.<\/p>\n<p>You can now just use <code>WarnOn<\/code> and pass the numbers directly in, just like in C#.<\/p>\n<p>This was implemented by <a href=\"https:\/\/github.com\/baronfel\">Chet Husk<\/a>. Thanks, Chet!<\/p>\n<h3>Support for ApplicationIcon in project files<\/h3>\n<p>Prior to this release, setting <code>ApplicationIcon<\/code> in F# project files would do nothing.<\/p>\n<p>Now, you can set this property in a project file just like in C#. A compiler flag, <code>--win32icon<\/code>, was also added.<\/p>\n<p>This was implemented by <a href=\"https:\/\/github.com\/albert-du\">albert-du<\/a>. Thanks!<\/p>\n<h3>More span optimizations<\/h3>\n<p><a href=\"https:\/\/github.com\/thinkbeforecoding\">J\u00e9r\u00e9mie Chassaing<\/a> implemented a lovely optimization for looping over a <code>Span<\/code>\/<code>ReadOnlySpan<\/code>.<\/p>\n<p>The following F# code:<\/p>\n<pre><code class=\"language-fsharp\">let sumArray (vs: int ReadOnlySpan) =\r\n    let mutable sum = 0\r\n    for i in 0 .. vs.Length-1 do\r\n        sum &lt;- sum + vs.[i]\r\n    sum<\/code><\/pre>\n<p>Now emits cleaner IL that removes a bounds check, allowing the runtime to more aggressively optimize the loop. This optimization also applies to <code>for x in xs do<\/code> loops.<\/p>\n<h2>Looking forward<\/h2>\n<p>With this release, we&#8217;re officially shifting gears to support three initiatives:<\/p>\n<ol>\n<li>Great support for F# in .NET 6<\/li>\n<li>Great support for F# in .NET Interactive<\/li>\n<li>Great support for F# in Visual Studio 2022<\/li>\n<\/ol>\n<p>For the first initiative, we&#8217;re going to lock down on the language features we intend on releasing with soon. We&#8217;re not intending on adding many language features this time. We feel that there is more value in core compiler improvements and core tooling improvements (F# interactive, Visual Studio) right now. <a href=\"https:\/\/github.com\/dotnet\/core\/blob\/main\/release-notes\/6.0\/README.md\" rel=\"noopener\" target=\"_blank\">.NET 6 is an LTS release<\/a>, we&#8217;re prioritizing existing feature-completeness, performance, and reliability. That doesn&#8217;t necessarily mean a feature freeze. In fact, we may also end up releasing a &#8220;compiler feature&#8221; or two, especially when related to improving build times. But it does mean that the set of new language features will be smaller when compared to F# 5. When we have a finalized set of language changes going into .NET 6, we&#8217;ll announce it and the version number that we&#8217;ll assign the release.<\/p>\n<p>For the second initiative, we&#8217;re focused mainly on making sure that F# code gives great output (plaintext, charting), has great tooling (intellisense, tooltips), and gives a good experience using a broad set of libraries, especially those tailored towards data science and machine learning. To that end, we&#8217;ve already accomplished much of what we intend to do, especially in supporting some exotic package layouts for bringing in different packages with native dependencies. But there is still work to be done, such as ensuring tooling experiences (completion, tooltips, etc.) all work well. We&#8217;re committed to delivering an incredible F# experience when .NET Interactive releases in GA.<\/p>\n<p>Lastly, we&#8217;re heavily focused on making sure we deliver a great F# experience in Visual Studio 2022. Since Visual Studio 2022 is going to be 64-bit, that means that there will be higher memory usage when compared to today. We have a lot of performance analysis work ahead of us. Our preliminary builds indicate that memory usage is ~2x when loading the F# codebase and running an expensive operation like Find All References. We are committed to bringing this factor down as much as possible. On top of that, we want to continue to iterate on Visual Studio productivity features and bring features like Inline Hints, better C# interop, faster build times, and more.<\/p>\n<p>Stay tuned, and happy F# coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio 16.10 comes with more updates to the F<\/p>\n","protected":false},"author":678,"featured_media":33081,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685],"tags":[4,73,7227,147],"class_list":["post-33080","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","tag-net","tag-f","tag-f-tools","tag-visual-studio"],"acf":[],"blog_post_summary":"<p>Visual Studio 16.10 comes with more updates to the F<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/33080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/678"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=33080"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/33080\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/33081"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=33080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=33080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=33080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}