Double click highlight variable Sublime Text 3 include $ - php

I wanted ST3 to include the "$" when selecting PHP files so I edited word_separators by removing $ as such :
"word_separators": "./\\()\"':,.;<>~!##%^&*|+=[]{}`~?"
And now it highlight the whole varibale including the "$" when double clicking a variable. However, now Sublime is not matching/outlining those variables using the default match_selection functionality.
Any thoughts on this? Is there a setting I am missing. Much appreciated.

Please see my answer to this question for an in-depth look at the effect of changing word_separators and various find and select options. Long story short, altering word_separators changes the behavior of double-clicking, as you noted, but other operations, including match_selection, rely on an internal word separators list that apparently can't be altered by the user. So, when you double-click to select a PHP variable, you'll get the $ selected, but other instances of the variable won't be highlighted. They will be selected when using CtrlD to make multiple selections, however:
Additionally, when using the Find dialog, other instances will be highlighted:
So, to address your original problem, if you need to see all the instances of the currently-selected variable, set "find_selected_text": true in your user preferences, double-click to select your variable of interest, then hit CtrlF (⌘F on OS X) to view all occurrences. Just make sure you don't have the regex search button selected, as $ has a special meaning in regexes.

Related

PHP linter for undefined variables/associative keys

We are looking for a PHP linter, and we are chasing a particular problem that's causing E_NOTICE's, a lot of them:
if($undef_variable)...
if($assoc['undef_key'])...
$undef_variable?...:...
$assoc['undef_key']?...:...
Functionally, the code works perfectly so if the tools was also able to replace on-the-fly such occurences with i.e.
if($undef_variable??null)
That would be a huge help.
Some of the code is in templates that are in included with some pre-set variables (always the same). So ideally the tool would also allow configuring some available global-namespace variables.
The tool should absolutely understand PHP7 syntax, especially anonymous functions.
At a minimum, we need to generate a list of every occurence where a variable is used as a boolean condition and is not defined in the same scope, and every occurence where an array key is used as a boolean condition.
Phpcs- PhpCodeSniffer can be used for that. You need to configure a rule for that. Find it here - Phpcs
Check this rule -
https://github.com/sirbrillig/phpcs-variable-analysis
If you use PhpStorm, it has an option in Inspections. https://www.jetbrains.com/help/phpstorm/php-undefined-variable.html

PHPStorm - xDebugg - variables listing

When going though my code with the debugg, you are able to see the variable and their values etc etc.
However, if an array has 200 odd variables or if an object has 300+ defs for it. It takes ages to find it straight away (once i find the variable i need, i put it under my watch list)
My questions is: How can you list the variable in alphabetical order or in any order at all within the debug variables list?
Debug tool window has an option to sort variables/array keys alphabetically. For that -- activate that option via "cog" icon:
NOTE: you can add that option as separate button on debug toolbar (look for A-Z icon on screenshot above) if you need to turn this option ON or OFF often. This can be done via Settings/Preferences | Appearance & Behaviour | Menus and Toolbars.
Standard in place search works there (in variables panel) as well. For that just start typing while panel has focus.
NOTE that search looks trough already expanded nodes only (just like in other places) -- it will NOT open nodes for you (e.g. if you are trying to find variable/key that is located in closed node then it will not be found).

Does anybody know how to add hook for php storm for changing . to ->? [duplicate]

Let's say I want to type the following in PhpStorm:
$longObjectName->propertyName = 'some value';
Seems innocent enough, no? If I start typing longOb, code completion kicks in and helpfully provides $longObjectName as a suggestion, since it exists elsewhere in my project. I think to myself, "Ah perfect, that's exactly what I wanted", so I hit Enter or Tab to accept the suggestion. At this point, I'm feeling pretty happy.
But now I want to insert ->, PHP's awkward but familiar object operator. If I type it manually, that's three whole keystrokes (including Shift), which makes me feel just a bit sad. A distant, nagging doubt begins to enter my mind. "Three keystrokes? What kind of evil IDE is this? Who are these ruthless dictators at JetBrains??"
The emotional roller coaster continues when I see the following in PhpStorm's Tip of the Day dialog, bringing a minuscule but insistent glimmer of hope to my dark, Monokai-schemed world:
When using Code Completion, you can accept the currently highlighted
selection in the popup list with the period character (.), comma (,),
semicolon (;), space and other characters.
The selected name is
automatically entered in the editor followed by the entered character.
In JavaScript, this means I can type longOb and hit . to both accept the first code completion suggestion and insert the JS object operator, resulting in longObjectName., at which point I can keep typing a property name and go on autocompleting all day long without ever hitting Enter. Amazing. Revolutionary even.
Now for some devastating news: it doesn't seem to work in PHP. (Fret not children—this harrowing tale is almost at its end.)
If I type longOb and then hit -, I get this:
longOb- // :(
I'm pretty sure the PHP interpreter wouldn't like me very much if I tried to execute that.
(Side note: ., ,, and ; exhibit pretty much the same behavior, contrary to the quoted Tip of the Day above.)
So here's what I would get if I were to make my fantasy world a reality:
$longObjectName->[handy dandy code completion list, primed and ready for action]
Wouldn't that be flipping awesome?
So finally, we arrive at the ultimate question, with some redundant stuff added for those who didn't bother to read my action-packed, heartwrenching story:
Is there a single keyboard shortcut in PhpStorm for "Accept the currently highlighted code completion suggestion and insert the PHP object operator (->)"?
Or is this just a bug?
Well, I solved this problem by recording a Macro and then binding it with a keyboard shortcut:
Go to Edit | Macros | Start Macro Recording
Type '->'
Stop Macro Recording using the button in the lower right corner, then name it whatever you want.
Assign Shortcut to it:
Go to File | Settings | Keymap | Macros |
Right click and choose 'Add Keyboard Shortcut'
I chose Ctrl+. as the shortcut and now I am more than happy. :)
You can use autohotkey (http://www.autohotkey.com/) to create new keystrokes and replace PHP Object Operator for period or anything else.
For example, with a script like this:
^.::
Send ->
return
Will replace (ctrl + .) with (->), in anywhere in Windows.
Or
#IfWinActive ahk_class SunAwtFrame
.::
Send ->
return
Will replace . (period) with (->) only in PhpStorm Window (Or others with ahk_class SunAwtFrame).
Use Window Spy to see the ahk_class class of any Windows Window.
You can use CTRL + . as . (period)
#IfWinActive ahk_class SunAwtFrame
^.::
Send .
return
1) As far as I remember this kind of completion was asked to be removed for PHP code (too unusual) .. but I cannot find such ticket right now (already spend over 20 mins on this) .. so I could be wrong (it was quite some time ago .. so possibly I'm confused with another code-completion improvement which was hard-configured to behave differently for PHP code only).
Kind of related to "why it was disabled/what problems where there in the past":
http://youtrack.jetbrains.com/issue/WI-7013
http://youtrack.jetbrains.com/issue/IDEA-88179
http://youtrack.jetbrains.com/issue/IDEA-59718
In any case: there is an open ticket to actually having it working: http://youtrack.jetbrains.com/issue/WI-21481 (only 1 vote so far).
2) There is no "complete with ->" action available. Related ticket: http://youtrack.jetbrains.com/issue/WI-17658 (star/vote/comment to get notified on progress)

How to Highlight PHP Method Calls in Sublime Text (textmate)

I am using Sublime Text 3 as a PHP editor, I've been customizing the PHP.tmLanguage file to include more syntax scopes, right now I cannot figure out how to capture class method invocations.
$html = new HTML("hr");
$html->output_ml("moo");
output_ml is currently declared as scope variable.other.property.php
I would like to add a scope to pertain to specifically to class method calls, but I am having trouble defining the regex in the tmLanguage file.
I've tried
<dict>
<key>match</key>
<string>(?i)\$[a-z_][a-z0-9_]*->([a-z_][a-z_0-9]*)\s*\(</string>
<key>name</key>
<string>meta.method-call.php</string>
</dict>
You were pretty close, I just tweaked a few things:
(?i:(?!\$[a-z_][a-z0-9_]*->)([a-z_][a-z_0-9]*)\s*\()
First thing I did was wrap the entire expression in the "case-insensitive" modifier, just so nothing got missed. Probably not necessary, but whatever. Second, and more importantly, I took your first group that was outside of parentheses, and made them a negative lookahead. This way, they match the class name and the arrow, but don't report it - basically saying "match whatever is ahead of us as long as we exist in front of it, but don't match us."
Now, you'll have a scope that matches just the method's name.
Demo
Now, here's what I don't get - why you should have to do this. I maintain both a language syntax and a color scheme, so I have a lot of experience with scoping in Sublime Text and TextMate. And to my knowledge, the PHP .tmLanguage already includes scopes for function calls. I'm not a PHP expert by any means, but I know the basics, so I made three examples of different PHP function calls:
Green highlights a large variety of function calls in different languages. In the top example, baz_quux is scoped as meta.function-call.object.php, in the middle example it's meta.function-call.static.php, and in the bottom it's just meta.function-call.php. I don't understand where you're getting variable.other.property.php from.
However, if I take away the parentheses after the function calls above:
I get the following scopes, from top down: variable.other.property.php (aha!), constant.other.class.php, and constant.other.php. If I put the parens back, and add a space or three after the end of the function name, they are still highlighted as functions, in green.
So, while we had some fun with regexes today, ultimately your work has already been done for you. If you're going to be doing more scope-hunting, I highly recommend the ScopeAlways plugin, which, like its name implies, always lists the full scope of the current cursor position in the bottom bar (you can turn it off via the Command Palette if you want). If I get a request to expand my color scheme's highlighting to a new language, I just open up as much code as I can find and poke around with my mouse, looking at the different scopes, then editing my theme to correct colors as needed, or add new ones for brand-new scopes. I then scan through the .tmLanguage file (after converting it to YAML) and see if I missed anything.
Good luck with your work!

PHP Eclipse - add Key Binding for Watch

I have to admit, for a FREE PRODUCT, Eclipse really delivers. However, sometimes I don't understand certain missing features...
Eclipse has over ELEVEN HUNDRED different key bindings.
(source: rigel222.com)
I would like to use one of those KeyBindings to add a "Watch" Expression to the expressions window, while debugging.
(source: rigel222.com)
Here is an additional screenshot showing that I already understand the "filter" process. I have set key-bindings for everything I could find pertaining to "Watch", but as you can see it doesn't show up in my right-click menu, and does not function when I use the defined keyboard shortcut.
(source: rigel222.com)
Despite the prevailing opinion that this is "blatant whining", It is also a legitimate problem for me.
Please help.
The menu item you seek is filtered out by default from the view. There is a filter button near the lower right corner of the window. There you should uncheck the "Filter uncategorized commands" checkbox, and then searching for watch should produce Add to Watch, Add Watch Expression output. I'm not entirely sure these are the ones you need, but it might work.

Categories