Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all 97813 articles
Browse latest View live

VS Code Interactive Window

$
0
0

I recently switched from Windows to Mac OS for my work computer and while the interactive window functions normally most of the time it is unable to view items on my path variable throwing the error "WebDriverException: Message: 'geckodriver' executable needs to be in PATH." I say it cannot view the path because when I run a simple script in any other terminal, even the integrated one, it works fine. I know I can work without the interactive window however for my purposes the data viewer is a very handy tool.

I have tried running: os.system('echo $PATH') in the interactive window as well as:os.system('export PATH=$PATH:/path/to/geckdriver/install/location;)

With the return of both being: 0

I have also tried switching it to all the different env's I have but it makes no difference.

I have also used brew to install geckodriver with no change.

If you have a solution or idea about what I could be doing wrong I would be very grateful. I have also confirmed that the interactive window still works on my windows machine when running geckodriver/selenium scripts.

Sample Code:from selenium import webdriverdriver = webdriver.Firefox()driver.get('https://www.google.ca')


Mac OS Mojave microphone permission for Visual Studio Code

$
0
0

I'm trying record audio with PyAudio however when working in VSCode no microphone permission request is generated.

I have done an NVRAM reset which allowed me to run the script though the terminal (after it generated a permission request).

Within the privacy settings the only apps available are Chrome and Terminal, so it is not possible to give VSCode permission here.

Is there a way to force a permission request for VSCode? Or somehow otherwise edit the microphone permissions?

How to install Windows Terminal on VS code

$
0
0

All in title. Also i'm russian and this is Google Translate. I opened the process in Task Manager and went to the file location. There was an error with access denial, but it was solved with the help of Computer Control. But I don't know how to open this particular terminal in vs code. I introduced OpenConsole first.Yes, but it was only a terminal. But that's what I'm interested in.
SCREENSHOT

Vs Code Not Loading Jupyter Notebook Images

$
0
0

I love the way vs code works with jupyter notebooks and WSL 2. However, the only thing stopping me from switching completely is the lack of image rendering from a distributed notebook. When I download a notebook from class, there is sometimes important images displaying flowcharts, diagrams, ect and these do not load on vs code but they do on Anaconda using jupyter notebook there. Any ideas? Thank YouVs Code Jupyter Notebook

anaconda jupyter notebook loaded

How do I add assembly references in Visual Studio Code?

$
0
0

So I've come across a similar issue twice now while working on my first project in C#. When trying to add either using System.Data; or using System.Timers;, I get the following error:

The type or namespace name 'x' doesn't exist in the namespace 'System' (are you missing an assembly reference?).

I have tried beginning a new project and running restore to see if I had accidentally removed something in the dependencies, but upon generating a new project I still receive the same error. I have tried to research the question and have seen answers referring to the 'solutions explorer', but as far as I can see there doesn't seem to be such a feature by this name in Visual Studio Code 1.8.

Can anyone point me in the right direction for how to get these working, perhaps by manually adding into the dependencies?

How to remote debugging on a cluster node from vscode?

$
0
0

I can use Remote-SSH plugin of vscode to login the server. But this is just the login node, and I want to further connect from the login node to a cluster node for computations and debugs on it. How can I do it with vscode? BTW: I want just connect it remotely without installing a vscode in the server. Thanks a lot for any suggestion and solution.

can't debug C with makefile in vscode

$
0
0

I need a way to debug a C program consisting of multi C files with the makefile in vscode, when I debug the program using the wingw32-make command in the tasks.json , the program run directly without stoping at the breakpoints, but when using the gcc command in the tasks.json the breakpoints can be arrived. I am confused. Forgive my ignorance, any response would be greatly appreciated!

below is my code

heada.h

#ifndef PRACTICES_MYFUNC0A_H#define PRACTICES_MYFUNC0A_Henum steerwheel  {square, circle};typedef struct {    int wheels;    enum steerwheel sw;} Car;Car * getCar(int, enum steerwheel);#endif //PRACTICES_MYFUNC0A_H

MainTest.c

#include <stdio.h>#include <malloc.h>#include "funcha.h"int main() {    Car *car = getCar(4, square);    int i;    printf("%d,%d\n",car->wheels, car->sw);    scanf("%d",&i);    printf("%d\n", i);    free(car);    getchar();}

MyFunc01.c

#include <stdio.h>#include <malloc.h>#include "funcha.h"Car * getCar(int wheels, enum steerwheel sw) {    Car *car = malloc(sizeof(Car));    car->wheels = wheels;    car->sw = sw;    return car;}

Makefile

MainTest: MainTest.o myFunc01.o funcha.h    gcc -o MainTest MainTest.o myFunc01.omyFunc01.o: myFunc01.c funcha.h    gcc -c myFunc01.cMainTest.o: MainTest.c funcha.h    gcc -c MainTest.c.PHONY: cleanclean:    rm MainTest myFunc01.o MainTest.o

and the .vscode foloer's file is below:launch.json

{"version": "0.2.0","configurations": [        {"name": "(gdb) 启动","type": "cppdbg","request": "launch","program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "D:\\work_softwares\\mingw64\\bin\\gdb.exe","setupCommands": [                {"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true                }            ],"preLaunchTask": "makerun"        }    ]}

