如何根据文件的扩展来获取文件的语言?
我在这个问题上遇到问题,如何使用VSCODE API根据文件的扩展来找到该文件的语言?我尝试了 vscode.languages.getlanguages
,但我认为这不是正确的。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我在这个问题上遇到问题,如何使用VSCODE API根据文件的扩展来找到该文件的语言?我尝试了 vscode.languages.getlanguages
,但我认为这不是正确的。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
您的意思是获取目标打开的文件的语言吗?因为您可以使用
window.activetexteditor?.document.languageId
。docs 在此。vscode.languages.getlanguages
是获得VSCODE注册语言的API,换句话说,获取VSCODE可以识别的语言列表。如果您想知道打开的文件的语言,则应使用window.activetexteditor?.document.languageId
。另外,您可以使用Event
vscode.window.ondidchangeactiveTextEditor
,以使您始终获得打开的文件的语言。例如,在我的扩展程序中,我像这样编码:
thescheduler
是一个对象:我的扩展名源代码为在这里,您可以将其视为参考。很抱歉,该代码的注释是中文友好的,希望它能为您提供帮助。
Do you mean get the targeted opened-file's language?For that you can use
window.activeTextEditor?.document.languageId
.The docs are here.vscode.languages.getLanguages
is the API that get the vscode's registered language,in other words,get the language list that vscode can recognize.If you want to know the opened file's language,you should usewindow.activeTextEditor?.document.languageId
.Also,you can use the event
vscode.window.onDidChangeActiveTextEditor
with it to keep you always get the opened-file's language.For instance,in my extension,I code like this:
theScheduler
is a object like this:My extension's source code are here,you can view it as a reference. I'm sorry that the code's annotation is chinese friendly,do hope it can help you some.