Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename of function and type does not work #1265

Closed
stoft opened this issue Dec 4, 2019 · 27 comments
Closed

Rename of function and type does not work #1265

stoft opened this issue Dec 4, 2019 · 27 comments
Labels
bug language services Problems related to language services - FSAC or FCS

Comments

@stoft
Copy link

stoft commented Dec 4, 2019

Describe the bug
F2/rename of a function name or type name simply does not work. (It does work on function parameters.)

To Reproduce
Steps to reproduce the behaviour:

  1. dotnet new console -lang F# -o RenameError
  2. cd RenameError
  3. code .
  4. Open `Program.fs``
  5. Click on the main function
  6. Press F2 (rename symbol) and type a different name
  7. Press enter

Expected behaviour
The function name is renamed to the different name.

Environment (please complete the following information):

  • OS: MacOS Catalina 10.15.1
  • Ionide version: 4.3.2
  • VSCode version: 1.40.2
  • dotnet SDK version: 3.1.100
  • mono / .Net Framework version: 6.4.0.198

Additional context
With verbose logging set to true in settings I get the following in the F# output:

[FSharpChecker] Current Queue Length: 0
[Checker] TryGetRecentCheckResultsForFile - /Users/rala/Projects/fsharp/RenameError/Program.fs
[LSP call] TextDocumentRename
[LSP] PositionHandler - Position request: /Users/rala/Projects/fsharp/RenameError/Program.fs at (6,7)
[FSharpChecker] Current Queue Length: 0
[Checker] TryGetRecentCheckResultsForFile - /Users/rala/Projects/fsharp/RenameError/Program.fs

Let me know if there are other logging or debugging settings I can tweak.

@open-collective-bot
Copy link

Hey @stoft 👋,

Thank you for opening an issue. We will get back to you as
soon as we can. Also, check out our OpenCollective and consider
backing us.

https://opencollective.com/ionide

PS.: We offer backer support for all backers. Don't forget to add backer label when you start backing us 😄

@Krzysztof-Cieslak
Copy link
Member

This should be fixed in 4.4.4

@stoft
Copy link
Author

stoft commented Jan 28, 2020

Still not fixed unfortunately. Let me know if there's any way I can help debug this.

@nhirschey
Copy link

nhirschey commented Feb 10, 2021

I am getting the same issue, rename and show references does not work on .fsx.

Repro:

  1. Create new empty folder
mkdir test
cd test
  1. Save file called test.fsx with
let x = 4.0

printfn "%A" x
  1. Try show all references or rename symbol to change x into y.

Screenshot 2021-02-10 113906

System info:
Ionide Version 5.3.2
Version: 1.53.0 (user setup)
Commit: 8490d3dde47c57ba65ec40dd192d014fd2113496
Date: 2021-02-03T20:36:38.611Z
Electron: 11.2.1
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19042

Log:

[15:58:48.090 INF] [LSP] TextDocumentHover Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "Position": {"Line": 0, "Character": 3, "$type": "Position"}, "$type": "TextDocumentPositionParams"}
[15:58:48.090 VRB] [Checker] Current Queue Length is 0
[15:58:48.090 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:48.455 INF] [LSP] TextDocumentDocumentHighlight Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "Position": {"Line": 0, "Character": 4, "$type": "Position"}, "$type": "TextDocumentPositionParams"}
[15:58:48.455 VRB] [Checker] Current Queue Length is 0
[15:58:48.455 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:48.706 INF] [LSP] TextDocumentCodeLens Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "$type": "CodeLensParams"}
[15:58:48.706 VRB] [Checker] Current Queue Length is 0
[15:58:48.706 INF] [Checker] GetDeclarations - c:\Users\nicho\Dropbox\Research\test2\test.fsx
[15:58:48.706 INF] [LSP] TextDocumentCodeAction Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "Range": {"Start": {"Line": 0, "Character": 4, "$type": "Position"}, "End": {"Line": 0, "Character": 4, "$type": "Position"}, "$type": "Range"}, "Context": {"Diagnostics": [], "$type": "CodeActionContext"}, "$type": "CodeActionParams"}
[15:58:48.707 DBG] [Commands] TryGetLatestTypeCheckResultsFor c:\Users\nicho\Dropbox\Research\test2\test.fsx, State@{"Value": 5, "$type": "Some"}, Checked@{"Value": 5, "$type": "Some"}
[15:58:48.707 DBG] [Commands] TryGetLatestTypeCheckResultsFor c:\Users\nicho\Dropbox\Research\test2\test.fsx, State@{"Value": 5, "$type": "Some"}, Checked@{"Value": 5, "$type": "Some"}
[15:58:48.707 VRB] [Checker] Current Queue Length is 0
[15:58:48.707 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:48.707 VRB] [Checker] Current Queue Length is 0
[15:58:48.707 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:48.707 VRB] [Checker] Current Queue Length is 0
[15:58:48.707 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:48.707 VRB] [Checker] Current Queue Length is 0
[15:58:48.707 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:49.387 INF] [LSP] TextDocumentCodeAction Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "Range": {"Start": {"Line": 0, "Character": 4, "$type": "Position"}, "End": {"Line": 0, "Character": 5, "$type": "Position"}, "$type": "Range"}, "Context": {"Diagnostics": [], "$type": "CodeActionContext"}, "$type": "CodeActionParams"}
[15:58:49.388 DBG] [Commands] TryGetLatestTypeCheckResultsFor c:\Users\nicho\Dropbox\Research\test2\test.fsx, State@{"Value": 5, "$type": "Some"}, Checked@{"Value": 5, "$type": "Some"}
[15:58:49.388 VRB] [Checker] Current Queue Length is 0
[15:58:49.388 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:49.388 DBG] [Commands] TryGetLatestTypeCheckResultsFor c:\Users\nicho\Dropbox\Research\test2\test.fsx, State@{"Value": 5, "$type": "Some"}, Checked@{"Value": 5, "$type": "Some"}
[15:58:49.388 VRB] [Checker] Current Queue Length is 0
[15:58:49.388 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:49.388 VRB] [Checker] Current Queue Length is 0
[15:58:49.388 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:49.388 VRB] [Checker] Current Queue Length is 0
[15:58:49.388 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:49.747 INF] [LSP] TextDocumentHover Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "Position": {"Line": 0, "Character": 4, "$type": "Position"}, "$type": "TextDocumentPositionParams"}
[15:58:49.747 VRB] [Checker] Current Queue Length is 0
[15:58:49.747 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[15:58:51.112 INF] [LSP] TextDocumentCodeLens Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "$type": "CodeLensParams"}
[15:58:51.112 VRB] [Checker] Current Queue Length is 0
[15:58:51.112 INF] [Checker] GetDeclarations - c:\Users\nicho\Dropbox\Research\test2\test.fsx
[15:58:53.910 INF] [LSP] TextDocumentRename Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "Position": {"Line": 0, "Character": 5, "$type": "Position"}, "NewName": "y", "$type": "RenameParams"}
[15:58:53.910 VRB] [Checker] Current Queue Length is 0
[15:58:53.910 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"

Server trace:

[Trace - 4:06:08 PM] Sending request 'textDocument/rename - (109)'.
Params: {
    "textDocument": {
        "uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx"
    },
    "position": {
        "line": 0,
        "character": 5
    },
    "newName": "z"
}


[16:06:08.143 INF] [LSP] TextDocumentRename Request: {"TextDocument": {"Uri": "file:///c%3A/Users/nicho/Dropbox/Research/test2/test.fsx", "$type": "TextDocumentIdentifier"}, "Position": {"Line": 0, "Character": 5, "$type": "Position"}, "NewName": "z", "$type": "RenameParams"}
[16:06:08.143 VRB] [Checker] Current Queue Length is 0
[16:06:08.143 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2\test.fsx"
[Trace - 4:06:08 PM] Received response 'textDocument/rename - (109)' in 2ms.
Result: {
    "documentChanges": []
}

@baronfel , if there's anything else that I can provide to help debug, let me know. I tried rolling back the install as far as 5.0.3 to see if I could track where it's breaking.

@bytesource
Copy link

I have the same issue. Renaming only works inside a function.

@bytesource
Copy link

Would it be possible to reopen this issue?

I tried deleting symbolCache.db, but I still cannot rename symbols in a .fsx file. Renaming only works for symbols inside a function.

If there's any data I could provide you with, just let me know, and I'll add it here.

@cartermp
Copy link
Contributor

cartermp commented Feb 20, 2021

I'll re-open this since it is trivially reproducible with @nhirschey's steps with the latest Ionide. Symbol highlighting does work - the editor can pick up that x is the same x as is defined earlier, and if you shadow it with another x it will pick up the shadowed value. I suspect there's a bug in the FSAC version used in the latest Ionide.

But it also took a little time, with the logs indicating several failures before that was working. Rename and find refs do not work, though.

@bytesource
Copy link

After updating to Ionide version 5.5.2 I tried again to rename a function name in a fsx file, but it still doesn't work. However, I now receive the following error message when pressing Enter after renaming:

Cached typecheck results not yet available

Could this be helpful in solving the issue?

Being able to rename function names is such a godsend, and I'd love to have this features available in fsx files, too.

If you need any additional information, just let me know.

EDIT:
After trying again, I received yet another error message:

Unknown workspace edit change received: { "textDocument": { "uri": "file:///d%3A/Documents/Programming/Fsharp/HSKCloze/Pinyin.fsx" }, "edits": [ { "range": { "start": { "line": 267, "character": 4 }, "end": { "line": 267, "character": 16 } }, "newText": "catSegmenter2" }, { "range": { "start": { "line": 302, "character": 24 }, "end": { "line": 302, "character": 36 } }, "newText": "catSegmenter2" } ] }

@nhirschey
Copy link

@bytesource On 5.5.2, stable (not insiders) vscode, I am able to rename and find all references successfully given the repro of the problem in my comment earlier in the thread. I can switch back and forth between renaming the variable x and y.

One time it did not work, but then I saved the file and it started working again.

Version: 1.55.2 (user setup)
Commit: 3c4e3df9e89829dce27b7b5c24508306b151f30d
Date: 2021-04-13T09:35:57.887Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19042

@bytesource
Copy link

@nhirschey, I tried what you did and... now it's working! It's fantastic!

Has this issue been fixed recently or was it just a glitch (for lack of a better term) with my setup?

@nhirschey
Copy link

I believe it was fixed in this week’s release by some off by one errors @baronfel fixed in fsautocomplete.

@baronfel I think you can close this issue. Thank you for those fixes!

@bytesource
Copy link

@nhirschey I see, that's great. @baronfel, thanks a lot for bringing back autocomplete to fsx files!

@baronfel
Copy link
Contributor

Glad that things are ok for you all :)

@LiteracyFanatic
Copy link

Rename is still broken for me with Ionide v5.5.5 and fsautocomplete v0.46.0. OS is Arch Linux. More specifically, the issue seems to happen when the type I'm trying to rename is used within an implementation of an interface for a class in a separate file. I've posted the smallest reproduction I've been able to come up with.

RenameTest.fsproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <RootNamespace>RenameTest</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Domain.fs" />
    <Compile Include="IFooPrinter.fs" />
    <Compile Include="FooPrinter.fs" />
    <Compile Include="Program.fs" />
  </ItemGroup>

</Project>

Domain.fs

namespace Domain

type Foo = {
    A: int
    B: string
}

IFooPrinter.fs

namespace Services

open Domain

type IFooPrinter =
    abstract PrintFoo: foo: Foo -> unit

FooPrinter.fs

namespace Services

open Domain

type FooPrinter() =
    interface IFooPrinter with
        member this.PrintFoo(foo: Foo) =
            printfn $"A = %i{foo.A}, B = %s{foo.B}"

Program.fs

open Domain
open Services

[<EntryPoint>]
let main argv =
    let foo = {
        A = 1
        B = "2"
    }
    let fooPrinter = FooPrinter() :> IFooPrinter
    fooPrinter.PrintFoo(foo)
    0

Opening Domain.fs and trying to rename Foo results in the following error message where the line number for the range is off by one.

Unknown workspace edit change received:
{
    "textDocument": {
        "uri": "file:///home/jordan/src/RenameTest/IFooPrinter.fs"
    },
    "edits": [
        {
            "range": {
                "start": {
                    "line": 5,
                    "character": 28
                },
                "end": {
                    "line": 5,
                    "character": 31
                }
            },
            "newText": "Bar"
        }
    ]
}

Sometimes after editing and saving FooPrinter.fs renaming starts to work, but this doesn't happen reliably.

@nhirschey
Copy link

@LiteracyFanatic you say

Sometimes after editing and saving FooPrinter.fs renaming starts to work, but this does not happen reliably.

This makes me wonder, when renaming does not work for you, is type checking working? I have found that renaming will not work and I get errors like the one you provide if type checking is broken as described in this issue #1500 (I give a script issue, but booksbaum gives a project example). However as long as the file is properly getting typechecked then renaming is fine.

Do the workarounds described in that issue to bring back type-checking cause rename to start working again for you? Specifically, closing the files, closing the folder, then reopening?

@LiteracyFanatic
Copy link

@nhirschey

Good question. While I do run into the issue you linked at times as well, I can reproduce the behavior related to renaming while type checking is working fine for me i.e. line lenses are displayed and I can hover over values to see their type information displayed. It's just the rename command which is failing. Unfortunately, I have yet to find a consistent way to fix it. I've messed around with editing and saving the file, clearing ionide's cache, and opening and closing vs code. Frustratingly, all I can say is that it will sometimes start working and other times will not. It never works when freshly cloning the example I posted though.

@nhirschey
Copy link

nhirschey commented May 23, 2021

@LiteracyFanatic see this gif. I get line lenses and hover values even though the file is not getting type checked (note the integer in the string list). And rename will also fail. But then if I do ctrl-p to bring up the command window and >Developer:reload window it reloads things and type checking + rename works.

I always get this rename error when my file is not being type-checked. I have not gotten this rename error while the file is properly type-checked. For me, the consistent fix is to close all files so that nothing is open in the editor, close the project folder, then reopen things. Booksbaum has some other ways for projects such as the developer:reload tip.

rename-typecheck-issue

@LiteracyFanatic
Copy link

@nhirschey I better understand what you mean now. I tried adding a list similar to yours and it properly typed checked and underlined the integer with red squiggles. Renaming Foo still doesn't work though.

I'm fairly certain the issue I'm experiencing is related to interface definitions specifically. I have a medium sized ASP.NET Core project that seemingly randomly refuses to let me rename things. Values inside a function work fine, but types are hit and miss. Even with two records defined in the same file, one will rename fine and the other won't. My attempts to reproduce in a test project kept failing.

Finally I realized that all of the types that wouldn't rename appeared in a class implementing an interface I was injecting into the dependency container. Any types which where only being used in functions or class members that didn't belong to an interface would rename fine. Unfortunately that means 90% of my domain and data model types won't rename.

@seanamos
Copy link

I still run into this regularly and it's quite easy to reproduce as well.
I don't get it with locally scoped variables, but with high level scopes (Modules/module level functions/types), it's quite often the rename will fail with an error:

Unknown workspace edit change received: { "textDocument": { "uri": "file:///xxx.fs" }, "edits": [ { "range": { "start": { "line": 55, "character": 26, "debuggerDisplay": "(55,26)" }, "end": { "line": 55, "character": 37, "debuggerDisplay": "(55,37)" }, "debuggerDisplay": "(55,26)-(55,37)" }, "newText": "MakeContext" } ] }

Not sure if it helps at all, but the start/end line characters don't line up with any source code. That is to say, the character runs past the length of the line. The start/end ranges also seem in the nearby vicinity of something that should get renamed (1 line+-) but are off.

@rosund2
Copy link

rosund2 commented Jan 9, 2022

I am running into this when working on scripts. Normal fs files works fine.

debug1

trying to rename logger to asd:

debug2

Windows 10, with the latest ionide

debug3

@bytesource
Copy link

Unfortunately, the issue is back for me, too.

@rosund2
Copy link

rosund2 commented Jan 10, 2022

Could maybe someone reopen this ?

@baronfel baronfel reopened this Jan 10, 2022
@kirse
Copy link

kirse commented May 14, 2022

+1 thanks for re-opening this. Seems to be a recent thing, or maybe it's because my project reached a certain level of complexity to start happening? Any way to assist with debug? This also seems to partially bork Shift+F12 (Find all Refs) and F12 (Go to Definition) as well which is pretty impactful for dev. Thanks

Before rename:
before-rename

After rename (tried to rename HandleResult to HandleResultNEW:
after-rename
!

@eyassud
Copy link

eyassud commented Jun 26, 2022

I am brand new to F# and created a brand new SAFE application and rename(F2) functionality is not working

@baronfel
Copy link
Contributor

sorry about that! we still haven't released the fix in Ionide yet. we're working on it, though!

@Krzysztof-Cieslak
Copy link
Member

7.0.0 is now released.

@forki
Copy link
Contributor

forki commented Jul 24, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug language services Problems related to language services - FSAC or FCS
Projects
None yet
Development

No branches or pull requests