Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding the run-code option to a new language in VSCode

I'm currently writing my own language and I'm at a point where I would like to publish it to the VSCode-Marketplace so people can test it.

I have written a language extension and a syntax highlighter with the Yeoman-Generator and now want to merge it with my executable file that launches the interpreter, so that a file can get interpreted after clicking the run-code button.

Code Image

I now have checked multiple articles, like:

  • How to add a run button in visual studio code? - StackOverflow
  • How to define or support a code language on Visual Studio? - StackOverflow
  • Debugger Extension Guide - VSCode API

However, I haven't found anything useful.

Currently, the code-runner displays the following error, when clicking on run, or pressing the shortcut: enter image description here

(Code language not supported or defined.)

But even after a lot of browsing Google for adding new language support to the code-runner, I found absolutely nothing helpful.

(See this page, idk what Settings/Preferences they are referring to!?)

I also was not successful with tasks, as they don't seem to connect to the run-buttom or debug-button in any way.

My question is: How can I make the run-button execute a custom bash-command, when a file in my language is opened?


1 Answers

Okay, I finally did it.

For anyone wondering:

  1. You have to go to the settings and type "code-runner" into the search bar.
  2. Scroll down a little, and you should find the code runner-executor map. enter image description here
  3. Click on the "edit in settings.json" button.
  4. Now a .json-file should've opened. There are two possible scenarios: Either, there is a json-object called code-runner.executorMapBy... or not.
  5. If there is none, type code-runner.executorMapByFileExtension and let autocomplete do the job.
  6. If the json-object exists, add the file-extension and a bash command that executes your compiler/interpreter. It gets automatically executed in the directory the program-file lies in.

Now still dont know, how to include the settings in my extension, but that was already a big step. Further help is still appreciated!


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!