Coder Social home page Coder Social logo

language-php's Introduction

Atom and all repositories under Atom will be archived on December 15, 2022. Learn more in our official announcement

PHP language support in Atom

CI Status

Adds syntax highlighting and snippets to PHP files in Atom.

Originally converted from the PHP TextMate bundle.

Contributions are greatly appreciated. Please fork this repository and open a pull request to add snippets, make grammar tweaks, etc.

language-php's People

Contributors

50wliu avatar andreyco avatar arandilopez avatar as-cii avatar blademf avatar darangi avatar dsifford avatar eexit avatar frozzare avatar ingramz avatar ionbazan avatar jacobbednarz avatar jasonrudolph avatar jens1o avatar kapitanoczywisty avatar kevinsawicki avatar lagden avatar lee-dohm avatar lkashef avatar mat-b- avatar mnquintana avatar mohamamdreza1000 avatar mostafaeweda avatar nyoro712 avatar roblourens avatar sadick254 avatar thisispiers avatar torn4dom4n avatar uzitech avatar zr9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

language-php's Issues

Make filetype priority

I have a .php file but the first line is <html> so it will take "HTML" as syntax highlighting (auto). I can set it to PHP manually but it would be nice if would automatically use PHP because the file ending is .php.

Also if I insert a blank line it will automatically use PHP

PHP syntax parse error

When makin an intensive use of simple quotes and contatenations in a long PHP file, the syntax highliter seems not to work ok.

Shows many sections of the file as commented or strings.

Array closing parenthesis highlighted incorrectly

The closing parenthesis in an array() statement (= the one having class="punctuation definition array end php") seems to be selected incorrectly โ€“ simply the first ) character is selected, which is not correct if there is a function/method called inside the array() definition. See the screenshot:

image

It is using Seti syntax theme which assigns the array() parentheses a different colour (light blue in this case).

Atom 0.177.0 on Mac OS X 10.10.2

Add custom file types

It would be nice if there is a way we could add custom file types which use PHP syntax.

For example I have use a .spv as a file extension (I no idea why) for all my PHP files. I can manually add it too the config files but this gets overridden each time I update atom.

Maybe if there was a way to do it in my atom config.

Auto-Complete Commenting.

Hey, this is something I feel would enhance the experience for many users using the PHP editor in At0m.

Make it so that when you open a comment, e.g /** make it auto-complete it.

e.g

    /**
     * 
     *
     *
     */

This type of stuff is very useful in IDE's like Eclipse, Netbeans, etc.
Another suggest would be once this feature is implement allow the user to choose to add stuff like,
@author
@Date <date this file was commented/made
@Version
@see
etc.

Default array value syntax error

When using the short array syntax as default value it looks bad.

default-array-error

When using the old array syntax as default value it looks good.

default-array-old

When removing the array type before the argument it looks good.

default-array-good

I have tested the default Atom Dark UI and Syntax theme and it looks the same.

HEREDOC highlighting broken

I have the following code:

$this->data['text_message'] .= <<<TRACKER
        <!-- Facebook Conversion Code for Checkout Success -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src ='//connect.facebook.net/en_US/fbds.js';
var s =document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '',{'value':'0.00','currency':'AUD'}]);
</script>
<noscript><img height="1" width="1"alt="" style="display:none" src="https://www.facebook.com/tr?ev=&amp;cd[value]=0.00&amp;cd[currency]=AUD&amp;noscript=1"/></noscript> 
TRACKER;

But atom doesn't highlight the contents of the HEREDOC as a string:

Example

The first < is correctly given the appropriate classes (class="string unquoted heredoc php") but the class doesn't persist to any of following tokens:
Example 2

PHP scope is not correctly recognised

It seems that grammar does not correctly recognise the PHP scope.

Expected behaviour:

  1. Open an empty .php file
  2. Type <?php ENTER fun TAB
  3. Snippet fun is expanded

Current behaviour:

  1. Open an empty .php file
  2. Type <?php ENTER fun TAB
  3. Snippet fun is not expanded

In the following case it works as expected:

  1. Open en empty .php file
  2. Type php TAB to expand into <?php | ?>
  3. ENTER fun TAB
  4. Snippet fun is expanded

However, when I close this file and reopen it again, completion of snippets does not work.

This probably also causes #2.

I already looked into php.cson, however, I couldn't find any obvious wrong definitions, that is, they are the same as in PHP.tmLanguage from Sublime Text 3.

Commenting

Commenting out blocks of code is using HTML comments rather than PHP comment tags.

Example.

if (!empty($attribute['description'])) {
    $out .= "<span class='attribute-description'>{$attribute['description']}</span>";
}

Highlighting these three lines in the editor and then using CMD + / yields the following.

<!-- if (!empty($attribute['description'])) {
    $out .= "<span class='attribute-description'>{$attribute['description']}</span>";
} -->

Should this package include, php functions autocompletion like array_push?

Hi,
When I type array shouldn't I get a list of array functions, and when I select one shouldn't I get, for example
array_push(array &$array , mixed $value1)

Can the above be done in language-php.cson file or is this out of the scope of the file?
If I want to do my own php autocompletions should I edit this file or something else?

Thanks

Highlighting parentheses

I tried taking a stab at adding this in the php.cson file - but didn't get far.

Things like if(true) or case($foo), or native functions in_array() - the parentheses are not wrapped in a span with a class(es), meaning we can't target them in syntax themes.

Example from the dom on an if statement checking a file_exists: source

Can this be added? I'll keep digging through the language file in the meantime.

highlighting bug

Highlighting stops working. See last 2 } in the example below

screen shot 2014-07-23 at 4 54 04 pm

Code

<?php

$data = "{$reg['id']}\t{$reg['firstName']}\t{$reg['lastName']}\t{$reg['email']}\t{$reg['program']}\t{$reg['campus']}\t{$reg['qualities1']}\t{$reg['qualities2']}\t{$reg['qualities3']}\t{$reg['qualities4']}\t{$reg['qualities5']}\n";

Docblock completion

It would be ace if DocBlocks were completed automatically when typing /**

Which would produce

/**
 *
**/

Auto-indent issues - square brackets, function arguments, heredoc/nowdoc

Is this the right place to ask about indenting issues that I am experiencing when editing PHP? Or is auto indenting actually handled by a different module?

The first two examples have very obvious work-arounds and are just annoying. The heredoc issue requires any heredoc strings to be revisited every time anyone auto-indents the whole file.

Indenting square-bracket array syntax over multiple lines only works with a trailing coma, so this works:

class Foo
{
    function bar ()
    {
        return
        [
            [
                // stuff
            ],
            [
                // more stuff
            ],
        ];
    }
}

But this does not:

class Foo
{
    function bar ()
    {
        return
        [
            [
                // stuff
            ],
            [
                // more stuff
                ]
            ];
        }
    }   

Indenting a multi-line function call only works if the closing parenthesis is on the same line as the final parameter, so this works:

class Foo
{
    function bar ()
    {
        foobar(
        extremely_long_and_tedious_variable_name_1,
        extremely_long_and_tedious_variable_name_2,
        extremely_long_and_tedious_variable_name_3 );
    }
}

But this does not:

class Foo
{
    function bar ()
    {
        foobar(
        extremely_long_and_tedious_variable_name_1,
        extremely_long_and_tedious_variable_name_2,
        extremely_long_and_tedious_variable_name_3
    );
}
}

And finally, heredoc and nowdoc syntax are both broken by auto-indent:

class Foo
{
    function bar ()
    {
        return
        <<<'HTML'
        <blockquote>Somthing pithy</blockquote>
        HTML
    }
}

Autocomplete snippets does not work

For example. If i'm in a PHP file and types "/" the comment snippets does not get activated. Also tried to hit a new line after "/" but that does not result in a complete snippet.
It would also be a nice feature if i activates the snippet over a function that the snippet reads arguments from the function and automatically adds expected "@params" and "@return" to the comment snippet.

Properly identify "finally" keyword

The keywords "try" and "catch" get proper classes, but "finally" doesn't.
It needs to get the "keyword.control.exception.finally.php" classes, but right now gets "constant.other.php".

Autocomplete is too fuzzy

I've set the autocomplete-plus to only use provider "Symbols", so I expect the problem lies with this package.

I'm used to fact that the auto-completion list is precise, no words which does not work.

Right now in PHP the auto-completion is giving me a long list of totally unrelated completions. Even in code bases with OOP and autoloading classes. Other IDE's such as NetBeans PHPStorm and Eclipse PDT works phenomenally with these kind of code bases, Atom needs a similar non-fuzzy auto-completion to replace those.

'Catch' with an argument (in contained Javascript)

The parser doesn't seem to recognize the closing parenthesis of the argument of this (Javascript) catch statement:

catch parenthesis bug php atom

(Notice the closing script tag is still highlighted with gray.) In TextMate the highlighting doesn't break, but as the php-grammar files of Atom and TextMate agree (compare the first and the latter), I have no clue how to fix this.

Cmd-/ doesn't comment out lines

Before

        $this->_setProperties(
            array(
                'userId', 'uid', 'email', 'cbk', 'sessionPhrase'
            )
        );

After

<!--         $this->_setProperties(
            array(
                'userId', 'uid', 'email', 'cbk', 'sessionPhrase'
            )
        ); -->

Parser not handling

This is an example from the system I'm working on. Please refrain from the style, I know it's horrible but since it's a legacy system not much can be done.

Anyway, this is a good example, because it's a hard thing for a parser to get this working - but it does work in other editors (ie: Sublime).

Could you please tell me what could I do to make it work? In case you didn't notice, the HTML code coloring is good in the beggining but whenever you reach the end of the image, near <?php endif; ?>, the HTML coloring is gone forever and the rest of the document is interpreted as being between quotes.

The images attached are from Atom and then Sublime, respectively (both Ubuntu 14).

Thanks in advance.
selecao_016
selecao_017

foreach snippet doesn't work as expected

The foreach snippet does not behave as expected:

Expand the snippet:

foreach ($variable as $key => $value) {
  # code...
}

Tab 1 is set correctly to highlight "variable". Tab 2 is set correctly to highlight "key". If tab 2 changes, tab 3 will highlight the second letter of tab 2 to the end of value instead of starting after tab 2.

screenshot 2014-05-15 10 00 44

Snippets formating and some solution

Hey i'm currently checking if snippets work as expected:

.text.html.basic

  • _prefix: php_
  • _prefix: else_
  • _prefix: ifelse_
  • _prefix: if_

  • _prefix: echo_

Actual:

<?php echo \$var; ?>

Expected:

<?php echo $var; ?>

Body:

<?php echo ${1:\\$var} ?>$0

Solution:

<?php echo ${1:\$var} ?>$0

  • _prefix: echoh_

Actual:

<?php echo htmlentities(\$var, ENT_QUOTES, 'utf-8') ?>

Expected:

<?php echo htmlentities($var, ENT_QUOTES, 'utf-8') ?>

Body:

<?php echo htmlentities(${1:\\$var}, ENT_QUOTES, \'utf-8\') ?>$0

Solution:

<?php echo htmlentities(${1:\$var}, ENT_QUOTES, \'utf-8\') ?>$0

  • _prefix: foreach_

Actual:

<?php foreach (\$variable as \$key => \$value): ?>
       ${0}
<?php endforeach ?>

Expected:

<?php foreach ($variable as $key => $value): ?>
       # code
<?php endforeach ?>

Body:

<?php foreach (\\$${1:variable} as \\$${2:key}${3: => \\$${4:value}}): ?>\n\t${0}\n<?php endforeach ?>

Solution:

<?php foreach (\$${1:variable} as \$${2:key}${3: => \$${4:value}}): ?>\n\t${0:# code}\n<?php endforeach ?>

.text.html.php:

  • _prefix: php_
  • _prefix: <<<_
  • _prefix: /_**
  • _prefix: class_
  • _prefix: def_
  • _prefix: do_
  • _prefix: else_
  • _prefix: elseif_
  • _prefix: ifelse_
  • _prefix: if_
  • _prefix: incl_
  • _prefix: incl1_
  • _prefix: req_
  • _prefix: req1_
  • _prefix: ret_
  • _prefix: ret1_
  • _prefix: ret0_
  • _prefix: switch_
  • _prefix: case_
  • _prefix: throw_
  • _prefix: while_

  • _prefix: globals_

Actual:

\$GLOBALS['variable'] = something;

Expected:

$GLOBALS['variable'] = something;

Body:

\\$GLOBALS[\'${1:variable}\']${2: = }${3:something}${4:;}$0

Solution:

\$GLOBALS[\'${1:variable}\']${2: = }${3:something}${4:;}$0

  • _prefix: con_

Actual:

function __construct(\$foo = null) {
    ${2/.+/$this-> = \$;/}
}```
Expected:
```php
function __construct($foo = null) {
    $this-> = ;
}```
Body: 
```php
function __construct(${1:\\$${2:foo}${3: = ${4:null}}}) {\n\t${2/.+/$this->$0 = \\$$0;/}$0\n}

  • _prefix: doc_v_

Actual:

/**
 * undocumented class variable
 *
 * @var string
 **/
var \$;

Expected:

/**
 * undocumented class variable
 *
 * @var string
 **/
var $;

Body:

/**\n * ${3:undocumented class variable}\n *\n * @var ${4:string}\n **/\n${1:var} \\$$2;$0

Solution:

/**\n * ${3:undocumented class variable}\n *\n * @var ${4:string}\n **/\n${1:var} \$$2;$0

  • _prefix: def?_

Actual:

def? 

Expected:

defined('')

Body:

$1defined(\'$2\')$0

Solution:

// Replace the prefix to defd maybe
use : defined(\'$1\')$0

  • _prefix: echo_

Actual:

echo "string"${0};

Expected:

echo "string";

Body:

echo "${1:string}"${0};

Solution:

echo "${1:string}";$0

  • _prefix: for_

Actual:

for (\$i=0; \$i < ; \$i++) { 
    # code...
}

Expected:

for ($i=0; $i < ; $i++) { 
    # code...
}

Body:

for (\\$${1:i}=${2:0}; \\$${1:i} < $3; \\$${1:i}++) { \n\t${0:# code...}\n}

Solution:


  • _prefix: foreach_

Actual:

foreach (\$variable as \$key => \$value) {
    # code...
}

Expected:

foreach ($variable as $key => $value) {
    # code...
}

Body:

foreach (\\$${1:variable} as \\$${2:key}${3: => \\$${4:value}}) {\n\t${0:# code...}\n}

Solution:

foreach (\$${1:variable} as \$${2:key}${3: => \$${4:value}}) {\n\t${0:# code...}\n}

  • _prefix: fun_

Actual:

public function FunctionName(\$value='')
{
    # code...
}

Expected:

public function FunctionName($value='')
{
    # code...
}

Body:

${1:public }function ${2:FunctionName}(${3:\\$${4:value}${5:=\'\'}})\n{\n\t${0:# code...}\n}

Solution:

${1:public }function ${2:FunctionName}(${3:\$${4:value}${5:=\'\'}})\n{\n\t${0:# code...}\n}

  • _prefix: if?_

Actual:

if? 

Expected:

$retVal = (condition) ? a : b;

Body:

\\$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b} ;

Solution:


  • _prefix: array_

Actual:

\$arrayName = array('' => , );

Expected:

$arrayName = array('' => , );

Body:

\\$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b} ;

Solution:

\$${1:arrayName} = array(\'$2\' => $3${4:,} $0);

assistance with coding to PSR-1 and PSR-2 standard

http://www.php-fig.org/psr/psr-1/
http://www.php-fig.org/psr/psr-2/

It would be terrific if Atom were able to automatically adjust code to be compliant with the above PSRs.

This is different to linting. I don't want Atom to tell me that my code is non-compliant (well, I do, but that's a separate issue). When typing in class and function braces, Atom should automatically move the open brace to the next line, etc.

It should also make sure indenting and line-feeds are per-specification.

Indent on if without braces

When I use Auto Indent on an If without braces I get the following :

if ($test)
foo()

Shouldn't it be

if ($test)
  foo()

Match html tags

I reported what I think is a bug, and was asked to open an issue.

The main thing being in a mixed PHP & HTML file, none of the matching HTML tags are being highlighted. Such as clicking on an opening <ul> I would expect the closing </ul> tag to be highlighted, bordered or marked in some way.

Hi David,

Thanks for the report! Would you open an issue on the https://github.com/atom/language-php repository? If a similar issue already exists you .
can also feel free to add information that might be helpful in the comments.

Thanks a lot! Cheers,
Ivan

It seems that when in a file containing both php and html, the matching html tag is not highlighted when you click on a certain tag. Such as clicking an opening content <div>, I'd expect the closing </div> to be highlighted in some way.

Go to Declaration from Context Menu Doesn't Do Anything

Looks like the "Go to Declaration" doesn't do anything when I do the following:

  1. Right-Click the function
  2. Click "Go to Declaration"
  3. Nothing happens, no errors in console

Anticipated behavior: A search would be performed, and the file with the function definition would open and scroll to that function's definition.

Screenshot

Heredoc containing a closing PHP tag breaks syntax highlighting

I have a file containing the following:

        $this->xml = <<<EOD
<?xml version="1.0"?>
<methodCall>
<methodName>{$this->method}</methodName>
<params>

EOD;

The syntax formatting is picking up the ?> within the heredoc as a closing PHP tag, and as such the syntax highlighting is broken from this point on in the file.

screen shot 2014-03-03 at 10 58 40

Auto Indent indents documentation wrong

When marking all the following rows below and auto indenting, (using CMD+^+P and searching for Auto Intent and pressing enter) the result is not correct like it was before. The result is missing single spaces on some rows, see below.

/**
 * Function description.
 */
function example() {
}

Result: (wrong)

/**
* Function description.
*/
function example() {
}

Editor interprets some PHP array indices in strings as constants

If I have this code:

<?php $test = "If you don't love {$arr[dess1]} and {$arr[dess2]} you're silly"; #ex8

The indices (dess1, dess2) are treated as constants though:

This is how Atom puts it in code (from the developer tools window):

Atom 138, Windows 8.1, issue is the same if <?php is on a separate line.

Does not work inside <?php ?>

Extension .php pages that are mostly HTML with some PHP within <?php ?> does not get syntax hilighted. The HTML is properly hilighted, but all PHP is just grey.

snippet not working on atom v0.177

Hello everyone,

I wanted to try language-php snippets but nothing happens when I type
class + tab in test.php file. No error.

I tried to remove the symfony package (in case of conflict) but it still does not work. Remark : html and react snippets works.

config :
VM debian 7 64 bits
atom v0.177

Switch Php Function

Hi,
I've recently start to try Atom.
In my last IDE, there was a auto indent function for the php switch condition.
An example:
capture decran 2014-07-08 a 09 51 47

Atom Snippet Tab Stops Not Working Correctly

So I'm trying to create a snippet for .js files. And I want a snippet that looks like this:

$scope.TAB1(TAB2, function(TAB3) {
    TAB4
});TAB5

So, my snippet looks like this, naturally:

    'Angular Scope':
        'prefix': 'scope'
        'body': '$scope.${1}(${2}, function(${3}) {
          ${4}
        });$5'

But for some reason it jumps from tab stop 1, to tab stop 3, to tab stop 5. The white space is also ignored. Is there any way around this? Any help is appreciated. Thanks!

Linespace braces

This is probably more of an opinion rather than a bug, but I would be interested in peoples thoughts on it.

When I am typing control structures I like that the closing brace is typed automatically, but it would be nice to include a line space and indent the caret so that you could continue typing without having to press enter.

Currently, you'll get this output. I'll symbolise the caret with _

foreach () {_[enter]}
// Leads to
foreach () {
_}

// I'd think that this was more helpful
foreach () {
  _
}

Ninja edit
I should also include that this also applies to short array syntax.

[_(enter)]
// Gives
[
_]

PHP tags are not highlighted

The long, short, and closing PHP tags ("") are not highlighted:
atom example

Here is the same situation in the PHPStorm IDE:
php storm example

Class snippet error when not wanting extend.

Hey,

use class+[tab] I get the following error:

After I enter a name for my class everything from the second letter to the end of extend is highlighted.
This makes it effectively impossible to use this for creating a class when not extending another.

e.g. everything in the [lassName extends AnotherClass].

/**
 * command
 */
class C[lassName extends AnotherClass]
{

  function __construct(argument)
  {
    # code...
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.