How can I compile and run my Pascal code in VS code? - json

Is there a way I can modify tasks.json and keybingings to create shortcuts for compiling the code and running it?
After a ton of googling I came up with this. When I press ctrl+shift+b it compiles but command prompt with the program doesn't pop up.
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "cmd",
"args": ["/C"],
"tasks": [
{
"taskName": "Compile",
"suppressTaskName": true,
"isBuildCommand": true,
"args": ["\"fpc ${file}\""]
},
{
"taskName": "Run",
"suppressTaskName": true,
"isBuildCommand": true,
"args": ["\"start $[fileBasenameNoExtension}.exe\""]
}
]
}

Pascal is stil alive and kicking. What I meant by Pascal is the modern object Pascal programming, not your daddy's Pascal. I've been making many apps for all platforms using (mainly) Free Pascal, with Lazarus IDE (for GUI apps) and VS Code (for non-GUI apps). Modern Pascal can do whatever every other languages out there are able to do. Check out The Big 5 Pascal of Today.
Now… to be able to work use Pascal with VS Code. First, install Free Pascal for sure. Then install the OmniPascal extension. And read my guide Free Pascal and VS Code. I provide many useful tasks in there to help you work with Pascal, including code formatting. It's in Indonesian but you could use Google Translate to read it in English (or whatever language you like).
HTH.

this is my tasks.json and it works very well
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "PAS build active file",
"command": "fpc",
"args": [
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}

Related

use a different .zshrc for vscode internal terminal

I'm using zsh from vscode integrated terminal
i also use hyper terminal, warp and iterm2 for other purposes but i like to use the integreated terminal while in vscode. i actually enjoy my heavy .zshrc config on external terminals, but i often get the popup "your shell environment is taking too long to load" from vscode. Tbh, i don't mind the popup itself, but i think that a lot of the features that are useful outside vscode are not needed inside.
How can i set a different .zshrc to load only to be used by the vscode integreated terminal ?
tried conditional loading from my .zshrc but don't like it
tried setting it in the vscode-settings.json
this self-answer confused me more
this i think points in the right direction but i am not sure how to use task.json
my env:
macOS 13.1 22C65 arm64
Apple M1 Max
vscode (1.74.11ad8d514439d5077d2b0b7ee64d2ce82a9308e5a for arm64)
zsh 5.9 (arm-apple-darwin22.1.0)
These are the settings to change in “settings.json”:
I created 3 profiles:
zsh-minimal with the vscode minimal config -> new ZDOTDIR
zsh-full with my usual heavy config -> probably not necessary since it is $HOME by default i think
bash, just in case i fu everything
set to null old profiles ( zsh and zsh(2)) to delete them from profiles selection dropdown menu, as per official documentation.
“terminal.integrated.defaultProfile.osx”: “zsh-minimal”,
“terminal.integrated.profiles.osx”: {
"zsh-minimal": {
"title": "zsh-minimal",
"path": "/opt/homebrew/bin//zsh",
"icon": "terminal",
"color": "terminal.ansiMagenta",
"args": [
"-l",
"-i"
],
"cwd": "${workspaceFolder}",
"env": {
"ZDOTDIR": "/Users/MYUSERNAME/.homesick/repos/MYUSERNAME-dotfiles/home/vscode_zsh"
},
},
"zsh-full": {
"title": "zsh-full",
"path": "/opt/homebrew/bin//zsh",
"icon": "terminal",
"color": "terminal.ansiCyan",
"args": [
"-l",
"-i"
],
"cwd": "${workspaceFolder}",
"env": {
"ZDOTDIR": "/Users/MYUSERNAME/"
},
},
"bash": {
"title": "bash",
"path": "/bin/bash",
"icon": "terminal",
"color": "terminal.ansiWhite",
"args": [
"-l",
"-i"
],
"cwd": "${workspaceFolder}",
},
"zsh": null,
"zsh (2)": null,
}

How do I display my HTML/CSS files on a browser via Visual Studio Code on Mac?

