Asked  7 Months ago    Answers:  5   Viewed   31 times

I can't find a way to run or debug php on Visual studio code, Does anyone know how?

 Answers

23

As far as I read about it today, you can't debug anything else than node.js, JavaScript and TypeScript at the moment, but they said they want to add new languages which you can debug. The editor is still in development. Nevertheless, I don't think there will be a php debugger in the future since php is serverside, so you can't debug it on your client alone.

If you want to debug php, I can recommend xDebug.


Updated:

Now, it is possible to debug with VS code. You need to install XDebug and php-debug extension for VScode.

Wednesday, March 31, 2021
 
Litty
answered 7 Months ago
41

UPDATE: August 2016: TSD is now depreciated. instead use https://www.npmjs.com/package/typings

npm install typings --global

OR

If using VS2015 NodeJS v1.2 released 29th July 2016 then typings-core@1.3.1 is installed automatically for you during first use:

Executing command 'npm install "C:PROGRAM FILES (X86)MICROSOFT VISUAL STUDIO 14.0COMMON7IDEEXTENSIONSMICROSOFTNODE.JS TOOLS FOR VISUAL STUDIO1.2TypingsAcquisitionTool"
ntvs-typings-acquisition-tool@1.0.0 ..........node_modulesntvs-typings-acquisition-tool
??? minimist@1.2.0
??? typings-core@1.3.1 (array-uniq@1.0.3, thenify@3.2.0, zip-object@0.1.0, popsicle-status@2.0.0, popsicle-retry@3.2.1, listify@1.0.0, promise-finally@2.2.1, xtend@4.0.1, graceful-fs@4.1.5, throat@3.0.0, lockfile@1.0.1, strip-bom@2.0.0, sort-keys@1.1.2, string-template@1.0.0, make-error-cause@1.2.1, any-promise@1.3.0, has@1.0.1, rc@1.1.6, object.pick@1.1.2, debug@2.2.0, mkdirp@0.5.1, invariant@2.2.1, configstore@2.0.0, parse-json@2.2.0, touch@1.0.0, detect-indent@4.0.0, is-absolute@0.2.5, popsicle-proxy-agent@3.0.0, rimraf@2.5.4, popsicle@8.0.4, typescript@1.8.7)

-----Original Answer-----

There is a package manager for Typescript Definition Files. This is a community driven repository containing Typescript definitions for many popular libraries.

You can install tsd by following the instructions here.

Once you install tsd globally, you can install packages from your project root in the command line like this:

$ tsd install express --save

This will create a typings directory if one doesn't exist and adds an express directory with an express.d.ts file inside.

Screenshot

It also creates a tsd.d.ts file that contains the references to all of your tsd files. If I install a few more tsd's, here is what it looks like.

enter image description here

Now to access my tsd files, all I need to do is reference their path in at the top of my code with /// <reference path="typings/tsd.d.ts" />

enter image description here

Now I get intellisense.

enter image description here

Friday, July 9, 2021
 
toesslab
answered 4 Months ago
97

See Tyler Long's answer. The steps below are not required in the newest versions of Visual Studio Code :)


I made a repository to demonstrate.

First off, the only way I could get the debugger to hit the test was to add a file, Program.cs, take control of the entry point from xUnit, and manually add code to test. It's not ideal, but I imagine you aren't going to be doing this very often, and it's easy to flip it back to normal.

Program.cs:

using System;
namespace XUnitDebugging
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var test = new TestClass();
            test.PassingTest();
            Console.WriteLine("Enter text...");
            Console.ReadLine();

        }
    }
}

Next, in project.json add the following:

  "buildOptions": {
    "emitEntryPoint": true,
    "debugType": "portable"
  },

project.json:

{
  "version": "1.0.0-*",
  "testRunner": "xunit",
  "buildOptions": {
    "emitEntryPoint": true,
    "debugType": "portable"
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    },
    "xunit": "2.2.0-beta2-build3300",
    "dotnet-test-xunit": "2.2.0-preview2-build1029"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      }
    }
  }
}

This will allow you to debug an xUnit unit test project.

Wednesday, July 14, 2021
 
superhero
answered 4 Months ago
68

To change the integrated terminal on Windows, you just need to change the terminal.integrated.shell.windows line:

  1. Open VS User Settings (Preferences > User Settings). This will open two side-by-side documents.
  2. Add a new "terminal.integrated.shell.windows": "C:\Bin\Cmder\Cmder.exe" setting to the User Settings document on the right if it's not already there. This is so you aren't editing the Default Setting directly, but instead adding to it.
  3. Save the User Settings file.

You can then access it with keys Ctrl+backtick by default.

Sunday, August 1, 2021
 
Pascal
answered 3 Months ago
33

When I had Unbound Breakpoints in VSCode I ended up needing to start the process with the --inspect or --debug-brk=5858 flag. Beyond that, launch.json gave me lots of trouble, and these resources helped

  • https://code.visualstudio.com/docs/nodejs/nodejs-debugging
  • https://code.visualstudio.com/docs/nodejs/debugging-recipes
    • https://github.com/microsoft/vscode-recipes/tree/master/nodemon
  • https://code.visualstudio.com/docs/typescript/typescript-debugging

launch.json examples:

    {
        "type": "node",
        "request": "attach",
        "name": "Node: Nodemon",
        "processId": "${command:PickProcess}",
        "restart": true,
        "protocol": "inspector",
    },
    {
        "name": "Launch tests via NPM",
        "type": "node",
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
            "run-script", "testDebug"
        ],
        "port": 5858
    }

package.json

"scripts": {
  "start": "NODE_PATH=./src DEBUG=express:* NODE_ENV=dev nodemon -w src --ext ts --exec node --inspect -r tsconfig-paths/register -r ts-node/register src/index.ts",
  "testDebug": "NODE_ENV=test ts-mocha --debug-brk=5858 --paths -p tsconfig.json",
 }

},

Saturday, October 16, 2021
 
superhero
answered 5 Days ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :