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

Problems with syntax highlighting and unary scope operator (C++) #254

Closed
matter123 opened this issue Jun 23, 2019 · 4 comments
Closed

Problems with syntax highlighting and unary scope operator (C++) #254

matter123 opened this issue Jun 23, 2019 · 4 comments

Comments

@matter123
Copy link
Collaborator

Copied From: microsoft/vscode-textmate#99

By @hassanbot

Original Issue

Hi! I'm not 100% sure this is the correct place to put this issue, so please redirect me if it should be placed somewhere else and I'll open one there.

Anyway, I'm having problems with the syntax highlighting when using the unary scope operator (to indicate global scope or anonymous namespace). Details below!

* VSCode Version: 1.35.1 (user setup)

* OS Version: Windows 10 Professional 64 bit, Build 17763 (Windows_NT x64 10.0.17763)

Steps to Reproduce:
1. Select the Monokai theme (though other themes probably work as well) through File -> Preferences -> Color Theme.
2. Create a .cpp file with the following code:

#include <iostream>
#include <string>

namespace hello
{
    void saySomething(std::string text)
    {
        std::cout << text << std::endl;
    }
}

void saySomething(std::string text)
{
    std::cout << text << std::endl;
}

int main()
{
    hello::saySomething("Hello world");
    saySomething("Hello world");
    ::saySomething("Hello world");
    return 0;
}

Expected syntax highlighting (in main function):
Namespaces: Green with underline.
Function calls: Green.
Strings: Yellow(ish).
Parentheses: White.
Semicolons: White.
Scope operators (::): White.

Resulting syntax highlighting:
Same as expected, except that the last call, using the scope resolution operator to indicate global scope shows in all white (see picture).
vscode_syntax_highlighting

Using the TM Scope Inspector (Ctrl + Shift + P -> Developer: Inspect TM Scopes), the scopes for the first two calls to saySomething are:
Scope operator:

  • punctuation.separator.namespace.access.cpp
  • meta.scope-resolution.cpp
  • meta.block.cpp
  • source.cpp

Function call

  • entity.name.function.call.cpp
  • meta.function-call.cpp
  • meta.block.cpp
  • source.cpp
    Parentheses
  • punctuation.section.arguments.[begin|end].bracket.round.cpp
  • meta.function-call.cpp
  • meta.block.cpp
  • source.cpp

Strings

  • string.quoted.double.cpp
  • meta.function-call.cpp
  • meta.block.cpp
  • source.cpp

Semicolons

  • punctuation.terminator.statement.cpp
  • meta.block.cpp
  • source.cpp

However, for the third call (::saySomething), the entire row (including scope operator, string, etc.) has the following scopes:

  • meta.function-call.cpp
  • meta.block.cpp
  • source.cpp

In addition to this, the closing curly bracket of the main function also gets this scope if the call to ::saySomething is present. Otherwise it gets this scope:

  • punctuation.section.block.end.bracket.curly.cpp
  • meta.block.cpp
  • source.cpp
@jeff-hykin
Copy link
Owner

I'll work on this before fixing the template syntax. And while I'm at it I'll clean up all of the :: syntax into one or two straight forward patterns.

@matter123
Copy link
Collaborator Author

It looks like the reported issue has been fixed. However there seems to be some othe regressions.

std went from entity.name.type.namespace.scope-resolution.cpp to entity.name.scope-resolution.cpp
ditto for hello in main

the hello in namespace hello is because of namespaces no longer having entity.name.type Though im not sure why thats an issue as the monokai theme is based on the sublime text one and hello has the follow scopes in sublime text 3:
source.c++ meta.namespace.c++ entity.name.namespace.c++

Image

vscode 1.35.1 Better Syntax 1.11.17
Screenshot-20190623154817-352x442 Screenshot-20190623154732-358x447

@jeff-hykin
Copy link
Owner

jeff-hykin commented Jun 23, 2019

Those scopes (with the extension) sound correct, although it is a shame the theme doesn't highlight hello in namespace hello.

@matter123
Copy link
Collaborator Author

matter123 commented Jun 23, 2019

Yeah because there should be support for that See https://github.com/microsoft/vscode/blob/master/extensions/theme-monokai/themes/monokai-color-theme.json#L208, maybe that change didn't make the 1.35.1 cut.

Edit: yep 1.35.1 monokai theme is missing color for entity.name.namespace So this issue should resolve itself in the next couple of weeks when 1.36 becomes stable.

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

No branches or pull requests

2 participants