Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typenames in casts are not syntax highlighted #114

Closed
philiparvidsson opened this issue May 17, 2017 · 7 comments
Closed

typenames in casts are not syntax highlighted #114

philiparvidsson opened this issue May 17, 2017 · 7 comments

Comments

@philiparvidsson
Copy link

how to test:

  1. activate c# mode (M-x csharp-mode)
  2. write a simple cast, e.g:
    MyType a = new MyType();
    var b = (MyType)a;
  3. look at the (MyType) cast

expected:

(MyType) should be syntax highlighted as a type name

actual:

(MyType) is not syntax highlighted as a type name

@josteink josteink added the bug label May 19, 2017
@josteink
Copy link
Collaborator

josteink commented May 19, 2017

Thanks for the report!

I can definitely reproduce this, and don't I think writing a test-case for it will be too hard.

From what I can tell java-mode has no issues with cases like this, so we really shouldn't either.

If we're going to support this, we need to be able to do this on a mostly regexp-based basis, as we have no intelligence about what is actually types and what is not in our code.

My first take at a pseudo-regexp for catching cases like this would be:

paren-start
optional space
identifier       <-- class-name here
optional space
parent-end
optional space
identifier       <-- thing to be cast

As far as I can see, that won't catch all valid syntaxes... For instance the following cases would not have the cast highlighted correctly:

var res = (MyType)(a.b().c());
var nested = (MyType)(((SubType)foo).SubTypeMethod())

But looking at those generic examples, with generic names, that just looks like terrible code which nobody should be encouraged to write anyway :)

Is everyone OK with not supporting cases like that? Or would anyone object to it?

Or maybe even better: can someone come up with a more sophisticated regexp which correctly handles more complex cases without messing up "regular" grouping of variables?

cc: @wasamasa

@wasamasa
Copy link
Collaborator

cc-mode actually tries fontifying types in casts, the code detecting this is closely related to everything with decl in its name (because depending on the context, we might be dealing with a declaration as well). I suspect the reason it doesn't work nearly as well in csharp-mode is because there's monkeypatching of those decl functions going on.

@josteink
Copy link
Collaborator

I suspect the reason it doesn't work nearly as well in csharp-mode is because there's monkeypatching of those decl functions going on.

I'm not sure I follow. Are you referring to use of the c-lang-defconst?

@wasamasa
Copy link
Collaborator

No, I'm referring to the redefinition of c-looking-at-inexpr-block and c-inside-bracelist-p.

@theothornhill
Copy link
Collaborator

This one should be fixed in the rework branch.
@philiparvidsson, can you test? I know it's been a while :)

@josteink
Copy link
Collaborator

Tested and works for me.

@philiparvidsson
Copy link
Author

I wasn't quick enough to test it out. ;-) @josteink thanks for testing it, I'll trust that it works. Great job, everyone and nice to see you again a few years later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants