Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode OmniSharp/C# intellisense does not see Ionide/F# lib modules/namespaces

I am using VSCode-Insiders and OmniSharp C# intellisense does not see F# types/modules/namespaces. Here is simple project:

module T1

let t = 42

And C#:

using System;

namespace flowRunner
{
    class Program
    {
      static void Main(string[] args)
        {
            Console.WriteLine(T1.t);
        }
    }
}

Build through command line with dotnet build works fine. Also dotnet run works fine too. And debugging in VS Code works. But intellisense shows:

intellisense problem

Question: How can I fix this? I have similar problem on bigger solution and it is very annoying when you have 1K errors all around which are not errors.

Also, what I noticed that this happened starting from some timepoint (assuming with some new version of IDE and/or Extension etc).

Omnisharp log (a part of it, but there is no errors or warns):

[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Visual Studio Build Tools 2017 15.9.28307.812 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
            2: StandAlone 16.0 - "C:\Users\dvitel\.vscode-insiders\extensions\ms-vscode.csharp-1.21.1\.omnisharp\1.34.2\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'C:\Users\dvitel\.vscode-insiders\extensions\ms-vscode.csharp-1.21.1\.omnisharp\1.34.2\.msbuild\Current\Bin\MSBuild.exe'

Also, I did not found any entry in logs dropdown for Ionide (I am pretty sure it existed some time before).

Projects are configured to have TargetFramework net45. But I tried also netcoreapp2.2 - it did not work.

Configuration. VS Code - Insiders:

Version: 1.38.0-insider (user setup)
Commit: 185308c0dd317d73fe4c19dea347582dee9650de
Date: 2019-08-26T09:46:11.283Z
Electron: 4.2.9
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362

Extensions (and their versions):

used extensions

.NET Core SDK:

PS C:\Users\dvitel\Documents\Visual Studio 2019\SO> dotnet --info
  Version: 2.2.6
  Commit:  7dac9b1b51

.NET Core SDKs installed:
  2.0.0 [C:\Program Files\dotnet\sdk]
  2.1.200 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
like image 382
dvitel Avatar asked Aug 27 '19 00:08

dvitel


2 Answers

I think I found the answer. Omnisharp log states that it uses Standalone 16.0 MSBuild instance. As I found on github, some people dealt with same problem. For example here guy solved the issue but installing VS Build tools 2017 with F Sharp compiller.

From his Ominsharp log, Visual Studio Build Tools 2017 15.3.26730.15 instance was selected. So I made an assumption that there is an issue with msbuild which is delivered with omnisharp.

Unfortunatelly I did not find normal method how to select other MSBuild instance or change MSBUILD_EXE_PATH (tried omnisharp.json - did not work), so I just renamed .msbuild folder of Standalone 16.0. It took VS MSBUild instance, but gave errors "SDK 'Microsoft.NET.Sdk' specified could not be found", so I ran VS Installer and added .NET Core build tools.

After this intellisence works fine with <ProjectReference Include="..\flow\flow.fsproj" />

works

like image 178
dvitel Avatar answered Oct 12 '22 11:10

dvitel


It's frustrating but essentially Omnisharp doesn't support F# so there's not much we can do to get it working at design time from what I can tell.

To fix intellisense you can build the dll of the fsharp project and reference it from your .csproj. If you need to hop back and forth from C# to F#, you can set up scripts (either triggered from the command line or tasks in vscode) and watchers (e.g. dotnet watch build) to rebuild the F# project. Then use the Omnisharp: Restart Omnisharp command to refresh and it should pick it up.

Disclaimer: I'm a beginner.

like image 43
drkmtr Avatar answered Oct 12 '22 12:10

drkmtr