Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make VS Code treat files without extension as a certain language?

At work there are a lot of file without extension. They are all COBOL files, so now I manually change their associating to COBOL each time I open one. But I was looking for a way to make VS Code treat files without extension as COBOL automatically.

I know you can add file associations in the settings, but the only thing that works is to add "*": "COBOL" there, but then everything is considered a COBOL file... I also tried `"[^.]": "COBOL" hoping regex would work but it didn't.

Is there a way to do this?

like image 299
The Oddler Avatar asked Oct 27 '17 08:10

The Oddler


1 Answers

You can apply the file associations to all files in a given directory only:

"files.associations": {
    "**/RootDir/**/*": "COBOL"
}

This way, all files in /RootDir/, or one of it's sub-directories, will be mapped to COBOL.
All files outside of /RootDir/ will still be mapped as usual according to their extensions.

Suppose your /RootDir/ doesn't contain only COBOL-files, but also some other file types. In this case you can go further and define exceptions for the file associations:

"files.associations": {
    "**/RootDir/**/*.bat": "bat",
    "**/RootDir/**/*.sh": "shellscript",
    "**/RootDir/**/*": "COBOL"
}

Basically you're instructing Visual Studio Code to map all files in /RootDir/ to COBOL, except for .bat and .sh which are mapped as Batch and Shellscript, respectively.
As above, all files outside of /RootDir/ will still be mapped as usual according to their extensions.

like image 189
Martin S Avatar answered Sep 23 '22 04:09

Martin S