From addc6ad42e32dc0cebbb01f18aa9db80f87bd249 Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Thu, 20 Oct 2022 04:19:30 +0200 Subject: [PATCH] When removing a file clear its diagnostics (#1005) * When removing a file clear its diagnostics Related to https://github.com/ionide/ionide-vscode-fsharp/issues/1768 * When removing it file from fsproj remove it also from the project options Fix bug where the file was still being consider part of the project on FSAC resulting in generating wrong diagnostic when editing the removed file. * Fix formatting issues --- src/FsAutoComplete.Core/Commands.fs | 3 ++- src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs | 4 ++++ src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/FsAutoComplete.Core/Commands.fs b/src/FsAutoComplete.Core/Commands.fs index 5afc3211e..3433211fd 100644 --- a/src/FsAutoComplete.Core/Commands.fs +++ b/src/FsAutoComplete.Core/Commands.fs @@ -1343,9 +1343,10 @@ type Commands(checker: FSharpCompilerServiceChecker, state: State, hasAnalyzers: return CoreResponse.Res() } - member _.FsProjRemoveFile (fsprojPath: string) (fileVirtPath: string) = + member _.FsProjRemoveFile (fsprojPath: string) (fileVirtPath: string) (fullPath: string) = async { FsProjEditor.removeFile fsprojPath fileVirtPath + state.RemoveProjectOptions(normalizePath fullPath) return CoreResponse.Res() } diff --git a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs index b026413b1..94e7ca004 100644 --- a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs +++ b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs @@ -3708,8 +3708,12 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar >> Log.addContextDestructured "parms" p ) + let fullPath = Path.Combine(Path.GetDirectoryName p.FsProj, p.FileVirtualPath) do! Commands.removeFile p.FsProj p.FileVirtualPath |> AsyncResult.ofCoreResponse loadedProjectOptions |> AVal.force |> ignore + let fileUri = Path.FilePathToUri fullPath + diagnosticCollections.ClearFor fileUri + return { Content = "" } with e -> logger.error ( diff --git a/src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs b/src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs index eaa723cae..b00656566 100644 --- a/src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs +++ b/src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs @@ -2636,7 +2636,12 @@ type FSharpLspServer(state: State, lspClient: FSharpLspClient) = >> Log.addContextDestructured "parms" p ) - let! res = commands.FsProjRemoveFile p.FsProj p.FileVirtualPath + let fullPath = Path.Combine(Path.GetDirectoryName p.FsProj, p.FileVirtualPath) + let! res = commands.FsProjRemoveFile p.FsProj p.FileVirtualPath fullPath + // Compute the fileUri, as this is the key used by the diagnostics collection. + let fileUri = Path.FilePathToUri fullPath + + diagnosticCollections.ClearFor fileUri let res = match res with