VScode formatter, keep open bracket at same line (PHP) - php

I have enable the "editor.formatOnSave" setting but in php files when the code is formate, all the open brackets are going to a new line. i just want them to stay in the same line ex
function test{
}
not
function test
{
}
I am looking for a solution all day but i cant find anything

If you want to have your php code formatted like this
function test {
}
then use intelephense with the following settings.
"intelephense.format.braces": "k&r"
Edit
As #Pinonirvana said in his answer, you can now do this through the GUI.
You'll find this information under du user settings:
Short key -> Ctrl+,
or
File > Preferences > Settings

The new versions of VScode include this feature already.
You just need to search for "intelephense" in the VScode settings, and look for a setting called "Braces".

There is default formatter in the intelephence and it doesen't have many options to customize. You can disable it in the php language-specific settings:
~/.config/Code - OSS/User/settings.json:
----------
...
"[php]": {
// "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
"editor.defaultFormatter": "kokororin.vscode-phpfmt"
},
...
Then you can use some another formatter that support customization, phpfmt for example. Here is my settings:
"phpfmt.exclude": [
"AllmanStyleBraces"
],
"phpfmt.smart_linebreak_after_curly": true,
"phpfmt.psr2": false,
"phpfmt.detect_indent": true

Easy Step, please follow below step -

Related

Disable Undefined Property error in PHP Devsense extension on VSCode

I just added the PHP extension by Devsense to my VSCode and now it's lighting up like a Christmas tree. I want to disable the Intellisense option for unknown/undefined properties.
Here is the issue
and the error message
Undefined property: MY_Model::$load PHP(PHP0416)
And a link to the post where they talk about adding it
I saw some options for Intelliphense where you could set "intelephense.diagnostics.undefinedProperties": false
in the vscode settings.json, but I couldn't find anything that would work for this extension.
The fix described here in the 3rd post to add the property in a comment does work, but is not feasible in the codebases I am working in. I need something more like the second post, where I can just disable the check altogether
I found the answer to my own question. Leaving it here because It took me way too long.
You just have to exclude the error code, in this case error code 0416
1 - Open Settings.json : ctrl + shift + P and type 'settings.json'
2 - Select 'Open User Settings (JSON)
3 - At the end of file, add this code:
"php.problems.exclude" : {
"/" : [416],
"vendor/" : true,
}

How do I disable parameter hints in Vscode [duplicate]

