ionide-vscode-fsharp
ionide-vscode-fsharp copied to clipboard
"The namespace or module '...' is not defined" despite module existing
Describe the bug
There is syntax highlighting with the error message of "The namespace or module '...' is not defined" despite the module existing in that exact version in my local files. When I build the program or run the tests (the file with the error is my test.fs file), everything works fine, but I get this annoying syntax highlighting.
Steps to reproduce
- Have a file that imports packages.
Link to sample reproduction
Expected behaviour
No syntax highlighting
Screenshots
Module highlighting:
Resulting highlighting:
Machine info
- OS: Windows 11
- .NET SDK version: Appears on 6.0.309 and 7.0.201
- Ionide version: 7.5.1
Additional context
If you want the exact files, I can share them with you. Just let me know.
Hello @CanePlayz,
Does the error goes away if you quit and restart VSCode?
As a workaround can you try the following:
Workaround 1
- Save/Commit the work you don't to lose
- Clean your temporary files
git clean -xdf
- Run
dotnet build
to try forcing Ionide to update
Workaround 2
- Save/Commit the work you don't to lose
- Clean your temporary files
git clean -xdf
- Quit and restart Ionide
Sometimes I need to do stuff like that on some of my projects.
Does the error goes away if you quit and restart VSCode?
Unfortunately, no. Sometimes, it does find the modules. And something that is different in those scenarios is that there is a file called something like NET Testing SDK...However, that might just be a side effect of the project finding the file, because that file only gets auto-generated when the module is found, and not the other way around (the file helping Ionide).
Thanks for the workarounds, however, they don't apply in this case since this is not a Git project. It's basically many very tiny projects, just exercises from university, only consisting of a .fsproj. and two to three .fs files. Building and restoring work fine, but unfortunately, they don't make the highlighting go away either.
The clean command is because in general you add the bin
and obj
folders to the gitignore file.
If you don't use Git, you can always remove the bin
and obj
folders manually or using the CLI.
The clean command is because in general you add the
bin
andobj
folders to the gitignore file.If you don't use Git, you can always remove the
bin
andobj
folders manually or using the CLI.
Yeah, thanks, I do that anyways on a regular basis with a little script.
Do you want one of those projects to see if you can replicate the issue?
I had the same issue with the default SAFE template, enabling Adaptive Lsp Server
fixed it for me (https://github.com/ionide/ionide-vscode-fsharp/issues/1852#issuecomment-1469005519)
Issue still persists with Adaptive Lsp Server enabled, unfortunately. It's also weird that on some of the exercise projects, it finds the modules, despite them not being any different from the other ones as far as I can see.
After running "dotnet test" once (which runs the tests specified in the file with the syntax highlighting), it finds the modules. That works as a workaround, but in a perfect world, it should find the modules from the beginning (as they are already installed locally before the "dotnet test").
Can you submit a repository that reproduces this issue?
Can you submit a repository that reproduces this issue?
You can find the project here: https://github.com/CanePlayz/Ionide-Test
After a dotnet restore
I cannot get this to reproduce.
https://user-images.githubusercontent.com/1490044/227225283-f949fc26-fa1e-44b6-a9fc-3a381781ea0b.mp4
Maybe there's something weird about your install of dotnet. What's dotnet --info
?
After a
dotnet restore
I cannot get this to reproduce.
Me neither anymore. Maybe something fixed it. It always finds the modules now after a dotnet restore
. But why does it need that dotnet restore
if the packages are already installed?
What's
dotnet --info
?
.NET SDK:
Version: 7.0.202
Commit: 6c74320bc3
Laufzeitumgebung:
OS Name: Windows
OS Version: 10.0.25314
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.202\
Host:
Version: 7.0.4
Architecture: x64
Commit: 0a396acafe
.NET SDKs installed:
6.0.407 [C:\Program Files\dotnet\sdk]
7.0.202 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Restore doesn't just download nuget packages, more importantly it creates several metadata files (like project.assets.json) in the Intermediate Output Path
of each project that are required in order to provide intellisense for the files in that project. The fact that performing a restore outside of the editor cleared things up for you makes me think that our automatic restore-triggering in FSAC isn't working consistently.
Restore doesn't just download nuget packages, more importantly it creates several metadata files (like project.assets.json) in the
Intermediate Output Path
of each project that are required in order to provide intellisense for the files in that project. The fact that performing a restore outside of the editor cleared things up for you makes me think that our automatic restore-triggering in FSAC isn't working consistently.
I see, that'd make sense. Could it be a problem that I have script that deletes all of the bin
and obj
folders every once in a while?
Thank you for this thread. I've been losing my mind. "dotnet restore".
@MangelMaxime I cannot reproduce this anymore. Should we close this issue?
I still get this issue. It's always after I add a new .fs
file to my .fsproj
. The reported error is usually to do with an included project like this:
<ProjectReference Include="../../../sutil/src/Sutil/Sutil.fsproj"/>
I would discount installation of .NET etc because it still happens even after installing a brand new laptop (the thinking being that having followed standard installation procedures on a new machine, there's been little to no chance for the .net install to get funky).
I'd be happy to try and make a repro project if that would help?
Yeah, I also just remembered that this was not just about modules not being found in general, but also about not finding them before doing a manual dotnet restore
, which is still necessary but shouldn't be.
Also worth noting that when I have a folder with multiple projects opened, I need to do dotnet restore
for all of them individually for Ionide to recognize the packages (even though they're the same packages). However, when I close the folder and reopen it, it seems to "remember" which projects have been restored.