-
Notifications
You must be signed in to change notification settings - Fork 198
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
Provide test running code lens #389
Conversation
apps/language_server/lib/language_server/providers/code_lens.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens.ex
Outdated
Show resolved
Hide resolved
9350593
to
b7420ea
Compare
@lukaszsamson I've pushed a new version that fixes most of the issues you brought up in your review. This new version more accurately identifies tests by making sure that the calls are within a module which imports I've found one small issue, where if a file contains multiple test modules, when running a test with the Finally, I want to apologize for the long delay. I've had a lot on my plate lately but I should be able to work on this in a more timely fashion going forward. |
apps/language_server/lib/language_server/providers/code_lens/test.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens/test.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens/test.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens/test.ex
Outdated
Show resolved
Hide resolved
I like the direction it's going. Some small fixes and we can merge it.
I don't think it's worth it to workaround mix bugs in such cornercases. Better report it upstream.
No need to apologize |
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.
First off thanks for tackling this ❤️! I haven't done a comprehensive review, but I think this is on a good path and I just have a few initial nitpicky things that I've left comments for.
I've found one small issue, where if a file contains multiple test modules, when running a test with the mix test file_path:test_line command, it will always run the corresponding test as well as the last test of all previous modules. This appears to be an issue with mix/ExUnit itself, but we might be able to work around it by providing more contextual data to the code lens (ie the module name, the test name, etc.). I've played around with this but couldn't find find a combination of mix test args that fixed this without creating some other problem.
Here's an invocation that we can use:
mix test --exclude test --include 'test:test recompiles files recompiles a file' test/cortex/reloader_test.exs
I think this would be better than relying on the line numbers because it will facilitate re-running the previous test (since the line number may have changed since the test was initially ran).
apps/language_server/lib/language_server/providers/code_lens/spec.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens/test.ex
Outdated
Show resolved
Hide resolved
|> List.last() | ||
|> elem(1) | ||
|> Map.get(:imports) | ||
|> Enum.any?(fn module -> module == ExUnit.Case end) |
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.
This probably works well, although an alternative would be to use the same configuration that ex_unit itself is using:
:test_pattern - a pattern to load test files. Defaults to
*_test.exs
To be clear I don't think we should change it at this time (unless the current code results in very poor performance or some similar concern).
Here's another update! I've had to change the way execution targets are identified to support the new test command syntax that @axelson suggested. I took a bit of work, especially finding a way to find which describe block (in any) a test belongs to, but I think it was worth it because it does indeed make for a much more comprehensive and repeatable test command. As an added bonus, using test names does not appear to suffer from the same inclusion bugs I was talking about earlier. I've also updated the docs, but I wasn't quite sure what kind of information we wanted to include in there. Suggestions for improvements are very welcome on that front! I was also wondering what the policy is on tests? From looking at the file structure, I've noticed that only a small part of the project appears to be tested. I'm gonna work on some tests for this anyway, but I still wanted to ask about it. Finally, I'll open a PR on vscode-elixir-ls to make use of this soon, I just got to review my code to make sure it's clean first. P.S. Should I resolve the opened conversations on the PR as I address them or do you guys want to take care of that once you've reviewed? |
Here's the PR for vscode-elixir-ls: elixir-lsp/vscode-elixir-ls#155 |
Also, I was working on unit tests that I'd like to push before this gets merged! I expect to get them done by tomorrow (as well as making sure the pipeline passes), but I seem to be getting some inconsistent errors that I might need help with. I'll keep you posted on that. |
@Blond11516 You can get test_paths and test_patterns like mix does https://github.com/elixir-lang/elixir/blob/281d35e52062c06efcae10b05b3f0c905155e5b3/lib/mix/lib/mix/tasks/test.ex#L400 (probably you will need to iterate over apps in case of umbrella) |
@axelson I've just tested the lenses with https://github.com/elixir-lsp/example_phx and everything seems to work fine for me, both in |
64810d5
to
185a0d9
Compare
I've added some unit tests for this. The tests for the I've narrowed the error down to the Would anyone have any idea what might be going on with this? Here are the different errors I've seen for reference: Cannot build without an application name...
Compilation error in seemingly random file
|
Okay, I see what the problem is. I'm running into #193 since I built my version of ElixirLS with 1.8.2 and OTP 21.3. Which means that there isn't anything to fix here. |
I've been working on checking whether files should be considered based on The solution relies on Mix.Project.in_project, but because we receive multiple code lens requests in rapid succession this causes file system navigation and project loading errors. I seem to understand that the spec code lens generation suffers from a similar problem and has a working solution which could probably be reused. That said, I think the current PR is big enough, so I suggest tackling this later on. We do currently run the risk of providing code lenses for files that mix won't run, but that would require importing We could also make this feature opt-in until this is fixed. A setting to allow disabling the feature wouldn't hurt anyway. If that's alright with you I'll add the new setting and this should be ready to be merged, apart from the test errors I mentioned earlier. |
In general I think we should strive to keep the LanguageServer as current working directory agnostic as possible, and instead rely on the project directory setting/state which shouldn't change out from under us. I like the approach of adding it as an experimental/beta feature and requiring users to specifically enable it. Also, I am definitely agreed about keeping the scope for this PR manageable. To add the new setting, the setting itself can be added in this PR and elixir-lsp/vscode-elixir-ls#155 should be updated to the document the setting (once I finish #338 this process will be a little cleaner and more structured).
Agreed |
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.
Some minor naming changes. After these changes and the introduction of the new setting (with a default of off) I think this is ready to merge 🎊
apps/language_server/lib/language_server/providers/code_lens/test.ex
Outdated
Show resolved
Hide resolved
apps/language_server/lib/language_server/providers/code_lens/test.ex
Outdated
Show resolved
Hide resolved
Not quite sure what exactly you mean by that. I've added a check to skip the provider unless the new setting is true and added the new setting to elixir-lsp/vscode-elixir-ls#155 |
I just updated the branch with master and that raised a new issue. We now return an error when Is there a way to return "2 results" from a task? If not, I'm not sure how to make those two processes independent. |
OK, let's bring back the old behaviour and return |
I've restored the old behaviour. Out of curiosity, what was the rationale behind returning an error when code lenses are disabled? Are we losing much by reverting this? |
My rationale to return error was that if the setting is disabled the server shouldn't get this request. |
I see. Thanks for the info! In other news, I think I've addressed every comment and request for change! I'll leave it up to you to do a final review and merge. In the meantime I'll have another look over elixir-lsp/vscode-elixir-ls#155 to make sure everything is tidy on that side. |
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.
Okay, this is looking good! ❤️
@lukaszsamson want to give a final review as well?
Looks fine, let's merge it |
Provide code lenses that allow to automatically run tests.
Adds a function to the CodeLens provider which provides the following lenses:
describe
blocktest
blockLenses are only provided for files which import the
ExUnit.Case
module.VSCode PR: elixir-lsp/vscode-elixir-ls#155
Fixes #386