I'm struggling with setting up environment for old tech project with PHP5.
My OS is Windows and I have installed so far VSCode plugins: PHP Debug, PHP Intelephense, PHPUnit, PHPUnit Test Explorer.
I downloaded phpunit-5.7.27.phar and configured VSCode according to documentation.
Settings.json
{
"php.validate.executablePath": "C:/wamp64/bin/php/php5.6.40/php.exe",
"phpunit.phpunit": "C:/wamp64/bin/php/php5.6.40/phpunit-5.7.27.phar",
"phpunit.php": "C:/wamp64/bin/php/php5.6.40/php.exe",
"intelephense.environment.phpVersion": "5.6.40",
"intelephense.environment.includePaths": [
"C:/wamp64/bin/php/php5.6.40/phpunit-5.7.27.phar",
"C:/wamp64/bin/php/php5.6.40/php.exe",
"C:/wamp64/bin/php/php5.6.40/"
]
}
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"xdebugSettings": {
"max_children": 256,
"max_data": 500,
"max_depth": 3
}
},
]
}
What works for me fine is breakpointing on running app with xdebug and running unittests with Cmd+Shift+P.
What I need help with are as follows:
Code editor shows error for PHP unit classes and methods (even though unittests are executing fine as is). Do I need to add to path something besides phar file? Is VSCode non-compatible with phar files? The same happens for PHPUnit\Framework\TestCase.
I can't figure out how to configure Test Explorer plugin to show nicely tests tree. Does it require some configuration in Launch.json? Launching tests with Cmd+Shift+P displays results only in terminal.
PHP Intelephense requires installed PHPUnit with composer in workspace.
composer require --dev phpunit/phpunit
PHPUnit Test Explorer has by default Phpunit: Files setting set to {test,tests}/**/*Test.php, so changing it to proper glob should allow plugin to detect all tests.
Related
In creating new Singer Taps using the Meltano SDK, it's not always clear how to setup testing in VS Code.
What's the best way to get the VS Code test features working?
First Method: Unit testing with VS Code "Tests" pane
This method makes unit tests (pytest tests) easy to run in the VS Code "Tests" pane.
Prereqs:
Python is installed on your machine.
The Python VS Code extension is installed.
You've run poetry install at least once.
You've set the Python interpreter to the Poetry environment via: "Command Palette" > "Python: Select Interpreter" and then select the matching Poetry environment.
Once the above are complete, the "tests" pane should populate with the list of unit tests and you'll have an option in the VS Code GUI to "Run" or "Debug" each test.
Second Method: Integration test by actually invoking the tap
This method actually runs your tap and sends the output to target-json or a similar sample target.
Prereqs:
Add a main to the bottom of your tap.py to make it invocable:
if __name__ == "__main__":
TapGoogleAnalytics.cli()
Install target-jsonl via pipx install target-jsonl or similar.
Replace tap_foobar with the actual name of your tap's library and then paste this into VS Code's launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/tap_foobar/tap.py",
"console": "integratedTerminal",
"args": ["--config", ".secrets/config.json", "|", "target-jsonl"],
"env": { "PYTHONPATH": "${workspaceRoot}"}
}
]
}
I am working on a proof-of-concept app, written in Rust, with the end goal being to produce a shared library (.dll/.so) callable via C ABI from a number of other languages (C++, C#, etc). I have two simple components; poc is a Rust console app, which references poclib which exposes some simple functions. The app itself builds and runs fine so far, but I am stuck on how to debug it in VSCode using CodeLLDB.
I have a top level "workspace" like this:
[workspace]
members = [
"poc",
"poclib"
]
poc/cargo.toml looks like this:
[package]
name = "poc"
version = "0.1.0"
edition = "2018"
[dependencies.poclib]
path = "../poclib"
[dependencies]
And poclib/cargo.toml looks like this:
[package]
name = "poclib"
version = "0.1.0"
edition = "2018"
[lib]
crate_type = ["cdylib"]
[dependencies]
unicode-segmentation = "1.7.1"
My launch.json looks like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'poc'",
"cargo": {
"args": [
"build",
"--bin=poc",
"--package=poc"
],
"filter": {
"name": "poc",
"kind": "bin"
}
},
"args": [ ],
"cwd": "${workspaceFolder}"
}
]
}
When I try to launch and debug in VSCode with the CodeLLDB extension installed, the app builds but then raises an error: /home/username/src/rustpoc/target/debug/poc: error while loading shared libraries: libpoclib.so: cannot open shared object file: No such file or directory. If I just do cargo run instead, it builds and runs fine, and I can verify that libpoclib.so is being built and placed in the ./target/debug folder.
If I comment out the crate_type option in the poclib/cargo.toml, it launches fine and I can hit breakpoints, but the shared library is no longer created.
I've tried adding an LD_LIBRARY_PATH setting to the launch.json, like this:
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/target/debug"
},
That doesn't fix anything, but it does change the error message - with that setting I get /home/username/src/rustpoc/target/debug/poc: error while loading shared libraries: libstd-0a9489cf400f65e4.so: cannot open shared object file: No such file or directory
How can I enable debugging Rust in VSCode while still producing shared libraries?
I don't understand why it worked at all initially, but the solution was to fix the crate_type option so that I'm producing both C ABI libraries and native Rust libraries.
crate_type = ["cdylib","lib"]
With that setting the build output contains both a libpoclib.so for use from C, and a libpoclib.rlib which the poc binary can link statically against, and LLDB debugging works as expected.
Metals announced that "It is now possible to run and test directly from VS Code using the new "Run", "Test", "Debug" and "Debug test" buttons." There is a nice gif showing what it can do, and I don't know how to get to that point.
I tried to launch VS Code debugger with the following configurations in launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "scala",
"request": "launch",
"name": "Untitled",
"mainClass": "com.playZip.Unzip",
"args": [],
"jvmOptions": []
}
]
}
and got this error message:
Couldn't find a debug adapter descriptor for debug type 'scala' (extension might have failed to activate)
Somebody on Gitter scalameta/metals had this problem and the answer was that he needs Bloop to support utest and I think mine does because there's a file .bloop/play-zip-test.json in my sbt project, but I'm not 100% if my Bloop supports utest and what to do if it doesn't. I tried running bloop utest and it failed because I don't have Bloop CLI installed. I have Bloop that comes with Metals.
Document how to run or debug applications #2005 added official debugging documentation at Running and debugging your code which documents two approaches
via code lenses run | debug
via a launch.json configuration
Here is a hello world example how to debug a test using VSC and Metals via launch.json approach. We will use
lihaoyi/utest library and set a breakpoint in a test.
Execute sbt new scala/scala-seed.g8 to create correct project structure
Open... sbt project with VSC or simply cd into project and execute code .
Replace ScalaTest with utest in build.sbt
libraryDependencies += "com.lihaoyi" %% "utest" % "0.7.2" % "test",
testFrameworks += new TestFramework("utest.runner.Framework")
Replace test/scala/example/HelloSpec.scala with HelloTests.scala
package example
import utest._
object HelloTests extends TestSuite{
val tests = Tests{
test("test1"){
1
}
}
}
Import sbt build with View | Command Palette... | Metals: Import Build
Put a breakpoint at line 8 and click Run and Debug
Select Test Suite for Pick the kind of class to debug
Leave empty for Enter the name of the build target
Write example.HelloTests for Enter the name of the class to debug
Write Debug example.HelloTests for Enter the name of configuration
This should create .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "scala",
"name": "Debug example.HelloTests",
"request": "launch",
"testClass": "example.HelloTests"
}
]
}
Now you should be able to Start Debugging by clicking the green triangle and stop at the breakpoint
Not sure if your problem is solved, but I did see the same issue before. To get more information about the error, you can check the Metals output. See the picture below:
From the output tab, select Metals. More detail of the error should be available.
In my case, the reason I got this error (Couldn't find a debug adapter descriptor for debug type 'scala' (extension might have failed to activate) ) is because the Java installed in my machine does not support JDI.
Message: Debugging is not supported because bloop server is running on a JRE /usr/lib/jvm/java-8-openjdk-amd64/jre with no support for Java Debug Interface: 'JDI implementation is not provided by the vendor'. To enable debugging, install a JDK and restart the bloop server.
I guess your case is probably the same. To solve it, just install a Java implementation supports JDI. For example, openjdk version "11.0.8" 2020-07-14 works fine with Metals on Ubuntu. You can do this to install it.
$ sudo apt install openjdk-11-jdk
If it still not works, make sure Metals: Java Home in VS Code settings points to the right Java version.
I ran into this same problem and it came down to the buildTarget. I have a multiple module project. When I looked at the metals logs this is what I saw:
Caused by: scala.MatchError: scala.meta.internal.metals.debug.BuildTargetNotFoundException: Build target not found: (of class scala.meta.internal.metals.debug.BuildTargetNotFoundException)
My Scala project
/client_accounts
/migrations
/app
Updated the launch.json to "buildTarget": "app", and it worked. Error reporting could be a bit better.
So if you get this error look at the logs for the root cause.
I'm trying to debug Hy code in Visual Studio Code. I have downloaded the hy-mode theme and it works great. There's only one problem. The hy-mode theme disables breakpoints.
I can add a breakpoint to my Hy code by switching to a totally unrelated language (like CoffeeScript) and then my Python debugger works. But I can't add breakpoints when I'm in hy-mode.
I debug code by writing a Python file that imports a Hy file. When I run the Python pdb debugger on the Python file, pdb debugs the Hy code just fine. But I can't add breakpoints to the Hy file when I'm have hy-mode active.
Is there a way to edit a Visual Studio Code theme so that to allow the insertion of breakpoints?
I found a solution to this problem. By adding "hy" to the languageIds list in the following files I can get Hy files to display breakpoints.
./ms-python.python-2019.8.30787/package.json
ms-python.python-2019.8.30787/out/client/package.json
"debuggers": [
{
"type": "python",
"label": "Python",
"languages": [
"python"
],
"enableBreakpointsFor": {
"languageIds": [
"python",
"html",
"jinja",
"hy"
]
},
I try to set up a launch.json for a vagrant-plugin on windows. My current version look like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Vagrant",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/vagrant",
"args": ["up"],
"env": {
"VAGRANT_CWD": "${workspaceRoot}/development"
}
}
]
}
When starting the plugin now, vagrant misses the external dependencies. So I get the error:
The executable 'curl' Vagrant is trying to run was not
found in the %PATH% variable. This is an error. Please verify
this software is installed and on the path.
Adding the needed dependencies to my path sound like trouble (cp.exe, dir.exe, ...).
I tried:
"env": {
"PATH": "/HashiCorp/Vagrant/embedded/bin;${PATH}",
"VAGRANT_CWD": "${workspaceRoot}/development"
}
But then i get Debugger terminal error: Process failed: spawn rdebug-ide.bat ENOENT.
Is there a way the expend the PATH environment Variable in the launch.json?
For the question of:
Is there a way the expend the PATH environment Variable in the
launch.json?
From the documentation:
You can also reference environment variables through ${env.Name} (e.g.
${env.PATH}). Be sure to match the environment variable name's casing,
for example env.Path on Windows.
At: http://code.visualstudio.com/docs/editor/tasks#_variable-substitution
For example I often use this for Ruby apps in my launch.json in Visual Studio Code:
...
"pathToBundler": "${env.HOME}/.rvm/gems/ruby-2.3.0/wrappers/bundle",
...
#sschoof If you are trying to run VS Code from the windows host machine I'd suggest reading this post.
I've current just started configuring a development workspace for use with nodejs, VS Code, and Azure using my Mac OSX host. My solution is working but I have not a done a windows implementation so I currently cannot offer more experienced advice.