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

What is the difference between "none include" and "none update" in SDK-style csproj projects?

$
0
0

I was looking for the correct way to ensure appsettings.json is copied to the bin directory when building my project.

This article recommends using "none update"

<ItemGroup>
    <None Update="appsettings.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

And this stackoverflow answer recommends using "none include":

<ItemGroup>
    <None Include="appsettings.json" CopyToOutputDirectory="Always" />
</ItemGroup>

What is the difference between update and include?


How to configure vscode to automatically add new lines between functions

$
0
0

Here I have a two functions with no line between them:

const test = () => {
  console.log('test')
}
const test = () => {
  console.log('test')
}

After saving , I want it autoformat and add new line between this two functions like that:

const test = () => {
  console.log('test')
}
// new line
const test = () => {
  console.log('test')
}

Debug Python with VSCode Remote - Containers

$
0
0

I have running container with Python app and WSGI configuration that accepts bunch of GET parameters. The goal is requesting the app through browser(or curl) and get working breakpoints using VSCode Remote - Containers extension.

Host OS: Fedora 28, Container OS: CentOS 7

Docker details:

- Docker v18.09.9
- No Dockerfile(just running container)
- Docker network using
- Container IP is 172.18.0.2
- App directory is mounted from host filesystem

App details:

- No frameworks
- Just Python3 with several modules
- Virtual environment using

IDE details:

- VSCode v1.38.1
- Remote - Containers extension
- Python extension(installed in attached container also)

In VSCode I can Attach to Running Container, then open app directory that mounted earlier and edit code, install packages etc. It's ok, but I stuck with debug configuration, predefined items(Flask, Django etc) don't match my workflow.

How to tweak launch.json file for that purpose?

TS breakpoints not finding source in VS Code (inspector)

$
0
0

I am using VS Code, and I'd like to set breakpoints in my TS files and step through them. I am launching an electron-based Angular application with node. My application successfully launches, but I when I hover over my breakpoints I see:

Breakpoint ignored because generated code not found (source map problem?)

My package.json heading looks like:

{
  "name": "angular-test",
  "version": "0.0.0",
  "main": "main.js",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --base-href ./",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "electron": "ng build --base-href ./ && electron .",
    "electron-tsc": "tsc main.ts && ng build --base-href ./ && electron ."
  },

and my launch.json looks like:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}\\main.js",
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
            "preLaunchTask": "npm: build",
            "args" : ["."],
            "outFiles": [
                "${workspaceFolder}/dist/*.js"
            ],
            "protocol": "inspector"
        }
    ]
}

