Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Namespace highlight #31

Closed
rafi opened this issue Aug 19, 2014 · 6 comments
Closed

Namespace highlight #31

rafi opened this issue Aug 19, 2014 · 6 comments

Comments

@rafi
Copy link

rafi commented Aug 19, 2014

Is it possible to highlight a namespace?
I've been using this to highlight backslashes: syn match phpParent "\\" contained .. but that's not too smart.

Thank you very much for your work.

@StanAngeloff
Copy link
Owner

Can you give an example? Are you after highlighting just the \ operator or the entire namespace?

@rafi
Copy link
Author

rafi commented Aug 20, 2014

Well, it'll be nice highlighting the entire namespace on lines with use or namespace. And the namespace up-until-the class name in function calls.

Examples:

  1. namespace Acme\CoreBundle;
  2. use Acme\CoreBundle\App;
  3. \Acme\System::init();
  4. echo \Acme::foo()

Highlights:

  1. Namespace: Acme\CoreBundle
  2. Namespace: Acme\CoreBundle\App
  3. Namespace: \Acme\ Class: System Method: init()
  4. Namespace: \ Class: Acme Method: foo()

I started learning Vimscript, but syntax files are still Chinese to me. Would this namespace highlight be hard to accomplish?

@StanAngeloff
Copy link
Owner

Thank you for the examples! I wouldn't necessarily say it's difficult to accomplish, however I'm not sold on the alternative highlighting. I'm going to leave this issue open for more people to weigh in with their opinions.

One caveat, though, is example 2 where use Acme\CoreBundle\App can be importing a class named App or a directory App (e.g., so later on you can say $instance = new App\Awesomeness()).

@swekaj
Copy link

swekaj commented Aug 21, 2014

I'm inclined to agree with @StanAngeloff, mostly. There's really only two instances you can be sure that the last item is a class vs. namespace:

  1. When extending or implementing, the last item must be a class or interface, e.g. class foo implements \Bar\Baz
  2. When calling a static function, e.g. \Bar\Baz::foo()

One of these situations (2) is already covered by existing highlight rules, the keyword before :: is always highlighted differently (at least for my color scheme). I could see merit highlighting case 1, but I don't have strong feelings about it.

I do think it could be nice to highlight the \ separator, though. That would make longer namespaces easier to read.

@StanAngeloff
Copy link
Owner

As part of #45 and once merged you should be able to specify different highlighting for the class/namespace following use. If anyone is interested to refactor the code to add support for namespace as well, please send over a pull request and I'll gladly review & accept.

Archiving discussion.

@tam5
Copy link

tam5 commented Dec 3, 2017

@StanAngeloff I agree with:

@swekaj 's

I do think it could be nice to highlight the \ separator, though. That would make longer namespaces easier to read.

Is there a way to accomplish this currently?

Btw thanks for all your work!

StanAngeloff added a commit that referenced this issue Dec 4, 2017
Closes #31 (and more specifically #31 (comment))

The new highlighting groups are linked to their parents to avoid
breaking existing syntax colouring.
camilledejoye pushed a commit to camilledejoye/php.vim that referenced this issue Apr 16, 2018
Closes StanAngeloff#31 (and more specifically StanAngeloff#31 (comment))

The new highlighting groups are linked to their parents to avoid
breaking existing syntax colouring.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants