0

I'm trying to automate some tasks within VSCode, specifically with a particular extension. My particular interest is https://github.com/huggingface/huggingface-vscode. I want to collect outputs from https://raw.githubusercontent.com/huggingface/huggingface-vscode/master/assets/ext-output.png.

Here's what I aim to achieve:

  • Load a project.
  • Open a file and navigate to a specified location within the file.
  • I already have the locations of the file where the cursor needs to be for getting the auto-completion suggestions
  • Trigger auto-completion at that location.
  • Collect the results of the auto-completion.
  • Save those results to a file.

Is there any way to programmatically control a VSCode extension to perform these steps?

I want to do this for Github Copilot and huggingface-vscode specifically.

I am okay with a solution that uses an external program (let's say Python code) other than VS Code to drive VS Code to get the desired result.

Example of the screen is attached what I have to capture.

starball
  • 20,030
  • 7
  • 43
  • 238
Exploring
  • 2,493
  • 11
  • 56
  • 97
  • what qualifies where to navigate to? where in the file is it? what's the deterministic procedure to get to the desired location invariable with the contents of the file? – starball Aug 15 '23 at 03:30
  • also, I'm on the fence of whether or not this counts as multiple questions (see [/help/dont-ask](/help/dont-ask)) – starball Aug 15 '23 at 03:30
  • @starball I already have the location for which I have to collect the auto-completion suggestion. I have spent a lot of time finding out how to achieve this kind of automation. Any feedback is will be appreciated. – Exploring Aug 15 '23 at 04:12
  • Does that Output appear in a completion/suggestion widget? And is that all you want - what appears in a suggestion widget? – Mark Aug 17 '23 at 22:11
  • I'm confused. you want to write an extension using the VS Code API to achieve this? Or a solution that doesn't require writing a VS Code extension using the VS Code API? – starball Aug 18 '23 at 00:37
  • @starball I have to do this programmatically. I don't mind either way. But is there a VS Code API that I can drive the editor in an automated fashion? I am not aware of any. – Exploring Aug 18 '23 at 04:16
  • You mention getting the results of an auto-completion but you show the Output Panel. – Mark Aug 18 '23 at 15:29
  • In the output panel you can see the response from the server. I need to capture that part. – Exploring Aug 18 '23 at 16:56
  • So you need to capture both the `Input to API` and `Output from Api` parts? You can capture suggestions that would be triggered at a position, but that is only the `Output from API` part. – Mark Aug 22 '23 at 17:49
  • I need to capture both the Input to API and Output from API. – Exploring Aug 25 '23 at 16:51

1 Answers1

0

I'd take a look at the following commands:

  • workbench.action.openWorkspace prompts the user to select a workspace to open.
  • workbench.action.files.openFile prompts the user to select a file to open.
  • workbench.action.gotoLine prompts the users for a line and column to go to.
  • For GitHub Copilot, github.copilot.acceptCursorPanelSolution. Also the following:
    • github.copilot.previousPanelSolution
    • github.copilot.nextPanelSolution
  • For HuggingFace VS Code, at the time of this writing, I don't see any commands exposed for suggestions right now. See the contributions" > commands` property in its extension manifest.
  • I don't know about selecting the result of the suggestion.
  • editor.action.clipboardCopyAction
  • editor.action.clipboardPasteAction
  • workbench.action.files.save

You can run commands using the VS Code API using executeCommands. You can bind a sequence of commands to a keyboard shortcut using runCommands.

If you're using the VS Code API, though, instead of the command palette or keyboard shortcuts, you can also use Workspace#openTextDocument to open documents.

starball
  • 20,030
  • 7
  • 43
  • 238
  • thanks a lot for pointing this out. But I presume if I adopt this approach, I need to write a VS Code plugin. Is it possible to do this automation from outside of VSCode, i.e. from python code that loads a project, trigger auto-completion for a file, and then collect the auto-completion. – Exploring Aug 19 '23 at 03:29
  • @Exploring you asked for an API. I told you about the API. and a way to potentially work within VS Code without writing an extension. If you want to drive VS Code with an external program, maybe you should actually ask for that in your question post :p – starball Aug 19 '23 at 05:45
  • thanks a lot for the giving me the ropes to understand how can I do this. I will create separate post how to drive vs code from external program. Thanks again. – Exploring Aug 19 '23 at 07:38
  • 1
    @Exploring I think it's okay if you just edit this question to make it clear that you'll accept answers that use programs other than VS Code to drive VS Code to get the desired result :) – starball Aug 19 '23 at 07:56