Skip to content

Commit

Permalink
When removing a file clear its diagnostics (#1005)
Browse files Browse the repository at this point in the history
* When removing a file clear its diagnostics

Related to ionide/ionide-vscode-fsharp#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
  • Loading branch information
MangelMaxime authored Oct 20, 2022
1 parent 4843755 commit addc6ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
4 changes: 4 additions & 0 deletions src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
7 changes: 6 additions & 1 deletion src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit addc6ad

Please sign in to comment.