How to run scheme program in VS Code - visual-studio-code

Just started to learn SICP (Structure and Interpretation of Computer Program). I installed mit-scheme compiler. I am able to run the interpreter by just typing scheme in terminal. I also have VSCode installed along with linting support for scheme.
Now I need to write, compile and launch the scheme program from VSCode.How do I do that. I dont need to debug line by line. I am new to VS code.
PS: I can write program, edit it and check for lint errors. I am unable to launch the scheme compiler out of the box. I am missing some steps in editing few jsons to get this done.
PS PS: I prefer VSCode and I want mit-scheme to interpret/ compile my program. Do not want to use racket or code runner extension. Thanks!

Main menu->Terminal->Configure tasks
Create new task:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "run scheme",
"type": "shell",
"command": "scheme",
"args": ["<", "${file}"]
}
]
}
Open file with scheme code
Main menu->Terminal->Run Task->run scheme

on mac os with chezscheme
install chezscheme
brew install chezscheme
install code runner extension of vscode
setup code runner in setting.json
"code-runner.executorMap": {
"scheme": "chez --script"
},
run scheme
create hello.ss
; Hello World
(display "Hello World")
(exit)
click run code button in top right or menu.

Most Scheme systems do not compile. They are interpreters. That is the reason why the book is called Structure and Interpretation of Computer Programs. The typical interaction with an interpreter is the REPL, the Read Eval Print Loop. The easiest way to write Scheme code is to use an editor like Emacs and execute run-scheme. After that you can send any s-expression with Ctrl-x Ctrl-e from the editor to the interpreter. Emacs shows the result in the REPL window.

What a coincidence! I'm learning SICP too.
I'm on a Mac. My way of running scheme programs in VS code is control+shift+ to open its terminal and the input scheme > foo.sch. (replace foo.sch with you file name).
And you can do this in the built-in Terminal app too, without VS Code.

Related

Setting CMake compilation options in VS Code

I recently started using VS Code and I have a question. How do I set the values of the compilation options defined in CMakeList.txt?
For example if the following option is set in the CMakeList.txt:
option(BUILD_WITH_TESTS "Build with tests." OFF)
Then I can set this value when building using for example the CMake GUI:
selecting option value
Does a similar toolkit exist in VS Code? What are the ways to set value BUILD_WITH_TESTS when building a project in VS Code?
At the moment I'm using VS Code with the plugin CMake Tools 1.5.3. But I do not find such functionality as a CMake GUI there.
You have several choices, depending on your exact requirements.
The CMake Tools extensions is a good choice, but it doesn't come with a GUI. If you want to use cmake-gui, you could still use it in your vscode CMake build directory, by executing cmake-gui <path_to_build_folder> in the vscode terminal.
In case you need to run this command often, you could customize your vscode settings, for a better cmake-gui integration, by using the Command Runner extension, which allows to run custom shell commands. After installation add the following to your settings.json:
"command-runner.commands": {
"cmake-gui": "cmake-gui ${workspaceFolder}/build"
}
and, if you like, a key binding to keybindings.json
{
"key": "ctrl+alt+1",
"command": "command-runner.run",
"args": { "command": "cmake-gui" }
}
Personally I would do none of the above methods, but just use ccmake in the terminal.
All of the above describes how to change settings in the current existing build directory (which is usually created by CMake Tools on first launch). However, the settings will get lost if you switch to a different compiler or delete the CMake cache in any other way.
To persist your settings and configure CMake by default with your preferred configuration, you can add your CMake arguments to your vscode workspace settings (in ${workspaceFolder}/.vscode/settings.json), e.g.
{
"cmake.configureArgs": [
"-DBUILD_WITH_TESTS=ON"
]
}

How to use ``OUTPUT`` in VSCode?

I've always used Sublime Text 3 for Python Coding, in which Build Systems were the only way of running a file.
Now I'm starting C++ programming, and I'm using VSCode. The problem I have is that, in that dock where:
PROBLEMS , OUTPUT , DEBUG CONSOLE , TERMINAL
The only thing I've had trouble with, is OUTPUT window, because nothing ever appears, so if I wanna run either Python or C++ code, it won't show anything to let me know what output would the program give. And if I just try to run it (pressing f5) it, it will open terminal and run it from it.
I saw something called Tasks but I don't know how they work, and they seem to be like Build Systems from Sublime Text 3.
I wanna use OUTPUT window, how can I get it working?
to run code in the output section of visual studio code you can use the extension Code Runner
just install, then press CTRL + ALT + N to run the file (supports c++ & python)
I wanna use OUTPUT window, how can I get it working?
As it stands now, you can not use the Output Window as a way to log code, that is reserved for native logs like Window, Main, Shared or Extensions to log their output using channels. There is a good candidate called the Debug Console.
You can log to the Debug Console using a launch.json configurable:
First, create a launch.json for your program.
Then add the following properties, in addition to whatever you need to get your program going:
internalConsoleOptions
Controls when the internal debug console should open
redirectOutput
Both of these used in tandem will open the 'Debug Console' instead of terminal and just provide the necessary output; though it still sends to terminal should you still want it:
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"internalConsoleOptions": "openOnSessionStart",
"redirectOutput": true
}
]
For c++ they have an extensive tutorial on how to debug and run: https://code.visualstudio.com/docs/languages/cpp (in addition to setting up launch.json and tasks.json files respectively https://code.visualstudio.com/docs/cpp/config-mingw#_build-helloworldcpp)
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install formulahendry.code-runner

How to run SML REPL in Visual Studio Code

I am trying to use SML/NJ in Visual Studio Code editor but can't figure out how to run SML REPL in Visual Studio Code. I have installed SML extension in Visual Studio Code but no documentation is available. How to configure SML in Visual Studio Code?
Have you installed latest SML/NJ version ? Download from here https://www.smlnj.org/dist/working/index.html
Install it.
Now open VSCode, go to menu Terminal > New terminal.
In terminal type sml and confirm command. It will enter the SML/NJ REPL mode.
On linux, you can open a bash terminal with Ctrl-j and use the sml command (if you have it installed) to get an integrated REPL.
To run REPL one can set-up a task for VSCode like this:
{
"label": "SML REPL",
"type": "shell",
"command": "sml ${file}",
}
this task will run current file with REPL.
It is also possible to use problem matcher and then issues (at least with syntax) will be highlighted directly in editor.

Running simple terminal commands in command palette VS Code

Is it possible to run simple terminal commands in Command Palette? Or an extension for it?
For example, something like rm unwantedfile.txt would be super useful to do in via command palette rather than having to open up the integrated terminal or do the task via mouse (mainly interested in not having to take my hands off the keyboard).
I know there's Edit with Shell Command, but it doesn't appear to be able to edit outside the file itself.
You can either use VS Code built-in functionality using shortcuts. Just add to keybindings.json:
{
"key": "cmd+shift+R",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "clear; rails server\u000D"
}
},
Or you can take a look at this extension, Command Runner, that does exactly what you're looking for.

Does Visual Studio Code work with PowerShell in the Command Palette?

