2017-02-22 61 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) 
}) 

这只能从磁盘打开该文档,它不会显示在编辑器中。