Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to associate a given language with a file extension in VSCode?

Is it currently possible to associate a given language with a file extension that is not typically associated with that language?

Say I have a filetype *.foo, and I want to associate it with JavaScript for syntax highlighting. Does anyone know if this is currently possible with VSCode?

I am working in a language that is syntactically similar to Visual Basic, and want to associate it with that language type. I understand that you can assign a language after the file is opened, however this is cumbersome to do each time a file is opened.

In Sublime Text for example it is possible to select "Open all with current extension as...". Does this exist yet for VSCode?

EDIT: The Visual Studio Code team has added a proper way to add both themes and languages.

https://code.visualstudio.com/updates#_yo-code-streamlined-customizations-for-vs-code

like image 273
KJ6YET Avatar asked Apr 29 '15 23:04

KJ6YET


People also ask

What is File Association in VS Code?

VS code file association. README.md. In Visual Studio Code you can add persistent file associations for language highlighting to your settings.json file like this: // Place your settings in this file to overwrite the default settings { "some_setting": custom_value, ... "

Can we use two languages in VS Code?

In Visual Studio Code, we have support for almost every major programming language. Several ship in the box, for example, JavaScript, TypeScript, CSS, and HTML but more rich language extensions can be found in the VS Code Marketplace.

What language is VS Code extensions written in?

VS Code extensions support two main languages: JavaScript and TypeScript.


2 Answers

VSCode v1.0 officially adds the File to Language Association feature. Add the following into .vscode/settings.json:

"files.associations": {
    "*.foo": "javascript"
}

You may find more details in the Visual Studio Code 1.0.0 release notes “File to language association” section.

like image 175
Evi Song Avatar answered Oct 11 '22 14:10

Evi Song


You can do it yourself: For this example I'll add the ".ino" files to the C++ plugin.

Navigate to the folder containing the corresponding plugin: C:\Users\username\AppData\Local\Code\app-0.1.0\resources\app\plugins\vs.language.cpp

Open the ticino.plugin.json file and edit contributes.language.extension. In this case, you go from:

"extensions": [ ".cpp", ".c", ".cc", ".cxx", ".h", ".hpp", ".hh"],

to

"extensions": [ ".cpp", ".c", ".cc", ".cxx", ".h", ".hpp", ".hh", ".ino" ],
like image 28
Sargeros Avatar answered Oct 11 '22 12:10

Sargeros