question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax highlighting broken (because incorrect 'file type' in editor)

See original GitHub issue

Sanity check

  • I certify that the redhat.ansible extension is in use and the language of the document in this bug report shows up as Ansible

Summary

Unfortunately, https://github.com/ansible/vscode-ansible/issues/293 was closed prematurely, because while the original reporter was helped to manually fix his problem, the problem still persists for new users with no indication other than a closed issue on the source repo as how to fix it.

To be clear: I understand how I can fix the issue for myself, but that still leaves the open issue that syntax highlighting does not work for people that I think should be addressed.

I believe the root cause is the order in which this extension and the YAML extension (also from Red Hat, which was automatically installed along with this extension for me in a fresh VSCode install) are installed. Without further testing (which I can carry out if needed) I would guess that if the user already has the YAML extension installed when installing the Ansible extension, then the Ansible extension takes ‘ownership’ of the .yml association, but that if neither extension is installed, after installing the Ansible extension, the YAML extension is installed as a dependency and then takes over the association.

Extension version

v0.7.1

VS Code version

1.63.2

Ansible Version

Version: 1.63.2
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Date: 2021-12-15T09:40:02.816Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19044

OS / Environment

Windows 10, WSL, Fedora 31, ansible-lint 5.1.3 using ansible 2.11.4

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
netsandboxcommented, Feb 4, 2022

@Gaibhne

I believe the root cause is the order in which this extension and the YAML extension (also from Red Hat, which was automatically installed along with this extension for me in a fresh VSCode install) are installed. Without further testing (which I can carry out if needed) I would guess that if the user already has the YAML extension installed when installing the Ansible extension, then the Ansible extension takes ‘ownership’ of the .yml association, but that if neither extension is installed, after installing the Ansible extension, the YAML extension is installed as a dependency and then takes over the association.

I can’t confirm this, I installed first the YAML extension and then the Ansible extension and all Ansible files are still use YAML language.

@ganeshrn It doesn’t help the user if he must enable the Ansible language for every file. Imagine a folder with 100 Ansible files 😱 So best would be if auto-detection would work out of the box. At least you should provide an example files.associations block in the README.

I use this one:

"files.associations": {
    "**/*playbook*.{yml,yaml}": "ansible",
    "**/defaults/*.{yml,yaml}": "ansible",
    "**/handlers/*.{yml,yaml}": "ansible",
    "**/meta/*.{yml,yaml}": "ansible",
    "**/playbooks/*.{yml,yaml}": "ansible",
    "**/requirements.{yml,yaml}": "ansible",
    "**/tasks/*.{yml,yaml}": "ansible",
    "**/vars/*.{yml,yaml}": "ansible"
}

This one is mainly inspired from ansible-lint’s detection rules: https://github.com/ansible-community/ansible-lint/blob/03fe3936d8015190744d3756a0a3361380a05adb/src/ansiblelint/config.py#L14-L40

0reactions
ssbarneacommented, May 25, 2022

Not a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Syntax highlighting breaks if the file is too big (#34240) - GitHub
Steps to Reproduce: open small (less than 10MB) file, type any text, add a comment (#blah blah) select syntax, should see color change...
Read more >
Javascript syntax highlighting it not working
I have an .html file which is part of a large project, and in the middle of the file, syntax highlighting just flat...
Read more >
Syntax highlighting broken on correct code
This issue's particularly strange because code does seem to compile as long as we start out in a template, which I'd presume because...
Read more >
Pycharm utils.py not getting syntax highlight - Stack Overflow
Look for your file name mapped to the Text type or to the Auto-detect file type by content type. Remove the incorrect mapping...
Read more >
Syntax highlighting doesn't appear to work correctly - GitLab
Syntax highlighting doesn't appear to work correctly. Summary. On some themes, the syntax highlighting seems pretty broken. Take this file for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found