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

Run/Debug code lenses don't appear #470

Closed
joshmanderson opened this issue Nov 28, 2018 · 53 comments · Fixed by #697
Closed

Run/Debug code lenses don't appear #470

joshmanderson opened this issue Nov 28, 2018 · 53 comments · Fixed by #697
Labels
Milestone

Comments

@joshmanderson
Copy link

joshmanderson commented Nov 28, 2018

Starting about a week ago, code lenses for each test, as well as the lens for the test class as a whole, have stopped appearing. Also, no tests appear in the test explorer panel, though this may have been a pre-existing issue – I've never used the test explorer before so I can't say for sure.

Restarting or reloading vscode does not fix the problem, nor does restarting the computer, nor disabling and re-enabling the test runner code lens – or the root vscode code lens – setting (also tried disable+restart and re-enable+restart).

Project is using gradle and tests use junit. Gradle version was upgraded from 2.14.1 to 3.5.1 17 days ago, but the issue has only started occurring in the last week, so I'm not sure that the gradle upgrade is relevant to the problem.

Has anyone else experienced similar issues recently and does anyone have any ideas as to what might be causing the issue?

@jdneo
Copy link
Member

jdneo commented Nov 29, 2018

@joshmanderson Would you mind to share the project to us?

@joshmanderson
Copy link
Author

@jdneo I can't do that, sorry – the project is private to my company.
I know that this certainly complicates the issue replication process, but I'm afraid it's just not possible for me to share it.

@jdneo
Copy link
Member

jdneo commented Nov 29, 2018

@joshmanderson Ok I understand. I'll keep my eyes on this issue and update here if I find anything.

@jdneo
Copy link
Member

jdneo commented Nov 29, 2018

@joshmanderson One more question.

Can you see the test explorer at the sidebar (though no test items in it), or there is no test explorer at all.

I‘m wondering if the extension gets activated successfully.

@chrissantamaria
Copy link

I'm having the same issue on two entirely separate machines; code lenses have stopped appearing and no tests are showing up in the Test Explorer either.

@jdneo
Copy link
Member

jdneo commented Dec 4, 2018

@chrissantamaria Are you using Gradle as your building tools?

@chrissantamaria
Copy link

@jdneo Forgive me, I'm not all that experienced with Java packages, but I believe I am; I'm just using the standard Java Extension Pack. Projects were created with Eclipse beforehand.

@jdneo
Copy link
Member

jdneo commented Dec 4, 2018

@chrissantamaria Don't worry.

Would you mind to share the content of .classpath file? Which is located at the base path of your project.

@chrissantamaria
Copy link

@jdneo

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-10">
		<attributes>
			<attribute name="module" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4">
		<attributes>
			<attribute name="module" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="output" path="bin"/>
</classpath>

@joshmanderson
Copy link
Author

@jdneo Apologies for the late reply.
The test explorer appears in the sidebar, but there are no tests shown within it.

@jdneo
Copy link
Member

jdneo commented Dec 5, 2018

I guess I got the root cause of this problem.

In our implementation, we will only search for the test items in the test folders. Here is the implementation to determine the location of the test folder.

But the implementation could not solve all the problems.

A valid .classpath file may look like this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" output="target/classes" path="src/main/java">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
			<attribute name="test" value="true"/>
		</attributes>
	</classpathentry>
	...
</classpath>

For some unknown reason, some projects may not have test attribute in its classpath entries. Just like @chrissantamaria provided. So I have to figure out a way to solve this scenario.

@joshmanderson
Copy link
Author

joshmanderson commented Dec 5, 2018

@jdneo
I can confirm that changing my .classpath from this:

...
<classpathentry kind="src" path="src/test/java" />
...

to this:

<classpathentry kind="src" path="src/test/java" output="build/classes/test">
    <attributes>
        <attribute name="test" value="true" />
    </attributes>
</classpathentry>

fixes the issue. Tests are now appearing in the test explorer (and can be run from there), and code lenses are appearing again (and working).

@jdneo
Copy link
Member

jdneo commented Dec 6, 2018

@joshmanderson Glad to know we have a workaround now. 😄

@thoni56
Copy link

thoni56 commented Dec 29, 2018

This workaround definitely worked for me too.

I had a project build in Eclipse that did not have "test" attributes in the classpathentry's. Adding this made the tests appear in the test explorer.

@rdcoe

This comment has been minimized.

@jdneo jdneo mentioned this issue Jan 6, 2019
@jdneo

This comment has been minimized.

@badsyntax

This comment has been minimized.

@jdneo

This comment has been minimized.

@badsyntax

This comment has been minimized.

@jdneo

This comment has been minimized.

@jenny-ci

This comment has been minimized.

@dampcake
Copy link

@jdneo I have tried setting <testSourceDirectory/> in multiple different Maven projects and it doesn't seem to make a difference. It's always empty unless I manually edit the .classpath file.

Note that I am using the default src/test/java paths in all of these projects.

@jdneo
Copy link
Member