I think this may be caused by webpack, e.g., at the top of my main.js.map I have: {"version":3,"sources":["webpack:///./src/$_lazy_route_resource lazy namespace object","webpack:///./src/app/app-routing.module.ts"

But from what I understand, inspector should not be sensitive to webpack.

What is a good setup for simple Typescript project using --watch and VSCode live server?

$
0
0

I've got a Typescript project I'm developing with the help of VS Code. I've noticed that it helps to automate my process in the background, like automatically recompiling and reloading. I like that I can run tsc in --watch mode on VS Code. I'm also attaching the VS Code debugger to Chrome, which requires serving up the JS from a local server. The VS Code live server does the trick and automatically reloads.

However, I'm not sure what project directory configuration I should use. Right now I've got TS files in ./src and the server root in ./dist.

The tsconfig.json is

{
    "compilerOptions": {
        "target": "es6",
        "module": "amd",
        "sourceMap": true,
        "outDir": "dist",
        "baseUrl": ".",
        "paths": {
            "*": [
                "node_modules/*",
                "src/types/*"
            ]
        }
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [

    ]
}

I wanted to keep things organized, so for instance I want to be able to clean the project by erasing all contents of the ./dist directory, which would mean only target compiled files go in there. That way I could also add dist to my .gitignore. However, as it's the root directory of my server, I have to put index.html in there and I want index.html on version control. I'm sharing some of my code with other people and this seems a bit confusing and possibly dangerous if they think they can blow away index.html.

What's the proper way to do this?

Performance improvements for using DecorationOptions, setDecorations

$
0
0

What can be done to improve the decoration of the large file (1M lines). I'm using following code to decorate GUID of the each file.

  const RE_GUID = /([0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12})\|/gi;

  const markGUID = (): void => {
    if (!activeEditor) {
      return;
    }
    const text = activeEditor.document.getText();

    const guid: vscode.DecorationOptions[] = [];
    let match;
    RE_GUID.lastIndex = 0;
    while ((match = RE_GUID.exec(text))) {
      const startPos = activeEditor.document.positionAt(match.index);
      const endPos = activeEditor.document.positionAt(
        match.index + match[1].length
      );
      const decoration: vscode.DecorationOptions = {
        range: new vscode.Range(startPos, endPos),
        hoverMessage: 'CorrelationID',
      };
      guid.push(decoration);
    }
    activeEditor.setDecorations(defineGUIDStyle, guid);
  };

Can it be batched? (I see I could this while loop spread with the setTimeout)

Can it be done on the other thread? Could I use the WebWorker?

JS RegEx for finding number of lines in a page, separated by form feed \f

$
0
0

I have a use case that requires a plain-text file to have lines to consist of at most 38 characters, and 'pages' to consist of at most 28 lines. To enforce this, I'm using regular expressions. I was able to enforce the line-length without any problems, but the page-length is proving to be much trickier. After several iterations, I came to the following as a regular expression that I feel should work, but it isn't.

let expression = /(([^\f]*)(\r\n)){29,}\f/;

It simply results in no matches. As a comparison, the following expression results in a single match, the entire document. I'm assuming it's matching all lines up until the final

let expression = /(.*(\r\n)){29,}

If anyone could provide some feedback, I'd greatly appreciate it! - Jacob

Edit 1 - removed code block around second expression, it was probably making my question confusing.

How can I find all line with text hard coded in a file .jsx on Visual Studio Code?

$
0
0

I have a lot of files where I have to replace the line with text hard coded in a file .json for internationalization. But it's to long and not sure to read each line manually. So I want to use a plug-in or another solution to do it.


How do you Configure Visual Studio Code to Execute node with Sudo command?

$
0
0

Current setup on Windows 10 with Visual Studio Code connecting remotely to a Raspberry Pi 3 via SSH and the official "Remote Development" extension by Microsoft. It has been working great to launch and debug node.js code. But now I need it to run the code with sudo because of the pigpio C-library that requires sudo to run.

I have read the docs and searched but I cannot figure out how to configure Visual Studio Code to use sudo in front of any node commands when I press F5 or Ctrl-F5.

How do I add prefix the node command with sudo when remotely debugging?

further research I found https://code.visualstudio.com/docs/editor/debugging#_launch-configurations and from that I tried simply adding "sudo" to the runtimeExecutable property but when launched it says command not found. So I opened the Terminal and tried it manually "sudo nano -v" and it works in the console but not through debugger.

{
    // 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": [
        {"type": "node","request": "launch","name": "Launch Program","program": "${workspaceFolder}/code/sandbox/test-pigpio.js","runtimeExecutable": "node"
        }
    ]
}

simply adding sudo to the runtimeExecutable property so it reads "sudo nano" does not work.

VS Code Source Control Pane is Blank

$
0
0

I've reinstalled my PC and tried connecting back up to my Azure DevOps Repo using VS Code and TFVC. I'm using TFVC Location with Visual Studio 2019 Community TF.exe. It all seems to work and I can connect to my repo with my credentials. It all seems to load up fine and I can even see TFVC with a number of changes/differences. - see image below. However I'm expecting to see my source control and list of files to commit like before. But the panel is blank. There's no errors in the Output window of VS Code either.

I've tried removing and re-adding the workspace. Tried editing/adding anew file to the project in hope of kickstarting TFVC pane to show the file list. - the number next to TFVC updates but I don't see any menu button or files list.

Has anyone else had this and know a solution, or know where I'm going wrong.

vscode tfvc

Setting up the shell environment on Remote SSH connection in vscode

$
0
0

I'd like to use VSCode's Remote--SSH feature on a cluster here. However, when one logs in, the cluster is not suitable for development. One must source a script or two to configure the shell first.

How can I get VSCode to do this?

I don't want to put the script in each command I have in the tasks.json, etc., nor does it belong in my .bashrc (or similar) file. I wasn't able to figure out anything from the documentation. Many thanks, in advance!

P.S. There may be a non-remoting setting that allows you to do this, but I didn't find that either.

How do I turn on text wrapping by default in VS Code

$
0
0

Usually when I use VS Code, very first thing I do on new document is command: "Toggle Word Wrap" or Alt+Z. I tried looking into User Settings, but I didn't find any relevant entries. Is there some way to have text wrapping 'on' for every document by default?

VSCode Dart Import Shortcut

$
0
0

Does VSCode and/or a plugin offer a keyboard shortcut to automatically add an import in a Dart file? In IntelliJ and Android Studio this effect is easily achieved with Opt+Enter.

create a C++ problemMatcher for a single log file?

$
0
0

I am trying to create a problemMatcher for the Keil compiler. This does not generate any console output. All output goes to a log file. I noticed that there is a npm module called Gulp that should be able to help with that. I have created a regexp that works with the output. How do I create a problemMatcher that monitors a single log file for errors and can open the source files?

Another issue is that the log file to be monitored is not in the same directory as the source code.

Another issue is that the file output does not contain any path information. There are multiple possible paths that need to be searched to find the file.

How to disable Peek problem in VS Code on a MAC?

$
0
0

Not sure how i got this, maybe via some extension that was installed on my VS Code, I need to disable this .

enter image description here


Java compile error in Visual Studio Code: Could not find or load main class

$
0
0

I mistakenly executed those two lines on console:

rm -rf ~/Library/Application\ Support/Code/Cache/*

rm -rf ~/Library/Application\ Support/Code/CachedData/*

I hoped to clear cache to improve speed, but then I discovered that it deletes some key files and I failed debug my java file every time after then which said:

bash-3.2$ /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java --enable-preview -Dfile.encoding=UTF-8 -cp /private/var/folders/58/tqd41r6x5rlfzms1y1rx7s_m0000gn/T/vscodesws_cb741/jdt_ws/jdt.ls-java-project/bin Test Error: Could not find or load main class Test Caused by: java.lang.ClassNotFoundException: Test

Could not find or load main class? But in the file the main class is right declared and I successfully ran before the problem occurred.

Thank you very much!

What is causing VS Code to scan every PHP file in a workspace?

$
0
0

When opening any PHP-based workspace in Visual Studio Code, I'm getting EMFILE: too many open files errors for every PHP file in the included directories. This happens right as the window loads the workspace, and happens with extensions enabled and when they're turned off (via Developer: Reload with Extensions Disabled).

Example output line:

[2019-10-26 07:13:58.364] [renderer1] [error] EMFILE: too many open files, open '/path/to/workspace/app/vendor/psy/psysh/test/CodeCleaner/InstanceOfPassTest.php': Error: EMFILE: too many open files, open '/path/to/workspace/app/vendor/psy/psysh/test/CodeCleaner/InstanceOfPassTest.php'

This prevents all of the extensions and even some core functionality from working, so I can't see a file outline or check changed files in "Source Control", for example. It also makes my CPU spike, with several different code processes running while attempting to load the workspace.

In my local filesystem (Linux Mint, if that matters), I've tried increasing my open file limit (ulimit -n 20000), but that didn't help. Even if it did, I think that would be just working around the true problem: something's attempting to access every file.

My questions are:

  1. What is causing these file scans?
  2. Can I prevent them from happening at all?
  3. Can I prevent them from happening for specific files in my workspace, e.g. external "vendor" files that I don't control? (i.e. only allow the scans for my files)

Java compiling error in Visual Studio Code: Could not find or load main class

$
0
0

I mistakenly executed those two lines on console

rm -rf ~/Library/Application\ Support/Code/Cache/*
rm -rf ~/Library/Application\ Support/Code/CachedData/*

I hoped to clear cache to improve speed, but then I discovered that it deletes some key files and I failed debug my java file every time after then which said:

bash-3.2$ /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java --enable-preview -Dfile.encoding=UTF-8 -cp /private/var/folders/58/tqd41r6x5rlfzms1y1rx7s_m0000gn/T/vscodesws_cb741/jdt_ws/jdt.ls-java-project/bin Test 
Error: Could not find or load main class Test
Caused by: java.lang.ClassNotFoundException: Test

Could not find or load main class? But in the file the main class is right declared and I successfully ran before the problem occurred.

Thank you very much!

How to fix an error CS1061 in a C# console application?

$
0
0

I am currently learning C# and .NET and I am currently learning how to make a NuGet package. One of the files that I have is set up as such:

using System.Text.RegularExpressions;

 namespace Packt.CS7
 {
public static class StringExtensions
{
    public static bool IsValidXmlTag(this string input)
    {
        return Regex.IsMatch(input, @"^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$");
    }

    public static bool IsValidPassword(this string input)
    {
        return Regex.IsMatch(input, "^[a-zA-Z0-9_-]{8,}$");
    }

    public static bool IsValidHex(this string input)
    {
        return Regex.IsMatch(input, "^#?([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$");
    }
}
}

And my Program.cs is set up like this:

using System;
using System.Xml.Linq;
using static System.Console;
using Packt.CS7;

namespace Assemblies
{
class Program
{
    static void Main(string[] args)
    {
        Write("Enter a valid color valid in hex: ");
        string hex = ReadLine();
        WriteLine($"Is {hex} a valid color value: {hex.IsValidHex()}");

        Write("Enter a valid XML tag: ");
        string xmlTag = ReadLine();
        WriteLine($"Is {xmlTag} a valid XML tag: {xmlTag.IsValidXmlTag()}");

        Write("Enter a valid password: ");
        string password = ReadLine();
        WriteLine($"Is {password} a valid password: {password.IsValidPassword()}");
    }
}
}

When the console application is run it is supposed to output:

Enter a valid color value in hex: 00ffc8
Is 00ffc8 a valid color value: True
Enter a valid XML tag: <h1 class="<" />
Is <h1 class="<" /> a valid XML tag: False
Enter a valid password: secretsauce
Is secretsauce a valid password: True

However what I am getting in the console is this:

Program.cs(14,60): error CS1061: 'string' does not contain a definition for 'IsValidHex' and no 
accessible extension method 'IsValidHex' accepting a first argument of type 'string' could be found 
(are you missing a using directive or an assembly reference?) 
[/Users/steelwind/HardWay/c#and.NET/Chapter07/Assemblies/Assemblies.csproj]

The build failed. Fix the build errors and run again.

I believe the problem lies in the fact when I open the first file, when it is open in VSCode it says that each of the classes has "0 references" meaning that it isn't being called somehow in the Program.cs. However I am not sure why.

Here is my files structure:

 Assemblies:
 >Assemblies.csproj
  ^bin
   ^Debug
    ^netcoreapp3.0
   ^Release
    ^netcoreapp3.0
     >Assemblies
    >Assemblies.deps.json
    >Assemblies.dll
    >Assemblies.pbd
    >Assemblies.runtimeconfig.dev.json
    >Assemblies.runtimeconfig.json
    >Newtonsoft.Json.dll
 ^obj
 >Program.cs

Shared library:
 ^bin
  ^Bin
   ^Debug
     ^netstandard2.0
      >SharedLibrary.deps.json
      >SharedLibrary.dll
      >SharedLibrary.pbd
     ^netstandard3.0
    wtsegarsMyFirstPackage1.0.0.nupkg
   ^Release
    ^netstandard
     >SharedLibrary.dll
     >SharedLibrary.pbd
 ^obj
 SharedLibrary.csproj
   StringExtensions.cs

VS Code: disable linking between open files and explorer

$
0
0

Can I disable the function link with editor in Visual Studio Code?

My project has a lot of files, so the explorer tree is long, but when I open an editor tab, this file will be auto focused on explorer panel. How to disable that feature?

The same feature in eclipse:

This function in eclipse

Viewing all 98319 articles
Browse latest View live


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