Omnisharp-vscode: Editor not updating reference when class file moved to new folder

Created on 21 Nov 2018  路  5Comments  路  Source: OmniSharp/omnisharp-vscode

Environment data

dotnet --info output:
.NET Core SDK (reflecting any global.json):
Version: 2.1.402
Commit: 3599f217f4

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.13-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.402/

Host (useful for support):
Version: 2.1.4
Commit: 85255dde3e

.NET Core SDKs installed:
1.0.1 [/usr/local/share/dotnet/sdk]
2.1.402 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

VS Code version:
Version 1.29.1 (1.29.1)
bc24f98b5f70467bc689abf41cc5550ca637088e

C# Extension version:
1.17.1

MacOS 10.13.6 (17G3025)

Steps to reproduce

See also animated GIF below

  1. dotnet new console
  2. Open VS Code
  3. Create root-level folders "Tests" and "Payroll"
  4. Move Program.cs to Tests folder
  5. Update Program.cs namespace to new folder
  6. Create declaration and instantiation to a variable of a new type
  7. Use CMD-. fix to generate new class in new file
  8. Move newly created file to Payroll folder
  9. Update namespace in new file
  10. Add using statement in Program.cs to reference Payroll namespace
  11. Save all files
  12. Hover over declaration statement in Program.cs. Note type can't be found and is referred to as being in Tests namespace

omnisharp

Expected behavior

New type should be found in correct namespace

Actual behavior

New type is not found in correct namespace

Other info

Restarting OmniSharp via command palate corrects issue
Related to Issue 2040?

Most helpful comment

@delroh You can use the "Restart OmniSharp" command instead of restarting Code

All 5 comments

This is really annoying! Thanks for making a nice bug report.

I was investigating this recently and found problem with vscode extension not properly reporting FileChangeEvents to o#. A lot of fileChangeEvents are simply "eaten", and I suspect a lot of it is upstream in VSCode's FileSystemWatcher.

In the example you provided: once you drag'n'drop file from folder A to B, what should happen:
1) file delete event for old filePath
2) file creation event for new filePath, creating new transient file at new filePath

what _actually_ happens:
1) no file deletion event: o# still thinks old file is alive, as if it has never been deleted
2) no file creation event at new path
3) file buffer update on new path a moment later - creating new transient file at newFilePath
4) since old path was never deleted, o# now thinks there are two files with the same content, leading to a storm of "Already defined" errors.

Also note: moving file in the same folder (renaming) dispatches file change events ok, but renaming folders / moving from folder to folder never works

I'm having a similar issue renaming classes (might be the same issue because like moving a file, the reference to it changes). Seems it caches the references and they aren't updated. The problem is solved by restarting VSCode so the extension is also reloaded and recognizes the renamed class (is there a way to reload the extension without restarting VSCode?). Another issue also happened that it was reporting that this renamed class had duplicated methods, when they weren't. Reloading VSCode fixed it. Maybe all this is related to this issue well reported here.

@delroh You can use the "Restart OmniSharp" command instead of restarting Code

@jimholmes I believe a simple version of this bug is:

  • dotnet new console
  • create a directory next to the csproj
  • move Program.cs into the new directory
  • intellisense doesn't work in Program.cs

Addressing this with https://github.com/OmniSharp/omnisharp-roslyn/pull/1368

Was this page helpful?
0 / 5 - 0 ratings