dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 655 forks source link

Rename file code fix doesn't work #1195

Open jchannon opened 7 years ago

jchannon commented 7 years ago

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-rc4-004706)

Product Information:
 Version:            1.0.0-rc4-004706
 Commit SHA-1 hash:  e38bc4950c

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.11
 OS Platform: Darwin
 RID:         osx.10.11-x64
 Base Path:   /usr/local/share/dotnet/sdk/1.0.0-rc4-004706

VS Code version:1.9.0 C# Extension version:1.7.0-beta4

Steps to reproduce

Have a file called Foo.cs and a class declaration inside called Bar. In the context menu choose Rename file to Bar.cs

Expected behavior

The file is renamed

Actual behavior

Nothing happens. Omnisharp logs contains the below but no file is renamed.

       ************ Request ************
POST - /v2/getcodeactions
************ Headers ************
Content-Type - application/json
************  Body ************
{
  "Filename": "/Users/jonathan/Projects/twittermw/tests/Fred.cs",
  "Selection": {
    "Start": {
      "Line": 3,
      "Column": 18
    },
    "End": {
      "Line": 3,
      "Column": 21
    }
  }
}
[dbug]: OmniSharp.Middleware.LoggingMiddleware
        ************  Response ************ 
{"CodeActions":[{"Identifier":"Rename type to Fred","Name":"Rename type to Fred"},{"Identifier":"Rename file to fff.cs","Name":"Rename file to fff.cs"}]}
[dbug]: OmniSharp.Middleware.LoggingMiddleware
        ************ Request ************
POST - /v2/runcodeaction
************ Headers ************
Content-Type - application/json
************  Body ************
{
  "Filename": "/Users/jonathan/Projects/twittermw/tests/Fred.cs",
  "Selection": {
    "Start": {
      "Line": 3,
      "Column": 18
    },
    "End": {
      "Line": 3,
      "Column": 21
    }
  },
  "Identifier": "Rename file to fff.cs",
  "WantsTextChanges": true
}
[trce]: OmniSharp.Host.Loader.AssemblyLoader
        Assembly loaded: Microsoft.CodeAnalysis.Features, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
[trce]: OmniSharp.Host.Loader.AssemblyLoader
        Assembly loaded: Microsoft.CodeAnalysis.CSharp.Features, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
[info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.RunCodeActionService
        Applying code action: Rename file to fff.cs
[dbug]: OmniSharp.Middleware.LoggingMiddleware
        ************  Response ************ 
{"Changes":[]}
DustinCampbell commented 7 years ago

Thanks for the report @jchannon

DustinCampbell commented 7 years ago

I can imagine why this would fail. Essentially, the service in omnisharp-roslyn gathers up all of the text changes and sends them back to the editor host (in this case, C# for VS Code) to apply. However, in this case, there aren't any text changes, just a file rename. This is something we'll need to handle in omnisharp-roslyn.

rchande commented 6 years ago

This should be fixed as of https://github.com/OmniSharp/omnisharp-vscode/pull/1805

DustinCampbell commented 6 years ago

Unless we've added code to tell VS Code to apply a file rename, I wouldn't expect this to be fixed.

DustinCampbell commented 6 years ago

@rchande : Please check the repro. This is about the Rename File code fix, which still does not work.

rchande commented 6 years ago

@DustinCampbell You're right, this is a different bug. Thanks for noticing :)

chtenb commented 2 years ago

The error message it gives me in a toaster is

Unable to open 'INewName.cs': Unable to read file 'c:\Users\...\INewName.cs' 
(Error: Unable to resolve non-existing file 'c:\Users\...\INewName.cs').

It's a pretty weird error, since the INewName.cs indeed is supposed not to exist. It's the one that should be written.

jptissot commented 2 years ago

The error message it gives me in a toaster is

Unable to open 'INewName.cs': Unable to read file 'c:\Users\...\INewName.cs' 
(Error: Unable to resolve non-existing file 'c:\Users\...\INewName.cs').

It's a pretty weird error, since the INewName.cs indeed is supposed not to exist. It's the one that should be written.

I am having this exact same issue.

hahn-kev commented 2 years ago

This is very strange. I decided I wanted to fix this issue, I started by reproducing with the current release version which I was able to do easily. Next I got the code running on my machine, however when I try to reproduce the bug it doesn't happen even if I do a prod build with the current release version v1.24.4 checked out. I'm not really sure how to properly debug the production version of the extension so idk what's going on.

I did see this error in the dev tools console.

rejected promise not handled within 1 second: "System.ArgumentException: 'A.cs' is not open.
   at Microsoft.CodeAnalysis.Workspace.CheckDocumentIsOpen(DocumentId documentId)
   at Microsoft.CodeAnalysis.Workspace.OnDocumentClosed(DocumentId documentId, TextLoader reloader, Boolean updateActiveContext)
   at OmniSharp.OmniSharpWorkspace.CloseDocument(DocumentId documentId) in D:\\a\\1\\s\\src\\OmniSharp.Roslyn\\OmniSharpWorkspace.cs:line 102
   at OmniSharp.Roslyn.CSharp.Services.Files.FileCloseService.Handle(FileCloseRequest request) in D:\\a\\1\\s\\src\\OmniSharp.Roslyn.CSharp\\Services\\Files\\FileCloseService.cs:line 23
   at OmniSharp.Endpoint.EndpointHandler`2.<AggregateResponsesFromLanguageHandlers>d__18.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 164
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OmniSharp.Endpoint.EndpointHandler`2.<HandleRequestForLanguage>d__20.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 227
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OmniSharp.Endpoint.EndpointHandler`2.<Process>d__16.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 131
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OmniSharp.Stdio.Host.<HandleRequest>d__14.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Stdio\\Host.cs:line 218"

this shows up a few seconds after vscode tries to open the file C.cs which is what the new file would have been called.