Visual studio code 用于检测语言和Intellisense错误的VSCode扩展API
我想创建一个vscode扩展,它提供了一个热键,可以根据文件的语言插入同一代码段的不同变体。该代码段是该语言(.py、.java、.js等)中当前单词(指针所在的单词)的简单“打印语句” 我已经使用“multi-command”扩展实现了这一点,正如我在文章中所发布的,但现在我想将其作为一个扩展,以便于每个人安装 我不能使用“代码片段或热键贡献”,因为它们比我的需要更简单, “选择并复制”当前单词,然后“插入并移动”到下一行,然后使用基于文件语言的复制项“插入代码段” 以下是我在激活功能中所做的操作:Visual studio code 用于检测语言和Intellisense错误的VSCode扩展API,visual-studio-code,vscode-extensions,Visual Studio Code,Vscode Extensions,我想创建一个vscode扩展,它提供了一个热键,可以根据文件的语言插入同一代码段的不同变体。该代码段是该语言(.py、.java、.js等)中当前单词(指针所在的单词)的简单“打印语句” 我已经使用“multi-command”扩展实现了这一点,正如我在文章中所发布的,但现在我想将其作为一个扩展,以便于每个人安装 我不能使用“代码片段或热键贡献”,因为它们比我的需要更简单, “选择并复制”当前单词,然后“插入并移动”到下一行,然后使用基于文件语言的复制项“插入代码段” 以下是我在激活功能中所做的
let disposable = vscode.commands.registerCommand('example-snippet.ExSnip', function () {
vscode.commands.executeCommand("editor.action.addSelectionToNextFindMatch");
vscode.commands.executeCommand("editor.action.clipboardCopyAction");
vscode.commands.executeCommand("editor.action.insertLineAfter");
//... "insert the snippet variation"
但在这一点上,我有两个问题:
npm安装-g yo生成器代码启动了该项目。)
我不知道如何检测运行此命令的文件的语言,以便决定使用该语言生成正确的打印语句。有没有办法检测到它
或者我完全走错了路,也许有更好的办法?我很高兴知道,因为我以前没有写过vscode扩展,提前谢谢。实现一个completionTemprovider
,并查看编辑器的语言ID
。文档
1/ vscode.TextEditor.insertSnippet(... // Property 'TextEditor' does not exist on type 'typeof import("vscode")'. Did you mean 'TextEdit'?
2/ TextEditor.insertSnippet(... // cannot find name TextEditor
3/ vscode.workspace.TextEditor.insertSnippet(... // Property 'TextEditor' does not exist on type 'workspace'