I HAVE looked around to find the solution and some fellows already expressed the command:
{
"version": "0.1.0",
"command": "Chrome",
"osx": {
"command": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
},
"args": [
"${file}"
]
}
after you press Cmd+Shift+p and entering Configure Task Runner
This thing is, I don't see that option, thus preventing me from completing this step. Perhaps I am ignorant as to how to work in this still.
Try specifiying a "taskName": attribute in your build task. i.e.
{
"version": "0.1.0",
"taskName": "MyName",
"command": "Chrome",
"osx": {
"command": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
},
"args": [
"${file}"
]
}
Download this: https://marketplace.visualstudio.com/items?itemName=peakchen90.open-html-in-browser. It is written in an asian language but it is very simple to handle, when your html file is opened, save it, right click and click the asian words. It will open in your default browser.

Capturing Visual Stadio Command Line Compilier (CL.EXE) Output With Regular Expressions

I've been trying to set up VS command line compiler to use in VS code IDE. I have read the examples and can use GCC with no problem but need to use VS compiler now too.
I have tried a single line problem matcher and I multiple one. Yet VC code seems to capture nothing.
Here is an example of output with error from the compiler:
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
helloWorld.c
..\Code\helloWorld.c(7) : error C2143: syntax error : missing ';' before '}'
Using the regExpr Expression:
(.*\n){2,3}\S+(\d+)\W+:\s(\bwarning|error\b\s\w+):\s(\w+\s\w+)\s+:\s(.*)$
It captures all the info I need (checked my work here: https://regex101.com/)
but when I put it in a Tasks.json file for VS code it doesn't work.
{
"version": "0.1.0",
"command": "Build",
"args": [
"${fileBasename}"
],
"isShellCommand": true,
"tasks": [
{
"taskName": "Build",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// No args
"args": [
"all"
],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "(.*\n){2,3}\\S+(\\d+)\\W+:\\s(\bwarning|error\b\\s\\w+):\\s(\\w+\\s\\w+)\\s+:\\s(.*)$",
"file": 1,
"line": 2,
"severity": 3,
"code": 4,
"message": 5
}
}
}
]
}
Anyone know how to setup VS Code IDE to use VS command line compiler? Any help would be greatly appreciated
The first two lines in your output can be avoided by adding /nologo flag to the compiler. So your tasks.json should be:
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"showOutput": "always",
"args": [
"all"
],
"problemMatcher": {
"owner": "cpp",
"severity": "info", // treat note as info
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*)\\((\\d+)\\):\\s+(warning|error|note)\\s*(\\w+)?:\\s+(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
}
}
}
]

Is it possible to define global compile tasks (e.g. file-extension-dependent) for Visual Studio Code?

I set up a tasks.json file to build my C code in VS Code, which also includes a problem matcher.
{
"version": "0.1.0",
"command": "gcc",
"args": ["-Wall", "-o", "${fileBasenameNoExtension}", "${fileBasename}"],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
Since I use variable substitution for the source file and the executable, it would work as portable solution for comfortable compilation of single source files. Unfortunately, VSC requires the tasks.json to be defined separately for each project, i.e. each folder. Is there any way to derive the suitable build task from file extension globally for any file?

VirtualBox crashes after starting gdb in Visual Studio Code

I'm a new apprentice at my company, so I'm new to Stackoverflow and coding in general, please bear with me.
I wanted to get away from the text editors (gedit and geany) I used before and started looking for an IDE. I chose to use Visual Studio Code, and started setting it up. I had to set up a compiler and a debugger. The compiler worked, but the debugger is making trouble.
I am running Debian 64 bit in a virtual machine, the host system is windows 10 64 bit. This is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "/usr/bin/gdb",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
},
{
"name": "C++ Attach",
"type": "cppdbg",
"request": "attach",
"program": "/usr/bin/gdb",
"processId": "${command.pickProcess}",
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
}
]
}
As you can see, I set the program to gdb. Now if i try to debug my code with "C++ Launch" the terminal window for the gdb debugger will open, and the VSCode window looks like it is in debug mode.
Shortly before my Virtual machine crashes
Then my Virtual Machine just crashes, without any error message. My virtual machine client says canceled. I looked into every logfile that seemed at least a little relevant. I checked the virtual machine log. I google this problem in various ways. I checked if it crashes even if I close gdb before the crash (it does). And still I haven't found a way to prevent this crash from happening.
I asked most of my co-workers and they don't know an answer either.
This is my first post/question, if I made any mistakes (format, formulation, etc.) please tell me, so the next time I want to ask something it will be better.
Thanks in advance.