Skip to content

VuFind with Visual Studio Code (VSCode)

Ere Maijala edited this page Dec 2, 2022 · 15 revisions

VuFind with Visual Studio Code

User Settings

This is the user's settings.json example. This is customized for using Visual Studio Code on MacOS with MAMPStack, so fix paths etc. as necessary (executable paths are not needed if the correct versions are in search path already).

// Place your settings in this file to overwrite the default settings
{
    "files.trimTrailingWhitespace": true,

    // Allow only crash reports to be sent to Microsoft.
    "telemetry.telemetryLevel": "crash",

    // Controls if opened editors from Quick Open show as preview. Preview editors are reused until they are kept (e.g. via double click or editing).
    "workbench.editor.enablePreview": false,

    // Points to the php-cs-fixer exectuable.
    "php-cs-fixer.executablePath": "/Applications/mampstack-7.0.12-0/php/bin/php-cs-fixer",

    // Required by the PHP language server if the default PHP installation is too old
    "php.validate.executablePath": "/Applications/mampstack-7.0.12-0/php/bin/php",

    // Change the settings below according to your preferences
    "window.title": "${activeEditorMedium}${separator}${rootName}",
    "window.zoomLevel": 0,
    "workbench.colorTheme": "Default Light+",
    "editor.minimap.enabled": true,
    // If you don't want the icons in explorer and editor titles:
    "workbench.iconTheme": null
}`

Workspace Settings

// Place your settings in this file to overwrite default and user settings.
{
    "editor.rulers": [85],

    // Optional. The name or path of the coding standard to use. Defaults to the one set in phpcs global config.
    "phpcs.standard": "pear",

    "php-cs-fixer.executablePath": "vendor/bin/php-cs-fixer",
    "php-cs-fixer.config": "tests/vufind.php-cs-fixer.php",

    // If you have PHP Intellisense installed, disable built-in basic suggestions:
    "php.suggest.basic": false
}

Useful Extensions

  • PHP CS Fixer (junstyle)
  • PHP Extension Pack
  • PHP Intellisense
  • phpcs

Debugging

Note that debugging with VSCode works slightly differently than with e.g. Eclipse. While Eclipse will listen for incoming debugger connection from PHP at all times, in VSCode debugging is started from the debugger. Go to debugger, click the small gear and icon and choose PHP so that a new launch configuration for listening for XDebug connection is created. Then start listening with the play button. This means that on PHP side XDebug can be enabled unconditionally. Further instructions on how to set up the PHP side are available at https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug.

Sample settings for MAMPStack:

[XDebug]
; The following line should already be somewhere added by pecl when xdebug is installed:
;zend_extension=/[something]/php/lib/php/extensions/xdebug.so 
xdebug.mode=debug
;xdebug.mode=profile
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.show_exception_trace=0
xdebug.log=/dev/null

Hints

Cmd/Ctrl+P = Quick Open. Enter @ at the beginning for a quick outline of current file or : for "go to line". Cmd/Ctrl+Shift+O = Quick outline Ctrl+G = Go to line

All keyboard shortcuts: https://code.visualstudio.com/docs/customization/keybindings