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

VS Code - Error: EPERM: operation not permitted

$
0
0

I have been experiencing A LOT of permission issues when using VS code with Windows 10.

  1. When trying to move a folder:
    • Error: EPERM: operation not permitted, rename 'path a' ->'path b'
  2. When deleting a folder:
    • It fails silently, the folder is removed from the solution explorer but it persists on disk.

It doesn't work with or without admin rights.

I went to the folder containing all my repos, set the ownership to me, applied full control to all authenticated users, and it still doesn't work.

enter image description here

Any idea ?

EDIT: It does work sometimes, that's what make it very strange


How do I evaluate expressions while debugging in VS Code?

$
0
0

enter image description hereI am using vscode to build my golang gin project.

I go to debugging mod and can not do evaluate expressions.

I want to go some line and evaluate that see what happened in that monent.

Like eclipse ctrl+shift+i or idea ctrl+alt+f8

Quick evaluate expression.

I also see this

Eclipse inspection (Ctrl + Shift + I) equivalent in IntelliJ IDEA (Community Edition)

Watch window or evaluate expressions while debugging in VS Code?

func main() {

router := gin.Default()
router.GET("/user/:name", func(c *gin.Context) {
    name := c.Param("name")
    c.String(http.StatusOK, name, 1, 2, 3, 4)

})

when the debugger line in name := c.Param("name")

I try to use the bottom of vscode window and when I type this code into the command it will return

but if I type name it will return the right string for me.

Failed to eval expression: { "Expr": "c.Param(\"name\")",

"Scope": {

"goroutineID": 34,

"frame": 1 },

"Cfg": {

"followPointers": true,

"maxVariableRecurse": 1,

"maxStringLen": 64,

"maxArrayValues": 64,

"maxStructFields": -1 } }

Eval error: function calls not allowed without using 'call'

VS Code Server for WSL closed unexpectedly

$
0
0

I am trying to run a Python project on the WSL (Ubuntu-18.04 distribution) system with VS code. I have the WSL - Remote plugin v0.39.9 installed. When run the command:

code .

Receive the error:

/home/username/.vscode-server/bin/6ab598523be7a800d7f3eb4d92d7ab9a66069390/bin/code: 12: /home/username/.vscode-server/bin/6ab598523be7a800d7f3eb4d92d7ab9a66069390/bin/code: /home/username/.vscode-server/bin/6ab598523be7a800d7f3eb4d92d7ab9a66069390/node: Exec format error

When I ran inside the VS Code trying to connect to the WSL instance:

Starting VS Code Server inside WSL (Ubuntu-18.04) Extension version: 0.39.9, Windows build: 18362. Multi distro support: enabled. WSL path support: enabled VS Code Server for WSL closed unexpectedly.

Adding Python package to path for VSCode terminal

$
0
0

I'm writing python classes in a package using VScode. I want to add this package's parent directory to the Python path when using the VScode Terminal so I can import the package (regardless of the directory of the file that's being run).

I've tried a .env file and Workspace settings without success.

Ultimately I want to run doctests on the classes using the terminal, and for that the terminal needs to be able import the package.

.env File

I have a Workspace. I first tried adding a .env file as follows (note I'm using Python 3 Anaconda on Windows):

PYTHONPATH=C:\\MyPython;${PYTHONPATH}

(I've tried single & double back slashes and forward slashes, nothing works).

When I run a script (test.py) in the terminal containing this:

print(os.environ.get('PYTHONPATH'))

I just get back None.

I did try setting a system wide PYTHONPATH environment variable in Windows, which then shows up, but the C:\MyPython is not added to it. I don't want to have to add/change the system PYTHONPATH every time I open a different Workspace!

Workspace Settings

I then tried adding Workspace settings in the MyProject.code-workspace file:

{
    "folders": [
        {
            "path": "C:\\MyPython"
        }
    ],
    "settings": {
        "terminal.integrated.cwd": "C:\\MyPython",
        "terminal.integrated.env.windows": "C:\\MyPython"
    }
}

Again this didn't work.

File Structure

My file structure is as follows:

C:\MyPython
    .env
    MyProject.code-workspace
    test.py
    Pkg\
        __init__.py
        Class1.py
        Class2.py

If I use the green triangle button ("Run File in Python Terminal") to run test.py then that file's directory (C:\MyPython) gets added to sys.path and everything works (e.g. import Pkg.Class1 works).

However if I run Class2.py (which includes import Pkg.Class1 in the code and doctest) then instead the directory C:\MyPython\Pkg gets added to sys.path and it can't find and import the Pkg package and the doctest fails.

As such I want to add C:\MyPython to the python path, regardless of the directory of the file that is being run.

Of course, I could just add all tests to test.py and run that, but I really just want to run the doctests in the class I'm working on, rather than have to run all the tests every time (and flip to another file to do it).

It seems like this should be easy, but I can't get it to work!

Any ideas?

PS: I haven't included the .py code for the test or classes since it's irrelevant to the problem, it's the import that fails. Ultimately I can see that the required directory appears neither in sys.path nor in os.environ.get('PYTHONPATH') and that's why the import fails.

Difference between navigateRight and focusRightGroup?

$
0
0

What is the difference between these two command IDs in VSCode?

  • workbench.action.navigateRight
  • workbench.action.focusRightGroup

How do I apply a transform to a variable in a snippet in VSCode?

$
0
0

With the code below I want to transform the variable in $2 to lowercase but I can't quite get it to work.

"Build Model": {
        "prefix": "mod",
        "body": [
            "import '${1:../backend.dart}';",
            "",
            "class ${2:Class} extends ManagedObject<_$2> implements _$2 {}",
            "${2/(*)/${2:/downcase}/}",
            "${2:/downcase}" //would be nice to be able to do this
            "@Table(name: \"${2/(*)/${2:/downcase}/}\")",
            "class _$2 {",
            "@Column(primaryKey: true, autoincrement: true, indexed: true)",
            "int id;",
            "$3",
            "}",
            ""
        ],
        "description": "Build a data model"
    },

JSHint does not recognise Async/Await syntax in Visual Studio Code (VSCode)

$
0
0

I've been struggling with VSCode and JSHint to find out a way to get rid of this syntax highlighting. It seems like JSHint is not able to recognise Async/Await syntax.

Here you can find a screenshot of what I'm talking about.

enter image description here

My JSHint version: jshint-esnext v2.7.0-3

Difference between closeEditorsAndGroup and closeEditorsInGroup

$
0
0

What is the difference between these two command IDs in VSCode?

  • workbench.action.closeEditorsAndGroup
  • workbench.action.closeEditorsInGroup

Both seem to trigger the same action when I run it (they both close all editors in the current editor group and the editor group)


How to check Debug.Writeline() output in VS code?

$
0
0

I want to know the exact way to check the output of Debug.Writeline() in VS Code using C# extension.

I was using .net core 2.2 as a framework to run a sample test from this website https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Keys/samples/Sample1_HelloWorld.cs.

The test passed but I couldn't see any output from the Debug.Writeline() in the terminal. So I googled and found that common solution is to include the following code in my .cs file:

/* Create a listener that outputs to the console screen, and 
   add it to the debug listeners. */
   TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out);
   Debug.Listeners.Add(myWriter);

However, after I put the code into the file, it can't find the property 'listeners' under the class 'Debug'. So I googled again and realised that it is because this property is only included in .Net Framework 4.8. Therefore, I downloaded .Net Framework v4.8 and changed 'TargetFramework as follows:

<TargetFramework>net48</TargetFramework>

After the modifications, I ran the test again:

dotnet test 

But the result is still like this:

Microsoft (R) Test Execution Command Line Tool Version 16.2.0-preview-20190606-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...


Test Run Successful.
Total tests: 1
     Passed: 1

This is my .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net48</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.0.0-preview.3"/>
    <PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.0.0-preview.2"/>
    <PackageReference Include="NUnit" Version="3.12.0"/>
    <PackageReference Include="NUnit3TestAdapter" Version="3.14.0"/>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0-preview-20190808-03"/>
  </ItemGroup>
</Project>

This is the sample test I ran without modification:

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using Azure.Identity;
using NUnit.Framework;
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Threading;

namespace Azure.Security.KeyVault.Keys.Samples
{
    /// <summary>
    /// Sample demonstrates how to set, get, update and delete a key using the synchronous methods of the KeyClient.
    /// </summary>
    [Category("Live")]
    public partial class HelloWorld
    {
        [Test]
        public void HelloWorldSync()
        {
            // Environment variable with the Key Vault endpoint.
            string keyVaultUrl = Environment.GetEnvironmentVariable("AZURE_KEYVAULT_URL");

            // Instantiate a key client that will be used to call the service. Notice that the client is using default Azure
            // credentials. To make default credentials work, ensure that environment variables 'AZURE_CLIENT_ID',
            // 'AZURE_CLIENT_KEY' and 'AZURE_TENANT_ID' are set with the service principal credentials.
            var client = new KeyClient(new Uri(keyVaultUrl), new DefaultAzureCredential());

            // Let's create a RSA key valid for 1 year. If the key
            // already exists in the Key Vault, then a new version of the key is created.
            string rsaKeyName = $"CloudRsaKey-{Guid.NewGuid()}";
            var rsaKey = new RsaKeyCreateOptions(rsaKeyName, hsm: false, keySize: 2048)
            {
                Expires = DateTimeOffset.Now.AddYears(1)
            };

            client.CreateRsaKey(rsaKey);

            // Let's Get the Cloud RSA Key from the Key Vault.
            Key cloudRsaKey = client.GetKey(rsaKeyName);
            Debug.WriteLine($"Key is returned with name {cloudRsaKey.Name} and type {cloudRsaKey.KeyMaterial.KeyType}");

            // After one year, the Cloud RSA Key is still required, we need to update the expiry time of the key.
            // The update method can be used to update the expiry attribute of the key.
            cloudRsaKey.Expires.Value.AddYears(1);
            KeyBase updatedKey = client.UpdateKey(cloudRsaKey, cloudRsaKey.KeyMaterial.KeyOps);
            Debug.WriteLine($"Key's updated expiry time is {updatedKey.Expires}");

            // We need the Cloud RSA key with bigger key size, so you want to update the key in Key Vault to ensure
            // it has the required size.
            // Calling CreateRsaKey on an existing key creates a new version of the key in the Key Vault 
            // with the new specified size.
            var newRsaKey = new RsaKeyCreateOptions(rsaKeyName, hsm: false, keySize: 4096)
            {
                Expires = DateTimeOffset.Now.AddYears(1)
            };

            client.CreateRsaKey(newRsaKey);

            // The Cloud RSA Key is no longer needed, need to delete it from the Key Vault.
            client.DeleteKey(rsaKeyName);

            // To ensure key is deleted on server side.
            Assert.IsTrue(WaitForDeletedKey(client, rsaKeyName));

            // If the keyvault is soft-delete enabled, then for permanent deletion, deleted key needs to be purged.
            client.PurgeDeletedKey(rsaKeyName);

        }

        private bool WaitForDeletedKey(KeyClient client, string keyName)
        {
            int maxIterations = 20;
            for (int i = 0; i < maxIterations; i++)
            {
                try
                {
                    client.GetDeletedKey(keyName);
                    return true;
                }
                catch
                {
                    Thread.Sleep(5000);
                }
            }
            return false;
        }
    }
}

This is the test after modification:

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using Azure.Identity;
using NUnit.Framework;
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Threading;

namespace Azure.Security.KeyVault.Keys.Samples
{
    /// <summary>
    /// Sample demonstrates how to set, get, update and delete a key using the synchronous methods of the KeyClient.
    /// </summary>
    [Category("Live")]
    public partial class HelloWorld
    {
        [Test]
        public static void Main()
        {    
            /* Create a listener that outputs to the console screen, and 
             add it to the debug listeners. */
           TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out);
           Debug.Listeners.Add(myWriter);

            // Environment variable with the Key Vault endpoint.
            string keyVaultUrl = Environment.GetEnvironmentVariable("AZURE_KEYVAULT_URL");

            // Instantiate a key client that will be used to call the service. Notice that the client is using default Azure
            // credentials. To make default credentials work, ensure that environment variables 'AZURE_CLIENT_ID',
            // 'AZURE_CLIENT_KEY' and 'AZURE_TENANT_ID' are set with the service principal credentials.
            var client = new KeyClient(new Uri(keyVaultUrl), new DefaultAzureCredential());

            // Let's create a RSA key valid for 1 year. If the key
            // already exists in the Key Vault, then a new version of the key is created.
            string rsaKeyName = $"CloudRsaKey-{Guid.NewGuid()}";
            var rsaKey = new RsaKeyCreateOptions(rsaKeyName, hsm: false, keySize: 2048)
            {
                Expires = DateTimeOffset.Now.AddYears(1)
            };

            client.CreateRsaKey(rsaKey);
            // Let's Get the Cloud RSA Key from the Key Vault.
            Key cloudRsaKey = client.GetKey(rsaKeyName);
            Debug.WriteLine($"Key is returned with name {cloudRsaKey.Name} and type {cloudRsaKey.KeyMaterial.KeyType}");

            // After one year, the Cloud RSA Key is still required, we need to update the expiry time of the key.
            // The update method can be used to update the expiry attribute of the key.
            cloudRsaKey.Expires.Value.AddYears(1);
            KeyBase updatedKey = client.UpdateKey(cloudRsaKey, cloudRsaKey.KeyMaterial.KeyOps);
            Debug.WriteLine($"Key's updated expiry time is {updatedKey.Expires}");

            // We need the Cloud RSA key with bigger key size, so you want to update the key in Key Vault to ensure
            // it has the required size.
            // Calling CreateRsaKey on an existing key creates a new version of the key in the Key Vault 
            // with the new specified size.
            var newRsaKey = new RsaKeyCreateOptions(rsaKeyName, hsm: false, keySize: 4096)
            {
                Expires = DateTimeOffset.Now.AddYears(1)
            };

            client.CreateRsaKey(newRsaKey);

            // The Cloud RSA Key is no longer needed, need to delete it from the Key Vault.
            client.DeleteKey(rsaKeyName);

            // To ensure key is deleted on server side.
            // Assert.IsTrue(WaitForDeletedKey(client, rsaKeyName));

            // If the keyvault is soft-delete enabled, then for permanent deletion, deleted key needs to be purged.
            // client.PurgeDeletedKey(rsaKeyName);

        }

        private bool WaitForDeletedKey(KeyClient client, string keyName)
        {
            int maxIterations = 20;
            for (int i = 0; i < maxIterations; i++)
            {
                try
                {
                    client.GetDeletedKey(keyName);
                    return true;
                }
                catch
                {
                    Thread.Sleep(5000);
                }
            }
            return false;
        }
    }
}

In the end I tried to type the following in the terminal:

dotnet run

I finally got what I expected from the terminal in a format like this:

Key is returned with name CloudRsaKey-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and type xxx
Key's updated expiry time is x/xx/20xx x:xx:xx AM +00:00

But I want to know if it is the only way to see the output from Debug.Witeline(). Since I did not type the dotnet test command in the terminal, I don't think I was actually running the test. I am quite confused.

Visual Studio Code not understanding CMake -DDEBUG

$
0
0

Developing on Ubuntu 18.04 with CMake 3.15.3 and Visual Studio Code 1.39.2. My C++ project has a CMakeLists.txt with this line:

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")

In the C++ code, the DEBUG define can be checked like this:

#ifdef DEBUG
    DebugFunction();
#else
    ReleaseFunction();
#endif

This all works as expected. Comment out the set(CMAKE_CXX_FLAGS_DEBUG... line and ReleaseFunction is called. Uncomment and DebugFunction is called.

The problem is that the Visual Studio Code editor does not understand whether the DEBUG symbol is actually defined. Code always assumes ``DEBUG is not defined and greys out DebugFunction.

Is there a simple way to get Visual Studio Code to understand which symbols are defined and which are not? Presumably this requires getting Code to look inside CMakeLists.txt...but how?

Visual Studio Code doesn't recognize my anaconda packages and modules

$
0
0

I'm new to Machine Learning and im trying to get used to VS Code, so I tried to use it but quickly ran into some problems (not knowing how to run python on the terminal, using the conda environment, etc). The main problem was that the packages that i have with anaconda didn't work in VS Code.

I've tried everything but I'm unable to get it running in the terminal. I'll explain myself with this example.

Example code:

#Not my actual code, but it's an example
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

x = np.linspace(0, 20, 100)
plt.plot(x,np.sin(x))
plt.show()

When i run it, this shows up in the terminal

Traceback (most recent call last):
  File "c:/Users/arman/Desktop/Untitled-1.py", line 2, in <module>
    import numpy as np
  File "C:\Users\arman\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\Users\arman\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: No se puede encontrar el módulo especificado.

###NOTE: this part 'DLL load failed: No se puede encontrar el módulo especificado.' basically means that it didnt find the module, sorry for the spanish.

, even though I'm in a conda environment. And that happens with every single package that comes with conda.

What can I do to make it work and why is that happening?

Visual Studio Code does not implement IntelliSense correctly for numpy but works for all other modules [Pictures inside]

$
0
0

I started working in Visual Studio Code and configured python IntelliSense. Untill now everything is working like a charm. However, IntelliSense works perfectly with all packages except numpy objects. The pictures below explains the problem better. One shows numpy object and the other shows request object.

I tried to reinstall numpy and enabling jedi but nothing changed.

enter image description hereenter image description here

How to export databases with commands azure cli with C# code

$
0
0

I use Azure CLI to export backup the databases in my resource group to the blobstorage, so i want to use same command on visual studio code with c#.

For example, I use the following command in Azure CLI to export the DB's in my resource group:

az sql db export -s (sql server) -n (database) -g (group) -p (password) -u login --storage-key " key " --storage-key-type --storage-uri (url blob)

How can I achieve this using a C# code instead?

How do I disable: [js] File is a CommonJS module; it may be converted to an ES6 module

$
0
0

The following is what I want to disable:

[js] File is a CommonJS module; it may be converted to an ES6 module.

I can't find it in settings.
Help appreciated as this is really annoying.

Delete 'Python Interactive' environment created by VSCode inside Jupyter?

$
0
0

I ran some jupyter notebook using VSCode. However, VSCode created some 'Python Interactive' environment which appears in my Jupyter Notebook. How do I remove them?enter image description here


How to show ignore file in visual studio code?

$
0
0

My tree view hides all ignored files from .gitignore. I cannot find anything in settings.json to show ignored files in my project. How do I show files ignored because of .gitignore?

Seperate JSX and function blocks from parent parentheses or parent tag

$
0
0

let say I have a React Component (class based for now, yeah i should start using hooks =D)

class App extends Component {
  state = {
    someState: ""
  }  

  render() {
    return (
      <View>
        <View>
          <Text>Header</Text>
        </View>

        <View>
          <Text>Main</Text>
        </View>

        <View styles={styles.footer}>
          <Text>Footer</Text>
        </View>
      </View>
    )
  }
}

Now i am using vimvscode so i use shift + [ or shift + ] a lot;

now let say i need to delete

state = {
  someState: ""
}

for me i think best way to delete that part i d + shift + [ if my cursor is at

  state = {
    someState: ""
  }[Cursor]

but it will delete up to class App extends Component

same goes for JSX

if i want to delete footer only

<View styles={styles.footer}>
  <Text>Footer<Text>
</View>  

with d + shift + ] if my cursor is at:

it will delete all upto:

<View styles={styles.footer}>
          <Text>Footer</Text>
        </View>
      </View>
    )
  }
}

I don't want this behaviour,

so i would love to know any prettier configuration or vim plugin that can help me do these stuff

How to create a comment block of //'s around text of different lengths

$
0
0

I'm curious, if there's a way to create these blocks automatically around a text? Currently working in VS / VSC projects.

/////////////////////////////////////////////////////////
///////////////////// Demo Text /////////////////////////
/////////////////////////////////////////////////////////

Due to varying text length, this can be really annoying.

Thanks!

How to toggle between opened tabs in VS Code

$
0
0

I was looking at default keybindings but didn't find it.
Is it even possible by default to toggle between opened tabs in VS Code?
If no, maybe you know extension for doing so?

Thanks!

importing library in visual studio code

$
0
0

let's say I want to use util4, I will write down in my java file:

import unit4.turtleLib.Turtle;

(I got the jar file in the same folder)
I'm running it over visual studio code without maven
(if I would want to install maven I would use a different IDE instead)
and I can't just put the jar file in the same folder it doesn't work that way, what should I do than?.

Viewing all 97313 articles
Browse latest View live


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