39

It seems like VS Community with python tools has a better syntax highlighting than VS Code with "Python" by Don Jayamanne. As you can see in the picture attached, VS Community highlights in ¿purple? the packages imported, and lightblue for classes while VS code just don't. Comparison

2
  • You can take a look at color schemes. Commented Jul 24, 2017 at 23:57
  • 1
    thanks @WillemVanOnsem, but I don't think those support python or even vs code. Commented Jul 25, 2017 at 1:02

8 Answers 8

79

I ran into the same issue and some VS Code themes are not supporting syntax highlighting atleast for me. I tried with Ruby and Python and the theme I was using was Dark(Visual Studio).

Changing to Dark+ (Default Dark) did the trick for me.

Goto Preferences -> Color Themes and choose Dark+(Default Dark) or something similar.

Hope it helps.

Sign up to request clarification or add additional context in comments.

3 Comments

nope, I was already using Dark+ when I sent the prntscn. Dark+ is better than Dark for me because it highlights the imports different, but still not highlighting classes. Thanks!
Instead of using the VScode Monkai I downloaded Monokai Pro and activated Monokai Classic. It fixed my issue :). Indeed it's a theme issue.
Changing to Default Dark+ does not solve the issue. This is an ongoing issue in VSCode as mentioned here github.com/microsoft/vscode-python/issues/9961. I have posted a workaround by overriding the default color schemes.
28

Looks like this issue has been bouncing around between maintainers of VSCode, MagicPython, and the Python extension

A quick workaround is to simply override your color theme as instructed here. For example, if you are using Default Dark+ color theme, you can add this to settings.json:

"editor.tokenColorCustomizations": {
    "textMateRules": [
      {
        "scope": "meta.function-call.generic.python",
        "settings": {
          "foreground": "#DCDCAA"
        }
      }
    ]
  },

Now callables are highlighted correctly as seen below:

enter image description here

5 Comments

Yep! this makes it look better! any clue about Classes highlighting? what would be the scope?
Classes are also highlighted when invoked since it is treated as callables (can't believe this is still an issue after 3 years in VSCode) EDIT: it is highlighted with the same color as all callables though (i.e. same color as functions/methods).
Right, that was my question, if you found a way to highlight class name in new SomeClass() with a different color. I agree with you on the unbelievableness of this missing feature. Thanks!
@alete have you tried using PyLance as your language server? The highlighting somehow looks similar to the picture you posted (i.e. different color for imported modules and module members, classes, etc). Not exactly the same, but closer.
This worked great for callables, but what about variables?
10

What did the trick for me, was to keep the Window: Auto Detect Color Scheme disabled. Attaching a picture of this checkbox in my answer:

enter image description here

1 Comment

Weirdly, enabling this fixed the issue for me :D
6

Try MagicPython systax highlighter from extensions.

1 Comment

I've got it, but it doesn't highlight classes. I've been digging in it's issues but it seems like it cannot be done.
1

I was facing the same issue. I used the Chromodynamics theme which is compatible with MagicPython. You can find it here or install directly in the VS-CODE

https://github.com/MagicStack/Chromodynamics

Comments

1

I had problems with syntax highlighting with python in vs code and the solution was that my file name did not end with ".py"

Comments

1

I've tried some workarounds, but the one that worked for me was installing: Python extension for Visual Studio Code

It comes with much more than you need, but solves the issue without patchwork.

VS Code About: Version: 1.52.1 (system setup)

settings.json:

{
    "window.zoomLevel": 0,
    "workbench.editorAssociations": [
        {
            "viewType": "jupyter.notebook.ipynb",
            "filenamePattern": "*.ipynb"
        }
    ],
    "git.ignoreMissingGitWarning": true,
    "workbench.colorTheme": "Default Dark+",
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "python.languageServer": "Microsoft",
}

enter image description here

Comments

0

I had the same problem, Python code was not highlighted as expected with MagicPython. I also had the extension "Familiar Java Themes" (v0.1.7) installed and was using the theme "Eclipse Light Theme" before. After I disabled this extension, Python highlighting was done properly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.