jdneo commented Jul 16, 2019

@dampcake It would be helpful if you could share a sample project to repro the issue. This would be helpful for us to investigate what is going on?

@dampcake
Copy link

https://github.com/dampcake/bencode (small single module Maven sample).
https://github.com/dampcake/incubator-druid/tree/fix-eclipse (large multi-module Maven).

I have tried adding <testSourceDirectory/> in the parent pom.xml as well as in each individual child pom.xml for multi module projects. After adding I have even tried cleaning the Java workspace and restarting. Nothing I do outside of modifying the .classpath file directly seems to have any impact.

@jdneo
Copy link
Member

jdneo commented Jul 16, 2019

@dampcake I tried the first one and it works on my side.
image

Here are some places that you may take a look:

  • Is the auto build turned on?
    image
  • Try to trigger compilation task before running the test to see if it could help. It's F1 > Java: Force Java Compilation > Full
  • Is there any output in the output channel?
    image

@dampcake
Copy link

Still not able to enable it:

  • Auto build is turned on.
  • Triggering a full build made no difference.
  • There is no output in the Java Test Runner output channel.

More info:
Java Test Runner version: 0.18.1
VSCode version: 1.36.1
OS: macOS 10.14.5
Java version: 1.8.0_201
Maven version: 3.6.0

Other things tried:

  • running git clean -fdX and opening to regenerate everything
  • cleaning the java server workspace

Screen shots:
Screen Shot 2019-07-15 at 11 25 15 PM
Screen Shot 2019-07-15 at 11 25 54 PM
Screen Shot 2019-07-15 at 11 26 51 PM

@jdneo
Copy link
Member

jdneo commented Jul 16, 2019

Hmmm, tried on Mac as well.
Screen Shot 2019-07-16 at 1 38 25 PM

So far I've no idea what is going on. Would you mind to share the .classpath file that generated by the Java Language Server? You can find it at the root of your project.

@dampcake
Copy link

Here is the generated .classpath file:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" output="target/classes" path="src/main/java">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" path="target/generated-sources/annotations">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
			<attribute name="ignore_optional_problems" value="true"/>
			<attribute name="m2e-apt" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
			<attribute name="ignore_optional_problems" value="true"/>
			<attribute name="m2e-apt" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="output" path="target/classes"/>
</classpath>

@jdneo
Copy link
Member

jdneo commented Jul 16, 2019

One thing I observed is that test scope is missing in the generated file. Here is mine:

<classpathentry kind="src" output="target/test-classes" path="src/test/java">
    <attributes>
        <attribute name="optional" value="true"/>
        <attribute name="maven.pomderived" value="true"/>
        <attribute name="test" value="true"/>
    </attributes>
    ...

@dampcake
Copy link

Yes and if added manually like in #470 (comment) it works, but it will not generate it with it in there. Was yours automatically generated like that?

@jdneo
Copy link
Member

jdneo commented Jul 16, 2019

Yes it's automatically generated. Wired....

@tthorntone
Copy link

tthorntone commented Jul 31, 2019

@jdneo Thanks for working this through with everyone! I'm experiencing another weird issue, related to this--

My .classpath does not by default generate the for my test sources, and my configuration is a bit complicated, so instead of a re-work I implemented this into my build.gradle:

def testSources = entries.findAll {element -> element.path == "src/test/java" || element.path == "src/test/resources" || element.path == "src/integrationTest/java" || element.path == "src/integrationTest/resources" }
  testSources.forEach { entry -> 
    entry.entryAttributes['test'] = 'true'
  }
}

This adds the test attribute, but at the bottom, see here:
Not Working ClassPath Gist

This does not work. However, if I let Eclipse do it , it generates the same xml, but with the test attribute at top, and it DOES work:
Working ClassPath Gist

@jdneo
Copy link
Member

jdneo commented Aug 1, 2019

@dampcake is your problem get resolved?

If the test attribute is still not auto generated in your .classpath, I suggest to file an issue in the Language Server repo: https://github.com/eclipse/eclipse.jdt.ls

@jdneo
Copy link
Member

jdneo commented Aug 1, 2019

Thank you @tthorntone for reporting this. I find a potential bug in the implementation. Let's discuss it in #759

@dampcake
Copy link

dampcake commented Aug 5, 2019

@jdneo it's still not working on my macbook. I just tried opening a couple projects today in Ubuntu and it's working fine there. I will try to dig in later this week and see if I can figure out what's going on.

@rmgalante
Copy link

rmgalante commented Oct 9, 2019

I am unable to see the tests in the Test Explorer. However, I can run the Maven test command as follows and that works.

mvn test -f "c:\Users\xxx\Documents\xxx\Java\xxx\pom.xml"

All the tests run to completion. Here is my configuration.

VS Code Version: 1.39.0 (user setup)
VS Code Commit: 9df03c6d6ce97c6645c5846f6dfa2a6a7d276515

Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362

Java JDK 1.8.0.221
Language Support for Java v 0.50.0
Debugger for Java v 0.22.0
Java Test Runner v 0.20.0
Maven v 3.6.2

I tried the solution in Issue 470, and it did not solve the problem.

The Test Explorer is blank, and none of the CodeLens links appear in my unit tests.

@jdneo
Copy link
Member

jdneo commented Oct 10, 2019

@rmgalante Any output in your output channel? Or any thing you can see in the problems panel?

@rmgalante
Copy link

I've cloned the open source repo, gozer, at https://github.com/walmartlabs/gozer. You should be able to duplicate this problem with that open source repo.

The Problem panel is empty. "No problems have been detected in the workspace so far."

The output panels shows the following exception when I launch the project. It does not look relevant to the problem as it is just the FileWatcher exception.

Looking for git in: C:\Program Files\Git\cmd\git.exe
Using git 2.21.0.windows.1 from C:\Program Files\Git\cmd\git.exe

git rev-parse --show-toplevel
git rev-parse --git-dir
git config --get commit.template
Open repository: c:\Users\xxx\Documents\xxx\Java\VSCode\gozer
git status -z -u
git check-ignore -v -z --stdin
git symbolic-ref --short HEAD
git rev-parse master
git rev-parse --symbolic-full-name master@{u}
git rev-list --left-right master...refs/remotes/origin/master
git for-each-ref --format %(refname) %(objectname) --sort -committerdate
git remote --verbose
Failed to watch ref 'c:\Users\xxx\Documents\xxx\Java\VSCode\gozer.git\refs\remotes\origin\master', is most likely packed.
Error: ENOENT: no such file or directory, watch 'c:\Users\xxx\Documents\xxx\Java\VSCode\gozer.git\refs\remotes\origin\master'
at FSWatcher.start (internal/fs/watchers.js:164:26)
at Object.watch (fs.js:1232:11)
at Object.t.watch (c:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\main.js:1:594401)
at T.updateTransientWatchers (c:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\main.js:1:98291)
at l.fire (c:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:50:539)
at k.updateModelState (c:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\main.js:1:115979)

I can't use VS Code if I don't have a Task Runner. I hope this can be fixed.

@adeick
Copy link

adeick commented Feb 15, 2020

I'm trying to figure out Debugging and Unit Testing for the first time. My class is using Eclipse, but I'd rather not download Eclipse if don't need to.
I have the Run/Debug Code Lense for the main method, but I do not have the Run Test/Debug Test Code Lense appearing on my Unit Test.

I'm not entirely sure where to edit the classpath. I have a bunch of .java files in a folder, but there isn't any .classpath file. I have my Visual Studio extensions stored in a completely different place on my computer. I have a .java file I want to use for testing, but it's not specified as a test file as far as I know.

I search for .classpath files in the File Explorer, and I found like 5 (they all look identical, I think they are for different versions of Java)
The one I have looks like:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12"/>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="output" path="bin"/>
</classpath>

And I changed the 2nd classpathentry line to what it said above, but it didn't work and I don't really know what I'm doing

@jdneo
Copy link
Member

jdneo commented Feb 16, 2020

@adeick If your project for teaching purpose and is not complicated, you can use the standalone project in VS Code Java:

  1. Just create a new empty folder.
  2. In this folder, all the required libraries can be put into a folder named lib

See: https://code.visualstudio.com/docs/java/java-project/lib.mp4

@ybelenko
Copy link

I'm working in OpenAPITools/openapi-generator(latest master) repo. Tests panel is empty. No CodeLens actions in test files.
I tried to add .classpath file to root directory manually:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="modules/openapi-generator/src/test/java/org/openapitools/codegen" output="build/classes/test">
        <attributes>
            <attribute name="test" value="true" />
        </attributes>
    </classpathentry>
</classpath>

Also tried to add <testSourceDirectory> to root pom.xml:

        <sourceDirectory>src/main/java</sourceDirectory>
        <outputDirectory>target/classes</outputDirectory>
        <testSourceDirectory>modules/openapi-generator/src/test/java/org/openapitools/codegen</testSourceDirectory>

Any suggestions?


Java Test Runner 0.23.0

MacOS Mojave 10.14.6

VSCode

Version: 1.46.0
Commit: a5d1cc28bb5da32ec67e86cc50f84c67cc690321
Date: 2020-06-10T08:59:06.977Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 18.7.0

Java SDK

$ java -version
java version "13.0.1" 2019-10-15
Java(TM) SE Runtime Environment (build 13.0.1+9)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)

@jdneo
Copy link
Member

jdneo commented Jun 11, 2020

@ybelenko I think it's because this project mixed with both Maven and Gradle, and the Java Language Server will import Gradle project by default.

I tried to disable the setting java.import.gradle.enabled and open the folder /modules/openapi-generator. The Code Lenses appear:

image

@ybelenko
Copy link

@jdneo Thanks a lot!

I've checked, it works under /modules/openapi-generator folder with disabled option.
Can I make it work somehow when VSCode opened with root directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet