Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio code 从文件路径确定文件的语言_Visual Studio Code_Vscode Extensions_Vscode Settings - Fatal编程技术网

Visual studio code 从文件路径确定文件的语言

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

在我的VSCode扩展中,我有一个字符串文件路径,需要知道它的关联语言

由于用户可以更改配置中的语言关联(
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)
})
这只会从磁盘打开文档,而不会在编辑器中显示