2017-02-22 59 views
0

在我的VSCode擴展中,我有一個字符串filePath,並且需要知道它的關聯語言。從文件路徑中確定文件的語言

由於用戶可以更改配置中的語言關聯(files.associations),所以只檢查已知的擴展名不起作用。

VSCode API中是否有這樣的功能?或者我需要使用vscode.workspace.getConfiguration("files").get("associations")從配置中提取信息?

回答

1

嘗試使用workspace.openTextDocumentdocument.languageId

import { workspace } from 'vscode'; 

workspace.openTextDocument(pathToMyFile).then(doc => { 
    console.log(doc.languageId) 
}) 

這隻能從磁盤打開該文檔,它不會顯示在編輯器中。