From 51933f5242fa2bb046953909137af5f517d77aa2 Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Tue, 30 Aug 2022 16:53:01 +0200 Subject: [PATCH 1/3] When removing a file clear its diagnostics Related to https://github.com/ionide/ionide-vscode-fsharp/issues/1768 --- 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 97feebae9..52a6c9cfe 100644 --- a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs +++ b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs @@ -3709,8 +3709,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 From 99d2ab9ac6fd831c69b84487f47789a87f2108bc Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Tue, 30 Aug 2022 23:35:00 +0200 Subject: [PATCH 2/3] 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. --- src/FsAutoComplete.Core/Commands.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FsAutoComplete.Core/Commands.fs b/src/FsAutoComplete.Core/Commands.fs index 3433211fd..8bc3d549b 100644 --- a/src/FsAutoComplete.Core/Commands.fs +++ b/src/FsAutoComplete.Core/Commands.fs @@ -1346,7 +1346,7 @@ type Commands(checker: FSharpCompilerServiceChecker, state: State, hasAnalyzers: member _.FsProjRemoveFile (fsprojPath: string) (fileVirtPath: string) (fullPath: string) = async { FsProjEditor.removeFile fsprojPath fileVirtPath - state.RemoveProjectOptions(normalizePath fullPath) + state.RemoveProjectOptions (normalizePath fullPath) return CoreResponse.Res() } From f3e1b23c5bd0bce70a51a0ec50ac7a725d8822a8 Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Sat, 3 Sep 2022 20:59:48 +0200 Subject: [PATCH 3/3] Fix formatting issues --- src/FsAutoComplete.Core/Commands.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FsAutoComplete.Core/Commands.fs b/src/FsAutoComplete.Core/Commands.fs index 8bc3d549b..3433211fd 100644 --- a/src/FsAutoComplete.Core/Commands.fs +++ b/src/FsAutoComplete.Core/Commands.fs @@ -1346,7 +1346,7 @@ type Commands(checker: FSharpCompilerServiceChecker, state: State, hasAnalyzers: member _.FsProjRemoveFile (fsprojPath: string) (fileVirtPath: string) (fullPath: string) = async { FsProjEditor.removeFile fsprojPath fileVirtPath - state.RemoveProjectOptions (normalizePath fullPath) + state.RemoveProjectOptions(normalizePath fullPath) return CoreResponse.Res() }