Reputation: 268
In my VSCode extension I have a string filePath and need to know its associated language.
As the user can change the language associations in the configuration (files.associations
) only checking for the known extensions does not work.
Is there a functionality in the VSCode API to do that? Or do I need to extract the information from the configuration using vscode.workspace.getConfiguration("files").get("associations")
?
Upvotes: 0
Views: 103
Reputation: 65223
Try using workspace.openTextDocument
and document.languageId
:
import { workspace } from 'vscode';
workspace.openTextDocument(pathToMyFile).then(doc => {
console.log(doc.languageId)
})
This only opens the document from the disk, it will not show it in the editor.
Upvotes: 1