Visual studio code 从文件路径确定文件的语言
在我的VSCode扩展中,我有一个字符串文件路径,需要知道它的关联语言 由于用户可以更改配置中的语言关联(Visual studio code 从文件路径确定文件的语言,visual-studio-code,vscode-extensions,vscode-settings,Visual Studio Code,Vscode Extensions,Vscode Settings,在我的VSCode扩展中,我有一个字符串文件路径,需要知道它的关联语言 由于用户可以更改配置中的语言关联(files.associations),因此仅检查已知扩展名不起作用 VSCode API中有这样做的功能吗?或者我需要使用vscode.workspace.getConfiguration(“文件”).get(“关联”)从配置中提取信息吗?尝试使用workspace.openTextDocument和document.languageId: import { workspace } fro
files.associations
),因此仅检查已知扩展名不起作用
VSCode API中有这样做的功能吗?或者我需要使用
vscode.workspace.getConfiguration(“文件”).get(“关联”)
从配置中提取信息吗?尝试使用workspace.openTextDocument
和document.languageId
:
import { workspace } from 'vscode';
workspace.openTextDocument(pathToMyFile).then(doc => {
console.log(doc.languageId)
})
这只会从磁盘打开文档,而不会在编辑器中显示