How can I disable the default tooltip hint message in VSCode? It's annoying sometimes.
editor.hover.enabled: false in settings.json to Tooltip
Click on Edit in settings.json
There are two panes
Default User Settings
"editor.quickSuggestions": {
"other": false,
"comments": false,
"strings": false
}
User Settings
"editor.parameterHints.enabled": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"html.suggest.html5": false,
"editor.snippetSuggestions": "none",
This also can be done UI.
Setting Snippet Suggestions : false
Update August 2018 (version 1.27)
Goto File=>Preference=>Settings
Text Editor => Suggestions
Click on Edit in settings.json
"editor.parameterHints.enabled": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"html.suggest.html5": false,
Update your suggest options and save.
Before August 2018
Goto File=>Preference=>User Settings
You will find settings.json
// Configures if the built-in HTML language support suggests Angular tags and properties.
"html.suggest.angular1": false,
"html.suggest.ionic": false,
"html.suggest.html5": false,
Just find your language and set suggest = false
Update
Setting to turn off ALL popups
"editor.parameterHints": false
"editor.hover.enabled": false,
is your bulletproof solution. Then you can use CTLR + K, CTLR + I.
To hide those hints you can just add "editor.parameterHints": false to your settings.json. Found the answer in here.
I find using a larger value for Editor > Hover: Delay (search for "delay" in the settings search bar) does the trick for me. Its default is 300ms. This doesn't address the desire to actually eliminate the tooltips, but having them only appear after, say, 2 seconds, reduces the visual clutter quite a bit for me.
On version 1.27.2, I found that only this parameter disabled all the tooltips: "editor.hover.enabled": false.
I'm using Visual Studio Code v1.63.0 and in Settings I searched for "hover" and, among other things, found "Editor > Hover: Delay" and "Editor > Hover: Enabled". Unchecking the latter will disable the hover. However, I personally find them useful but they're displayed too quickly so I increased ""Editor > Hover: Delay" from "300" to "5000"
Simple way that no one here has mentioned: Code → Preferences → Settings. Search for "hover". Uncheck the checkbox where it says "Editor > Hover: Enabled".
Cntrl + shift + P -> Prefences: Open Settings (JSON)
"editor.parameterHints": false,
"editor.hover.enabled": false
i had to do both of these.
Here's the noob version, assuming you know little about VS Code (like me).
Windows.
VS Code version: 1.37.1
While in VS Code:
press F1 then type "settings" or "preferences" - then click "Preferences: Open User Settings"
- or -
from top menu: File>Preferences>Settings
- or -
hotkey: ctrl+,
in the settings pane, type "hover" (no need to press "enter")
the settings pane should display the hover settings immediately
Uncheck "Editor › Hover: Enabled"
hover disable
Rockstar Version: edit the JSON like a balla
F1 then type "Open Settings (JSON)"
-or-
navigate to settings JSON file and open in VS Code
https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations
Add this to JSON file (within curly braces, INCLUDE quotes): "editor.hover.enabled": false
Note: each line needs a comma after it. If you add to top, put a comma after this line. If you add to bottom, add a comma after the previous line.
Don't forget to save!
what JSON looks like
If you're new to coding, those tooltips can come in handy. You may want instead to just DELAY their appearance as Logan suggested.
click here: https://stackoverflow.com/a/53512394/8623576
or simply scroll up! :)
Note: I appreciate others have posted almost the EXACT same answer but, as I mentioned, this is the NOOB version that assumes the user has little/no experience with VS Code.
for Versions 1.31+ this one line did it for me:
"editor.parameterHints.enabled": false
Go to the settings gear wheel in the bottom left hand corner, then go to Settings and search "hover". Uncheck the "Controls whether the hover is shown" box.
Arrrg!!!
Hope this helps others. Running with v1.72.1. For the life of me was trying all the different settings, options, suggesting and couldn't get the tooltip help disabled... Coffee might have been my solution, finally noticed in the tooltip window there is an 'x' in the upper right corner for a close, clicking it. WOW! It worked and seems to have persisted my desire to dismiss them. I wanted them gone.... Perfect!!! Thinking about it, don't see a way to get them back if someone might actually want them back. VS Code is nice for a lot of stuff, but pretty bad for some of it's design and usability...
If you are not looking for disable and as mentioned by user: Darrell Brogdon above, if you want to delay the hover time of tooltip as solution then simply add the below line in user settings with your desired time value.
replace value 3000 as per your need.
Note: hover settings are moved in Online Services Settings in newer versions, hence you might not be able to find it with search 'hover' in user settings.
// modify in Preferences --> Settings or settings.json
"editor.hover.delay": 3000,

Why won't the key combination Ctrl-K Ctrl-F work for php visual code?

