Ionide-vscode-fsharp: Rename of function and type does not work

Created on 4 Dec 2019  路  19Comments  路  Source: ionide/ionide-vscode-fsharp

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.

bug language services

Most helpful comment

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.

All 19 comments

Hey @stoft :wave:,

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 :smile:

This should be fixed in 4.4.4

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

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\test2test.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\test2test.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\test2test.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\test2test.fsx, State@{"Value": 5, "$type": "Some"}, Checked@{"Value": 5, "$type": "Some"}
[15:58:48.707 DBG] [Commands] TryGetLatestTypeCheckResultsFor c:\Users\nicho\Dropbox\Research\test2test.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\test2test.fsx"
[15:58:48.707 VRB] [Checker] Current Queue Length is 0
[15:58:48.707 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2test.fsx"
[15:58:48.707 VRB] [Checker] Current Queue Length is 0
[15:58:48.707 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2test.fsx"
[15:58:48.707 VRB] [Checker] Current Queue Length is 0
[15:58:48.707 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2test.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\test2test.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\test2test.fsx"
[15:58:49.388 DBG] [Commands] TryGetLatestTypeCheckResultsFor c:\Users\nicho\Dropbox\Research\test2test.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\test2test.fsx"
[15:58:49.388 VRB] [Checker] Current Queue Length is 0
[15:58:49.388 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2test.fsx"
[15:58:49.388 VRB] [Checker] Current Queue Length is 0
[15:58:49.388 INF] [Checker] TryGetRecentCheckResultsForFile - "c:\Users\nicho\Dropbox\Research\test2test.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\test2test.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\test2test.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\test2test.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.

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

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.

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.

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" } ] }

@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

@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?

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

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

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

Glad that things are ok for you all :)

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.

@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 https://github.com/ionide/ionide-vscode-fsharp/issues/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?

@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.

@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

@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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lilred picture lilred  路  6Comments

sergey-tihon picture sergey-tihon  路  6Comments

cartermp picture cartermp  路  4Comments

cloudRoutine picture cloudRoutine  路  5Comments

gsomix picture gsomix  路  6Comments