tasks.json

{"tasks": [        {"type": "shell","label": "makerun",            // this manner can arrived at the breakpoints。 why ???????"command": "D:\\work_softwares\\mingw64\\bin\\mingw32-make.exe","args": ["-C","${workspaceFolder}","MainTest"            ],"options": {"cwd": "D:\\work_softwares\\mingw64\\bin"            },"problemMatcher": [],"group": {"kind": "build","isDefault": true            }        },        {"type": "shell","label": "notmakerun",            // this manner can arrived at the breakpoints。"command": "D:\\work_softwares\\mingw64\\bin\\gcc.exe","args": ["-g","${workspaceFolder}\\*.c","-o","${workspaceFolder}\\MainTest.exe"            ],"options": {"cwd": "D:\\work_softwares\\mingw64\\bin"            },"problemMatcher": []        }    ],"version": "2.0.0"}

VSCode - Enclose expression in a function call, much like IntelliJ's .arg

$
0
0
  • Assume we've got Math.random() * 5|, | being the caret's position.

  • I'd like it to convert to someFunc(Math.random() * 5) as quickly as possible. In Webstorm and other JetBrains IDE's, I'd simply write .arg at the end of an expression, press tab, and it'd get automatically enclosed in braces, and the caret would be placed before them.

Does VSC offer such a functionality?


Cast and type env variables using file

$
0
0

For all my projects, I load all env variables at the start and check that all the expected keys exist as described by an .env.example file following the dotenv-safe approach.

However, the env variables are strings, which have to be manually cast whenever they're used inside the Python code. This is annoying and error-prone. I'd like to use the information from the .env.example file to cast the env variables and get Python typing support in my IDE (VS Code). How do I do that?

env.example

PORT: intSSL: boolean

Python Ideal Behavior

# Set the env in some way (doesn't matter)import osos.environment["SSL"] = "0"os.environment["PORT"] = "99999"env = type_env()if not env["SSL"]: # <-- I'd like this to be cast to boolean and typed as a boolean    print("Connecting w/o SSL!")if 65535 < env["PORT"]:  # <-- I'd like this to be cast to int and typed as an int    print("Invalid port!")

In this code example, what would the type_env() function look like assuming it only supported boolean, int, float, and str?

It's not too hard to do the casting as shown in e.g. https://stackoverflow.com/a/11781375/1452257, but it's unclear to me how to get it working with typing support.

.NET Core Web API cannot be called from .NET Core Console App

$
0
0

This is very frustrating.

I have a .NET Core Web API which I can call from Postman and get response (GET/POST/PUT etc.) but when I try and use a .NET Core Console app to call the web api I get this error on the Post method:

Exception has occurred: CLR/System.NullReferenceException An exception of type 'System.NullReferenceException' occurred in WebServer.dll but was not handled in user code: 'Object reference not set to an instance of an object.'

Now I have run the API and client in debug mode and I can see that Post controller is being triggered but the object ("Product") is empty. So it looks like somehow the .NET Console app Post's body is not being sent or being rejected while the postman is fine.

Here i must mention that on the .NET Core console client I used to get a certificate error which was even worse, I used to get request refused error so I have done the following:

From command prompt executed >"dotnet dev-certs https --trust"

and also added the code for httpclient:

handler.ServerCertificateCustomValidationCallback=HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

Can someone please help? I am just using a simple example taken from Microsoft MSDN website.

Just to mention I am using Windows 10 Pro as OS and it is a dev machine where both Web API and client is running so no other PC involved.

Thanks.

Code is below. I have pasted the full code below as they are generic example so anyone can use the Visual Studio Code/Visual Studio to create project with these as is and try to debug to see what is going wrong.

WebAPI

Controller

using Microsoft.AspNetCore.Mvc;using WebServer.Models;using System.Collections.Generic;using System.Linq;namespace WebServer.Controllers {    [Route("api/[controller]")]    public class ProductsController : Controller     {        // Add actions here        [HttpGet]        public Product[] Get()         {            return FakeData.Products.Values.ToArray();        }        [HttpGet]        public Product[] GetAllProducts()         {            return FakeData.Products.Values.ToArray();        }        [HttpGet("{id}")]        public Product Get(int id)         {            if (FakeData.Products.ContainsKey(id))                return FakeData.Products[id];            else             return null;        }        [HttpPost]        public Product Post([FromBody]Product product)         {            product.ID = FakeData.Products.Keys.Max() + 1;            FakeData.Products.Add(product.ID, product);            return product; // contains the new ID        }        [HttpPut("{id}")]        public void Put(int id, [FromBody]Product product)         {          if (FakeData.Products.ContainsKey(id))           {            var target = FakeData.Products[id];            target.ID = product.ID;            target.Name = product.Name;            target.Price = product.Price;          }        }        [HttpDelete("{id}")]        public void Delete(int id)         {           if (FakeData.Products.ContainsKey(id))            {              FakeData.Products.Remove(id);           }        }    }    }

Model

using System.Collections.Generic;namespace WebServer.Models {    public class Product {        public int ID { get; set; }        public string Name { get; set; }        public double Price { get; set; }    }    public class FakeData {    public static IDictionary<int, Product> Products;    static FakeData() {        Products = new Dictionary<int, Product>();        Products.Add(0, new Product { ID = 0, Name = "Apple", Price = 5.55 });        Products.Add(1, new Product { ID = 1, Name = "Bike", Price = 6.66 });        Products.Add(2, new Product { ID = 2, Name = "Coffee", Price = 7.77 });    }}}

.NET Core Console App client (calling the above Web API)

using System;using System.Net;using System.Net.Http;using System.Net.Http.Headers;using System.Threading.Tasks;namespace WebClient{    public class Product    {        public string ID { get; set; }        public string Name { get; set; }        public decimal Price { get; set; }    }    class Program    {        static HttpClientHandler handler = new HttpClientHandler();        static HttpClient client = new HttpClient(handler);        static void ShowProduct(Product product)        {            Console.WriteLine($"Name: {product.Name}\tPrice: "+                $"{product.Price}");        }        static async Task<Uri> CreateProductAsync(Product product)        {            HttpResponseMessage response = await client.PostAsJsonAsync("api/products", product);            response.EnsureSuccessStatusCode();            // return URI of the created resource.            return response.Headers.Location;        }        static async Task<Product> GetProductAsync(string path)        {            Product product = null;            HttpResponseMessage response = await client.GetAsync(path);            if (response.IsSuccessStatusCode)            {                product = await response.Content.ReadAsAsync<Product>();            }            return product;        }        static async Task<Product> UpdateProductAsync(Product product)        {            HttpResponseMessage response = await client.PutAsJsonAsync(                $"api/products/{product.ID}", product);            response.EnsureSuccessStatusCode();            // Deserialize the updated product from the response body.            product = await response.Content.ReadAsAsync<Product>();            return product;        }        static async Task<HttpStatusCode> DeleteProductAsync(string id)        {            HttpResponseMessage response = await client.DeleteAsync(                $"api/products/{id}");            return response.StatusCode;        }        static void Main()        {            RunAsync().GetAwaiter().GetResult();        }        static async Task RunAsync()        {            // Update port # in the following line.            handler.ServerCertificateCustomValidationCallback=HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;            client.BaseAddress = new Uri("http://localhost:5000/");            client.DefaultRequestHeaders.Accept.Clear();            client.DefaultRequestHeaders.Accept.Add(                new MediaTypeWithQualityHeaderValue("application/json"));            try            {                // Create a new product                Product product = new Product                {                    ID="100",                    Name = "Orange",                    Price = 100                };                var url = await CreateProductAsync(product);                Console.WriteLine($"Created at {url}");                // Get the product                product = await GetProductAsync(url.PathAndQuery);                ShowProduct(product);                // Update the product                Console.WriteLine("Updating price...");                product.Price = 80;                await UpdateProductAsync(product);                // Get the updated product                product = await GetProductAsync(url.PathAndQuery);                ShowProduct(product);                // Delete the product                var statusCode = await DeleteProductAsync(product.ID);                Console.WriteLine($"Deleted (HTTP Status = {(int)statusCode})");            }            catch (Exception e)            {                Console.WriteLine(e.Message);                if(e.InnerException!=null)                {                    Console.WriteLine(e.InnerException.Message);                }            }            Console.ReadLine();        }    }}

Coding C# WinForms without Visual Studio [closed]

$
0
0

I have recently installed Visual Studio Code on my Raspberry Pi (or Code-OSS by headmelted) and I've "connected" it with mono to create and run a WinForms application. However, I always use Visual Studio to create WinForms applications and I don't know how to add buttons and labels to a WinForms application. I live in China and don't have any access to Google or YouTube. I've tried searching on Bing, but most websites are blocked. Can anyone give me a link or some sample code?

Collaps similiar files in file browser

$
0
0

Is there a way to collaps similiar files (like compiled sass files) in the file browses? When I have a Angular project or such I don't necessarily need for example the test files.

Something similiar to how PhpStorm does it: enter image description here

vscode shows typescript related problems in jsconfig.json file

$
0
0

I set up a normal create-react-app project and add jsconfig.json to the root directory. But it shows the error which is typescript related.problems in Vscode terminalHere is the jsconfig.json file

jsconfig.json configurations

Folder structure

enter image description here

Can anyone help me with this?

Thanks,Prakhil

How to view my HTML code in browser with Visual Studio Code?

$
0
0

How to view my HTML code in a browser with the new Microsoft Visual Studio Code?

With Notepad++ you have the option to Run in a browser. How can I do the same thing with Visual Studio Code?

Debug button in bottom toolbar leads to "launch: program '[program_name]' does not exits." with CMake Tools

$
0
0

Since the Extension CMake Tools (1.3.1) is maintained directly by Microsoft the helper extension that created the bridge between ms-vscode.cpptools and this tool is not compatible anymore and as of that, the launch.json is not created automatically anymore.

If I manually create the launch.json as follows:

{    // Use IntelliSense to learn about possible attributes.    // Hover to view descriptions of existing attributes.    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [        {"name": "test","type": "cppdbg","request": "launch","program": "${command:cmake.buildDirectory}/test","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [                {"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true                }            ]        }    ]}

and define cmake.buildDirector in the settings.json

"cmake.buildDirectory": "${workspaceFolder}/build/${command:cmake.buildKit}/${command:cmake.buildType}",

the building works fine, and I can launch the application with the correct kit and build type from the Run side panel clicking on the run-symbol.

But if I hit the "Debug" button in the bottom toolbar of the VSCode window I get launch: program '[test]' does not exits, with the option "Cancel" or "Open launch.json"

Does anyone know what might cause this problem or how this can be debugged?


How do I jump to a closing bracket in Visual Studio Code?

$
0
0

In VSCode when I type a bracket, e.g '(', it automatically creates the ending bracket: ')'.Are there any shortcuts to jump to the closing bracket or parenthesis, without pressing the 'End' key?

I found a way to do in Sublime Text 2 that did exactly that, using a Regex in the User's Key Bindings, but couldn't find a way to do it in VSCode.

VScode settings.json

$
0
0

My understanding is that most logical way to manage my extensions ( and other stuff, I guess ) in VSCode is to edit its setting.json file. I am using Debian Linux MX Continuum 18.3 and based on what I have read on internet it should be found in ~/.config/Code/User, but there is no such file there.

How can I refactor in VS Code?

$
0
0

This might be an inappropriate place to ask this question but in VS Code I can't find the option to refactor. There is an option to "replace all" but that seems to be more like a "find/replace" method that only looks at the document I'm in. I'd like it to refactor all references to the method throughout the program.

Here are a couple of images.

Right Click

Edit Tab

Why do I get this error: Can't compile code “launch: program does not exist"

$
0
0

I have tried for both Python and C++.I have tried a lot more things but the same error comes up every time I compile my code, I don't know why is it not running.

I've been following this related SO topicCan't compile code "launch: program <program_path> does not exist "and tried this several times, but still not working.

My launch.json file

"version": "0.2.0","configurations": [    {"name": "(gdb) Launch","type": "cppdbg","request": "launch","program": "enter program name, for example ${E:\\python project\\invisiblecloak.exe}","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": true,"MIMode": "gdb","miDebuggerPath": "/path/to/gdb","setupCommands": [            {"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true            }        ]    }]}

I just want a Hello World code running first in Visual Studio Code.

openCV setup using Visual Studio Code

$
0
0

I am using Microsoft Visual Studio Code with MinGw for setting up openCV using C++. A simple "Hello World" code executes successfully. But whenever I am trying to include an openCV library the compiler throws an error.

main.cpp:3:10: fatal error: opencv2/opencv.hpp: No such file or directory    3 | #include <opencv2/opencv.hpp>      |          ^~~~~~~~~~~~~~~~~~~~compilation terminated.

I searched for many solution on the internet but unfortunately none worked. Please help me in this regard as I am stuck with this issue for a long time.

c_cpp_properties.json file

launch.json file

task.json file

main.cpp code I am trying to execute

Viewing all 97813 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>