With Visual Studio Code (not the traditional Visual Studio IDEs), can you run PowerShell in the Command Palette? I ask because I commonly use it in the full IDE.
I have not seen PowerShell mentioned in the documentation, other than for basic syntax highlighting. I have tried it with no success. Is it unsupported, or is it an optional feature I can configure somehow?
Note: to those voting up the PowerGUI answer, it is not correct as it references the wrong edition of Visual Studio for this question. It is helpful if you are using the full IDE, but not the new editor named: Code.
This was the first problem I wanted to solve in VSCode. I did not find a way to
type PowerShell commands but I have found a way to create and run PowerShell tasks.
In the command palette type and choose Tasks: Configure Task Runner. It will
show you a json file configured for the default task runner.
I replaced the content with this
{
"version": "0.1.0",
"command": "PowerShell.exe",
"isShellCommand": true,
"args": [
"-NoProfile",
"Invoke-Build.ps1"
],
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"showOutput": "always"
},
{
"taskName": "Test",
"isTestCommand": true,
"showOutput": "always"
},
{
"taskName": "Build, Test",
"showOutput": "always"
}
]
}
As a result in the command palette I can choose and run my predefined tasks (Build, Test, and combined Build, Test). I can add other tasks and probably bind them to some hotkeys. This is not exactly what I would like to have in VSCode for PowerShell but for the preview it is at least something.
P.S. This just my first experiment that somewhat worked. It is not perfect, more likely. There are many configuration parameters for this json file that I have not tried yet.
With version 0.10.1 of Visual Studio Code, you can run and debug PowerShell. Here is a sample launch.json that I use:
{
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell",
"type": "PowerShell",
"program": "MyScript.ps1",
"args": "-Verbose"
}
]
}
Unfortunately, I cannot get the args to work (for more details, see: https://github.com/PowerShell/vscode-powershell/issues/24). Another problem I have is that Read-Host does not work with VS Code (for more details, see: https://github.com/PowerShell/vscode-powershell/issues/29). Definitely some rough edges.
Here's how you can configure the Powershell task to execute the currently opened .ps1 file without any Invoke-Build dependency:
{
"version": "0.1.0",
"command": "PowerShell.exe",
"isShellCommand": true,
"args": [
"${file}"
],
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"showOutput": "always"
},
{
"taskName": "Test",
"isTestCommand": true,
"showOutput": "always"
},
{
"taskName": "Build, Test",
"showOutput": "always"
}
]
}
Note: This is just a slight modification of Roman's answer (My edit to his answer was rejected).
Open the Debug view, in the View Bar select Debug from the View menu or press Ctrl + Shift + D.
In the Launch Configuration dropdown (shown in the following screenshot), select Add Configuration...
The launch.json configuration will open in the editor, type PowerShell and select the debug configurations you want, as shown in the following screenshot.
Save the launch.json file and select the debug configuration you want from the Launch Configuration dropdown:
Now you can debug PowerShell scripts through VSCode.
The Scripting Guys wrote a comprehensive 2 part blog post on this topic, like everything else they write, it's well worth a read if you're new to VSCode and PowerShell.
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/06/debugging-powershell-script-in-visual-studio-code-part-1/
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/13/debugging-powershell-script-in-visual-studio-code-part-2/
EDIT: I am aware that this question is several years old, but I came across it before I found any up to date information on how to set up PowerShell debugging in VSCode
As of version 0.10.3 there is now a PowerShell extension written by Microsoft that will enable writing PowerShell with IntelliSense and highlighting in Visual Studio Code
http://blogs.msdn.com/b/powershell/archive/2015/11/17/announcing-windows-powershell-for-visual-studio-code-and-more.aspx
At least in V1.4 (July 2016) this has been made a lot simpler.
The relevant documentation can be found here:
https://code.visualstudio.com/docs/editor/integrated-terminal
Essentially all you're doing is adding an entry to the settings.json file for User Settings.
Adding the following value:
// 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows":"C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
IMG: Shows the User Settings settings.json file and the successful Integrated Console showing the PowerShell prompt:
An "Integrated Terminal" is now integrated into Visual Studio Code. This is a PowerShell Terminal in Windows. (Likely BASH in Linux / MacOS). The terminal appears in a panel at the bottom of the code editor, not in the Command Pallete.
Keyboard Shortcut to open Terminal: CTRL + `
Sources:
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
https://code.visualstudio.com/docs/getstarted/keybindings
I confirmed in version 1.19.2. Not sure when the feature was first integrated.
There is a much easier way to run PowerShell, no configuration needed:
Install the Code Runner Extension
Open the PowerShell code file in Text Editor, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code, or right click the Text Editor and then click Run Code in context menu, the code will run and the output will be shown in the Output Window.
Besides, you could select part of the PowerShell code and run the code snippet. Very convenient!
PowerGUI tool provides a nice interface to Visual Studio. The goal of this extension is to bring PowerShell development into Visual Studio.
Here is how it looks -
Along with IntelliSense, the PowerGUI Visual Studio Extension provides the following features and more to make it easier to work with PowerShell.
PowerShell file and project types: You can create/edit PowerShell code files and assemble them into projects with more than one file.
PowerShell code snippets: The code snippet feature can be used for PowerShell code.
PowerShell console window: This feature provides the PowerShell console environment within Visual Studio IDE. This allows you to run commands or view output of scripts. Figure B shows the console window opened in the IDE.
PowerShell debugging: This feature is why I installed the extension; it provides a way to debug scripts within Visual Studio. It's a straight-forward way to locate syntax or logical problems in a script.
Syntax highlighting and script analysis: These are more Visual Studio features made available to PowerShell development.
In order to install the PowerGUI Visual Studio Extension, PowerGUI must be installed, with the caveat that the correct version of each product is installed.
Download Here
It also provides Debugging facility which is the best part I like as a developer.
Thanks!