-
Notifications
You must be signed in to change notification settings - Fork 124
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
Code actions for marking & removing unused code #502
Conversation
d689c60
to
44a1316
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. A few small tweaks and it should be good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code actions don't work for me since the error messages have the form (after rebasing to the latest master):
I guess we could search for a substring but pessimistic about such solution's performance. Wdyt?
There are a couple more changes that I have in mind before merging the PR, which I'll add tomorrow hopefully
ocaml-lsp-server/test/e2e/__tests__/textDocument-codeAction.test.ts
Outdated
Show resolved
Hide resolved
This still needs some changes to pick up the right error messages. How does ocamllsp decide which diagnostics to show? I have a test project with all warnings turned on, but I only see a subset of them in my editor. When I build with dune I see all of the warnings. |
I know that ocaml-lsp uses merlin to get the warnings, but I'm not sure how
merlin decides which warnings to show -- it may either get configs from
dune or have only support for some of the warnings
…On Tue, 7 Sept 2021 at 18:33, Jack Feser ***@***.***> wrote:
This still needs some changes to pick up the right error messages.
How does ocamllsp decide which diagnostics to show? I have a test project
with all warnings turned on, but I only see a subset of them in my editor.
When I build with dune I see all of the warnings.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#502 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD4YR62CWBYU3HMMIC6CJLLUAY5FVANCNFSM5DMGP5UQ>
.
|
My understanding is that merlin gets configs from dune (through dune ocaml-merlin?). So I'm not sure why it's not picking up my dune file config. |
It seems that merlin is in fact seeing my config. However, it doesn't support most of the "unused X" warnings. Supported: 26, 27 Not sure how hard it would be to get support for 32-37 into merlin. |
Can you upload the project where you're testing this stuff? AFAIK, merlin doesn't special case any warnings and just reads the warning config from dune. |
https://github.com/jfeser/warnings-test Merlin doesn't special case warnings, but I think they only hook into certain parts of the compiler (ocaml/merlin#343). They also do some filtering (ocaml/merlin#419). |
In that case what you have is fine. Soon, some diagnostics will come directly from the dune build so your code actions will be picked up from there. |
That's good to hear. @ulugbekna Have another look. The code actions should work now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the code looks much better and works like a charm! :-)
Importantly, I think that these two code actions are activated in a very similar setting & should be combined to avoid duplicate work of filtering diagnostics.
Regarding testing, ideally, we would pass code to ocaml-lsp, get diagnostics for the code, and use those real diagnostics to test the code. Thus, we would catch if the diag messages for warnings 26 and 27 are changed.
I also left some suggestions inline.
1704923
to
5360fcb
Compare
We should better handle patterns.
We need to inspect the context in which we propose the code action. Ideally, we should do that in the same pattern match as
Importantly, I think we don't need to handle
Only on build we get a warning 32 about unused val declaration. I think there is also a dangling file |
Good catch. I think that should be fixed now.
Yep, this would be a nice addition.
Would this be
Yep, removed. |
263fb86
to
aa8b52d
Compare
values, types, modules, opens
aa8b52d
to
6286a66
Compare
merging to avoid making the author resolve more merge conflicts. if any other improvements are necessary, please continue them in separate PR's. |
CHANGES: ## Fixes - Ppx processes are now executed correctly (ocaml/ocaml-lsp#513) ## Breaking Change - ocamllsp drops support for `.merlin` files, and as a consequence no longer depends on dot-merlin-reader. (ocaml/ocaml-lsp#523) ## Features - New code action to automatically remove values, types, opens (ocaml/ocaml-lsp#502)
Adds code actions for marking unused code (i.e. by prepending '_' to variable names) and for removing unused code. Currently it can remove unused types, modules, opens, constructors, and variables.