Rich P
Rich P

Reputation: 51

How to enable JavaScript IntelliSense for custom file extensions in VS Code?

The question title says it all. My organization uses a non-standard file extension on source code written using JavaScript. Changing the file extension to ".js" seems to activate IntelliSense.

However, I was wondering if the IntelliSense could be activated using the non-standard file extension.

Upvotes: 4

Views: 1937

Answers (4)

snnsnn
snnsnn

Reputation: 13620

Those who needs this functionality for a plugin can use the following contribution in their package.json files:

"contributes": {
  "languages": [
    {
      "id": "javascript",
      "extensions": [
        ".myext"
      ]
    }
  ],
}

This defines a file extension call myext that will be treated as javascript which comes very handy for adding intellisense to virtual files.

https://code.visualstudio.com/api/references/contribution-points#contributes.languages https://code.visualstudio.com/api/extension-guides/virtual-documents

Upvotes: 0

Matt McCutchen
Matt McCutchen

Reputation: 30879

From this issue (found in a web search), it sounds like the TypeScript language service does not support non-standard extensions, so you won't be able to get semantic features like type-based completions (which I assumed was what you meant by IntelliSense). The techniques described in the other answers may give you basic syntax highlighting.

Upvotes: 0

user6080677
user6080677

Reputation:

Click the bottom right of the window where it says "Plain Text" or the name of the detected language. This will bring up a menu at the top that lets you change it for the current session and also configure that specific extension to always be interpreted as JS. VS Code Bottom Toolbar VS Code Language selection Menu

Upvotes: 5

jabacchetta
jabacchetta

Reputation: 50028

Use the files.associations setting:

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

Upvotes: 1

Related Questions