I'm intending to format the selection (indentation) for the PHP code, but it does not work.
I already made sure that there aren't duplicate shortcuts.
I also disabled all extensions.
I changed the keyboard shortcut from Ctrl+K Ctrl+f to Ctrl+k Ctrl+y.
None of these helped.
Is the only language that does not work for me to format selection
Eye. It's not because I'm missing the closing tag (?>).
To see menu bar if not present press
Left Alt
then go:
Preferences > Keyboard Shortcuts
type in the search bar
ctrl+k ctrl+f
you should see
perhaps you have a collision and other command has the same shortcut defined or your shortcut is not defined at all.
You can double click on shortcut to edit it.
Note at the picture When this is when the command works because one shortcut may work only if you are currently editing document and other when you are browsing files so once you set a shortcut make sure your checking it in different places of editor to see if its working or not.
If you use shortcut:
Ctrl+Shift+P
and select command:
You'll see whole bunch of shortcuts and there should be there one you are missing:
{ "key": "ctrl+k ctrl+f", "command": "editor.action.formatSelection",
"when": "editorHasDocumentSelectionFormattingProvider && editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly" },
I think that you can just copy the one above, paste to your file if it is not present and save that file, restart your Code and all should be working. Remember that the file is JSON so keep its format - look how other keys are presented there and your pasting should not make JSON invalid.
.vue file doesn't have formate selection.
This function depends on your file type.
I checked that this key binding was indeed still specified, there was no duplicate key binding, etc.; still, Visual Studio Code refused to recognize the key combination. Then I quit visual studio code and restarted it, and the key combination started working again.
Sometimes, the basic quit-and-restart is the answer!
If nothing is working you can create your own "format selection" with multiple commands. You would need a code formatter and a macro extension to run multiple commands from one keybinding,I'm using "prettier" and "multi-command" extension.
You can use this keybinding in your keybindings.json (Click File -> Preferences -> Keyboard shortcuts. Use the tab that opens up to edit and find available key bindings) with the multi-command extension - no need for anything in settings.json:
{
"key": "Shift+Alt+A", // or whatever keybinding you wish
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.formatDocument",
"editor.action.clipboardCopyAction",
"undo",
"editor.action.clipboardPasteAction",
]
},
"when": "editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly"
}
I use it because "format selection" is not working with "*.vue" files.

Visual Studio Code: how to prioritize one formatting provider over the other

I'm coding PHP and using a few extensions that are very useful:
PHP Formatter just for formatting code
PHP Intelephense for providing intellisense
In this case both of them are Formatting providers, so you can right click in your editor and select "Format document" and everything will get indented and beautiful.... you get the point.
The thing here is that the formatting done by the PHP Intelephense (which I don't like) is the one that stays.
If, for instance, I disable the Intelephense extension the formatting looks good.
Let me give you a visual difference between the two formatting:
Intelephense (bad):
if ($condition) {
doSomthing();
}
else {
doAnotherThing();
}
PHP formatter (good) [chek out the else]
if ($condition) {
doSomthing();
} else {
doAnotherThing();
}
Zanks in advance for your time
"intelephense.format.enable": false
This will do your work.
There is no generic way to choose one over the other. This is left to extension authors to handle via settings as explained in the docs here
What happens when there are multiple formatters for one language? This
can be a problem when different formatters' actions contradict. In the
October release, we added settings to enable or disable the default
formatters that ship with VS Code. The best practice is for extension
authors to add a similar setting as what we did in VS Code as shown
below.
"html.format.enable": true,
"javascript.format.enable": true,
"typescript.format.enable": true,
"json.format.enable": true
You can read more discussion on how they came to this in this github issue.
So what does this mean for you? It means that the intelliphense extension needs to add a setting to disable formatting. You can create an issue and wait for them to fix it or try to make a PR to fix it yourself.

PhpStorm code formatter and indentation

I'm using PhpStorm with Symfony 3 to write my project.
But I've an issue. When I reformat the code,
This code :
Turns into this code :
And I don't know what is the setting I have to change to fix that :/ Any idea?
I found the solution for this at https://www.jetbrains.com/help/phpstorm/reformat-and-rearrange-code.html
First enable formatter markers in Settings->Editor->Tab:Formatter Control
After that, you can switch on/off the formatter on every statement/docblock via
// #formatter:off
or
/**
* #formatter:off
*/
be sure, that you enable the formatter with // #formatter:on if you want to format the code below your chained method call.
You change it in Menu:
File -> Default Settings -> Editor -> Code Style -> PHP
and overlap: Wrapping and Braces:
Chained method calls : "Wrap always"
Align when multiline "Y"
Place ';' on new Line "Y"
After it you can reformat yours code CTR+ALT+L

Categories