How to disable PHP validation in Visual Studio Code? - visual-studio-code

When opening any PHP file in the Windows version of Visual Studio Code (version 0.10.1), I get the message:
Cannot validate the php file. The php program was not found. Use the 'php.validate.executablePath' setting to configure the location of 'php'
I don't have PHP installed locally -- is there some way to turn off the automatic validation for PHP, either for the project or globally?

Starting with version 0.10.5, there is a setting under the PHP Configuration Options section in settings.json to control validation. You can modify either the workspace settings or the global settings depending on what you want to accomplish.
// Whether php validation is enabled or not.
"php.validate.enable": true,

For Windows it doesn't seem to work since it starts as a null pointer.
"php.validate.executablePath": null
If you change it into something like:
"php.validate.executablePath": "C:\\php\\php.exe"
and put an empty file (could be a text file) named as "php.exe" it stops showing the warning, although I do not know if there could be any side effects when VS Code actually tries to use it.
But I would like to add that installing php may be a better option. It just executes when called upon, so the only extra resource that you may end up using would be some hard drive space.

Not sure how to accomplish this in the Windows version. But for the Linux version (and Mac?):
Adding a path of /dev/null seems to suppress the message.
File -> Preferences -> User Settings (or Workspace Settings).
"php.validate.executablePath": "/dev/null"

Setting PHP validation to false in Preferences/User settings.json and/or Preferences/Workspace settings.json does currently work in Windows (year 2016, VSC Version 1.4.0) to end the validation messages. User preference settings are applied globally, while Workspace settings are applied to specific folders or projects.
Just to clarify what may not be obvious to newbies, custom settings in User 'settings.json' and Workspace 'settings.json' pages must be bracketed, otherwise the defaults will not be overwritten.
After the settings have been entered, the page must be saved (File/Save). A backup of 'settings.json' may be exported via Save As by changing the file name and/or choosing another folder. For example, 'myfolder\2017-01-01_vsc_user_settings.json'. To use the backup file, open it in VSC and copy/paste the code back into Preferences/User or Preferences/Workplace 'settings.json'.
https://code.visualstudio.com/docs/customization/userandworkspace
Turn off PHP validation: settings.json
// Place your settings in this file to overwrite default and user settings.
{
"php.validate.enable": false
}
Use comma separators to overwrite multiple default settings: settings.json.
// Place your settings in this file to overwrite default and user settings.
{
"php.validate.enable": false,
"files.trimTrailingWhitespace": true,
"editor.autoClosingBrackets": false,
"editor.wordWrap": true
}

If you are opening a php file in visual studio code, then I assume you would like to use intellisense. Just install the extension PHP Debug in Visual Studio Code, and follow all the instructions till you create and save the JSON file in Visual Studio Code.

Related

VS Code: How can I enable format-on-save for .cpp files but not .h?

There's a ticket open here for having extension specific settings: https://github.com/Microsoft/vscode/issues/35350
But it's still open. So I'm wondering, is there a hack or workaround or plugin that can do what I want?
Alternatively, I'd be ok (for now) with being able to enable format-on-save in a specific folder, but have it disabled in general.
(We use clang-format but presumably that doesn't really matter)

How to open a binary file (e.g. Excel) in Visual Studio Code with its default application

I use Visual Studio Code to work on projects that not only include program code, but also data files, e.g. in Excel format.
VSCode cannot edit such files, as they are binary. Attempting to do so shows a warning, and if you persist, the file is shown (as gibberish).
I've also tried to pass the file to the (CMD) terminal (right click, 'Open in Terminal'). In a regular CMD window that would invoke the default application, but that does not work in VSCode.
Is there a simple way that I can use from VSCode to open such files using the default applications?
The extension sandcastle.vscode-open does this. Install it, and you can open any file with its default application by right clicking on the filename in the explorer menu.
In v1.66 you can set a default editor for binary files and avoid the warning (see release notes: binary file):
Default binary editor
A new setting, workbench.editor.defaultBinaryEditor, lets you
circumvent the binary file warning and automatically open the editor
type of your choosing when a binary file is detected. You can select
the default binary editor from a dropdown in the Settings editor or
via IntelliSense in settings.json.
TBH, I am still investigating whether you can set this to some external application like Excel?

How to access Visual Studio Code extension settings

Got myself Visual Studio Code. I've installed a Uncrustify extension to make my files be formatted when I edit them. I wanted to make it format my files on save, but I cannot open like Options menu for this extension or something like that. The author gives this screenshot:
But I cannot reach that menu. When I click on this little gear circle near the extension under the Extensions tab, it just pops up a menu with: Disable (Workspace), Disable (Always), Uninstall. I can only edit 4 things, like my .cfg file path under Ctrl+Comma settings, but that's not what I am searching for, and it's not what is on this screen provided by author
I guess I am not only asking about this particular extension, but generally for extension settings in this editor.
Many ways mentioned here in an issue created available on VSCode repository: Allow to change settings from Extensions editor.
On Windows, I could be able to change settings by going to:
File -> Preferences -> Settings -> Extensions.
Dont know if you figured it out yet or not but maybe for someone who comes here to find an answer.
Step 1: Press ctrl+alt+p to open the command pallet.
Step 2: Search and execute this command Uncrustify: Open config file
If your config file has not been created, then before step 2 you must execute Uncrustify: Create default config file command.
Anyways, these instructions are present their in Details section of the extension.

Is it possible to have Visual Studio Code custom configured from a .ps1 file?

I'm attempting to put together a standard VS Code build for my company. I have a ps1 file that copies/installs extensions for VS Code after it's been installed but I can't seem to find how or even if it is possible to then configure VS Code settings to utilize those extensions.
For example, one of the extensions is "vscode-icons". I can install the extension just fine but then the user needs to setup his preferences manually to actually use the extension by going to the File->Preferences->File Icon Theme->VS Code Icons.
Is it possible to have my ps1 install file actually make configuration changes so any user who opens VS Code has the custom configuration settings?
The config settings for VS Code are JSON files - just needs to locate and edit them.
First check what manual change is doing then create part in the script to edit the settings.
https://code.visualstudio.com/docs/customization/userandworkspace

Visual Studio Code: Auto-refresh file changes

Working with Visual Studio Code I have noticed if a file you are working with change, whenever that file get focused in a code panel it will be reloaded from the disk (if you don't have changes in the file through VSCode).
However, if you are on that file there is no alert to warning you about file changes.
I've been reviewing the settings and I cannot find anything like the visual studio option:
Detect when file is changed outside the environment
So my question: Is there any hidden setting or some hack to make that warning happen.
Update
Solved in version 0.3.0 of Visual Studio Code.
The file will be updated from disk if there is no changes through the editor. (very useful to read log files during a process execution)
If there are changes on both sides (from disk and through the editor) when ever you try to save the file using VSCode, the editor will warn you about that situation (i.e. "dirty writes") and a file comparison will allow you to decide what to do.
VSCode will never refresh the file if you have changes in that file that are not saved to disk. However, if the file is open and does not have changes, it will replace with the changes on disk, that is true.
There is currently no way to disable this behaviour.
{
"files.useExperimentalFileWatcher" : true
}
in Code -> Preferences -> Settings
Tested with Visual Studio Code Version 1.26.1 on mac and win
SUPER-SHIFT-p > File: Revert File is the only way
(where SUPER is Command on Mac and Ctrl on PC)
In version 1.57.1 (June 2021) there is still no setting like Detect when file is changed outside the environment.
But if the file was accidentally changed outside, you can easily revert the changes with just the Undo (Ctrl+Z) command
On Ubuntu, after creating a new file using vscode, it doesn't show up until I refresh the explorer manually. It's really frustrating. There was a key I changed in settings.json and everything worked fine after that:
"files.legacyWatcher": "on",
save, restart the vscode and be safe :)