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

When removing a file clear its diagnostics #1005

Merged

Conversation

MangelMaxime
Copy link
Contributor

Related to ionide/ionide-vscode-fsharp#1768

This PR apply the fix suggested by @Krzysztof-Cieslak on ionide/ionide-vscode-fsharp#1768 (comment)

fsac_clear_diag_when_removing_file.mp4

It works however, if user start to edit the file again. New diagnostics are computed for this file. I believe that we need to remove/clear/unregister something else too.

Example:

fsac_new_diag_generated_after_removing_file.mp4

Editing the file should not generate diagnostics for Log.fs file.

@Booksbaum
Copy link
Contributor

It works however, if user start to edit the file again. New diagnostics are computed for this file. I believe that we need to remove/clear/unregister something else too.

Issue might be: ProjectOptions for that file are still cached -> might still behaves like it's part of project.
https://github.com/fsharp/FsAutoComplete/blob/680a95b9d02c330d5b8a3a459271cc532efb368c/src/FsAutoComplete.Core/State.fs#L152
https://github.com/fsharp/FsAutoComplete/blob/680a95b9d02c330d5b8a3a459271cc532efb368c/src/FsAutoComplete.Core/Commands.fs#L702-L756
-> try Remove Projects options for that file with state.RemoveProjectOptions(file)


Editing the file should not generate diagnostics for Log.fs file.

Why not? It's still a F# file inside current workspace -- just without project.
If anything there should be MORE diagnostics: All previous references (to stuff in other files or dependencies) should now be invalid -> more errors
(I know: not how project-less fs-files currently behave -- but would be great to get errors (including maybe a Not part of a project error). Currently dangling fs-files are a bit strange: completion & tooltips (and even CodeFixes) work -- but no diags...)

@MangelMaxime
Copy link
Contributor Author

Editing the file should not generate diagnostics for Log.fs file.

Why not? It's still a F# file inside current workspace -- just without project. If anything there should be MORE diagnostics: All previous references (to stuff in other files or dependencies) should now be invalid -> more errors (I know: not how project-less fs-files currently behave -- but would be great to get errors (including maybe a Not part of a project error). Currently dangling fs-files are a bit strange: completion & tooltips (and even CodeFixes) work -- but no diags...)

What I mean is it should not generates diagnostics as if the file was still part of the project.

It should consider the file independent.

@MangelMaxime MangelMaxime changed the title [Need help] When removing a file clear its diagnostics When removing a file clear its diagnostics Aug 30, 2022
@MangelMaxime
Copy link
Contributor Author

Thank you @Booksbaum , your solution seems to be working.

@baronfel I think there still one thing left to clean which is the pipeline hints but that less invasive that the diagnostics.

image

@baronfel
Copy link
Contributor

baronfel commented Sep 3, 2022

The build errors are formatting related, run dotnet run --project build -t Format to handle that part.

The changes look reasonable to me, I'd need to check in Ionide but I think those are computed at the same time codelens are, s if you also send the 'workspace/codeLens/refresh' notification (from the LspClient) to get the editor to re-request those.

@MangelMaxime
Copy link
Contributor Author

I also get bitten by the formatting issues.

If the formatting is required I think it be easier it was just run by default on the changed files instead of failing later.

In one of my project, I started using Husky.Net which allow to add git hooks and others stuff in your project.

With a Husky task like this one:

{
   "tasks": [
      {
         "name": "dotnet-format",
         "command": "dotnet",
         "args": [ "fantomas", "${staged}" ],
         "include": [ "**/*.fs", "**/*.fsi" ]
      }
   ]
}

and this pre-commit code dotnet husky run --name dotnet-format every time make a commit then all the files that have been staged are formatted before the commit is applied.

The only step required to have that working is to restore the dotnet tools and I think call dotnet husky install once so it can register some stuff. That could be done when restoring the package.

What do you think about this workflow?

@baronfel
Copy link
Contributor

baronfel commented Sep 3, 2022

My initial thoughts are

  • agree with a pre-commit hook,
  • I'm concerned about introducing Husky - we already have Fake (though its use in the repo is diminishing) and I don't have a good idea about which would be used when

Go ahead and add it and we can see how it looks

@MangelMaxime
Copy link
Contributor Author

It is possible to not use Husky and directly attach to the git hook mechanism.

However, we will need to handle more logic as we will not "benefit" from the Husky task runner. I will have a look at what this involve and if possible show both implementation for comparaison.

@MangelMaxime
Copy link
Contributor Author

Hello @baronfel

I don't think the failing tests are related to my changes. If yes, don't hesitate to tell me :)

This PR should be ready to be merged. The issues we discussed about the auto formatting will be addressed in another PR.

@baronfel
Copy link
Contributor

baronfel commented Oct 5, 2022

I agree on all counts. Going to kick the CI again since I know some of those failures are transient, and then we'll merge.

Thank you for your time and attention on this!

…ions

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.
@baronfel baronfel force-pushed the fix/remove_diags_when_removing_file branch from c66d184 to f3e1b23 Compare October 20, 2022 02:02
@baronfel
Copy link
Contributor

force-pushed a merge resolution that also applies the fix to the new adaptive LSP server

@baronfel baronfel merged commit addc6ad into ionide:main Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants