Skip to content

Commit

Permalink
[PHP] Suppress method completions when typing php tags (#3237)
Browse files Browse the repository at this point in the history
* [PHP] Suppress method completions when typing php tags

Resolves https://github.com/sublimehq/sublime_text/issues/5256

The fix consists of two parts:

1. Extending the completion's selector by 

       - punctuation.section.embedded.begin

2. Making sure to highlight incomplete <?php tags

       punctuation.section.embedded.begin
    
   Note: If this isn't acceptable we might want to scope incomplete
   tags using a `meta` scope and add this to the selector (1.) as well.

   We just need to ensure ST sees the correct scope while typing the
   opening php tag in order to not add those methods to the list of
   available completions.

* [PHP] Fix php snippet

This commit makes sure to correctly complete the `<?php | ?>` snippet
depending on whether `php` or `<?php` was entered. In the latter case
we might want to apply `php (begin tag)` snippet which doesn't add a
second `<?`.

Before this commit:

  <?ph|   =>  <?<?php | ?>

With this commit:

  <?ph|   =>  <?php | ?>

* [PHP] Use separate patterns for incomplete php tags

Keep scoping to suppress completions while not pushing/popping contexts
until tag is complete. May help to prevent some false positives or
confusion about non-running but highlighted code.
  • Loading branch information
deathaxe authored Feb 15, 2022
1 parent 346258e commit 1f94fc2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions PHP/PHP Source.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ contexts:
push:
- meta_scope: embedding.php text.html.basic
- clear_scopes: true
- match: <\?(?i:(?!php)ph?)
scope: meta.embedded.block.php punctuation.section.embedded.begin.php
- match: <\?(?i:php)?
scope: meta.embedded.block.php punctuation.section.embedded.begin.php
pop: 1
Expand All @@ -131,6 +133,8 @@ contexts:
push: scope:text.html.basic

single-line-php-tag:
- match: <\?(?i:(?!php)ph?)
scope: meta.embedded.block.php punctuation.section.embedded.begin.php
- match: (?:<\?=|<\?(?i:php)?(?=.*\?>))
scope: punctuation.section.embedded.begin.php
push:
Expand Down
2 changes: 1 addition & 1 deletion PHP/PHP.sublime-completions
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"scope": "source.php - string - comment - variable.other.php - meta.embedded.html",
"scope": "source.php - string - comment - variable.other.php - meta.embedded.html - punctuation.section.embedded.begin.php",
"completions":
[
"php",
Expand Down
2 changes: 2 additions & 0 deletions PHP/PHP.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ contexts:
- match: ''
set: scope:text.html.basic
with_prototype:
- match: <\?(?i:(?!php)ph?)
scope: meta.embedded.block.php punctuation.section.embedded.begin.php
- match: <\?(?i:php|=)?(?![^?]*\?>)
scope: punctuation.section.embedded.begin.php
push:
Expand Down
6 changes: 6 additions & 0 deletions PHP/Snippets/php (begin tag).sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_PHP_OPEN_TAG:php} $0 ?>]]></content>
<tabTrigger>php</tabTrigger>
<scope>embedding.php text.html punctuation.section.embedded.begin.php</scope>
<description>&lt;?php … ?&gt;</description>
</snippet>
2 changes: 1 addition & 1 deletion PHP/Snippets/php.sublime-snippet
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<snippet>
<content><![CDATA[<?${TM_PHP_OPEN_TAG:php} $0 ?>]]></content>
<tabTrigger>php</tabTrigger>
<scope>embedding.php text.html - source.php</scope>
<scope>embedding.php text.html - source.php - punctuation.section.embedded.begin.php</scope>
<description>&lt;?php … ?&gt;</description>
</snippet>

0 comments on commit 1f94fc2

Please sign in to comment.