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

VS code new update doesn't retain opened file (tabs) when switching/opening another file

$
0
0

Early February VS Code update seemed to have messed my entire IDE settings.

Version: 1.42.0

When I open a file and switch or drag another file to the main working area the previous one just closes even if I double click on the tab to retain the opened file

The only property which could potentially help is workbench.editor.enablePreview

What do I do to revert that so that I can have multiple tabs/files open again?


Python Intellisense VSCode Wrong Autocomplete Imports & PyLint wrong impor-error warning

$
0
0

My current app structure is:

backend
  -- api
    |-- migrations
    |-- app
    |   -- main
    |      -- routes.py
    |   -- modules
    |      -- Mod1
    |         -- helper.py
    |         -- controller.py
    |      -- Mod2
    |         -- helper.py
    |         -- controller.py
    |-- venv
    |-- application.py

My settings (saved in .vscode within the backend folder):

"python.pythonPath": "${workspaceFolder}/api/venv/bin/python3",
    "python.envFile": "${workspaceFolder}/api/.env",
    "python.venvPath": "${workspaceFolder}/api/venv/bin/python3",

If I try to import a module, I would normally do from app.modules.mod1 import controller. But VSCode Intellisense keeps correcting me to from api.app.modules... - which doesn't work (Flask gives me an Import Error).

Pylint also keeps telling me that my imports are wrong, even though my app runs fine. I adjusted the pylint-path as per this answer, but still gives me the same error.

I also lost the ability to "navigate" my code - I can't hold Cmd and click a function. Any ideas on what I might me doing wrong? It's a tremendous lost in productivity to miss the autocomplete and function links...

VS Code knows Scala and Java, but can't connect them

$
0
0

I am trying to interoperate Scala with Java, and have managed to create a Maven based project (repository here) that compiles fine from commandline (mvn clean package).

However, I keep running into the issue that my IDE (VS Code) doesn't understand the interoperation at all.

The Problems

The file AccessScala.java is trying to access a variable in WithinModule.scala.

package me.parent.jModule;

import me.parent.jModule.WithinModule;

public class AccessScala {
    public static void main(String[] args) {
        WithinModule within = new WithinModule();
        // -- this is like a static variable, but Scala doesn't allow that
        // System.out.println(WithinModule.string());
        // -- this is the auto-generated getter
        System.out.println(within.string());
        // -- this getter was manually added
        System.out.println(within.getString());
    }
}

VS Code raises three problems:

  1. The import me.parent.jModule.WithinModule cannot be resolved : AccessScala[3,8]
  2. WithinModule cannot be resolved to a type : AccessScala [7,9]
  3. WithinModule cannot be resolved to a type : AccessScala [7,35]

Project Setup

The project has two modules, but right now only jModule is relevant. it contains Java and Scala code in separate folders. sModule contains some Scala code that I wanted to access as well, but my current problem has nothing to do with Maven modules and everything with VS Code understanding the Scala-Java connections.

> parent
 | > jModule
 | | > src/main
 | | | > java/me/parent/jModule
 | | | | > AccessScala.java
 | | | > scala/me/parent/jModule
 | | | | > WithinModule.scala
 | | > build.sbt
 | | > project/build.properties
 | | > pom.xml
 | > sModule
 | | > src/scala/me/parent/sModule
 | | | >ExternalModule.scala
 | | > pom.xml
 | | > build.sbt
 | | > project/build.properties
 | > build.sbt
 | > project/build.properties
 | > pom.xml

VS Code

I'm using the Java Extention Pack, Scala-Metals and Scala Syntax

Both for Java and Scala it detects errors etc, so it knows Scala is there.

Question

Why does VS Code complain and what could I do to make this work? Is there a way at all, or do I just have to use IntelliJ (i have other problems there, stay tuned for those questions ;)

VSCode single to double quote automatic replace

$
0
0

When I execute a Format Document command on a Vue Component.vue file VSCode replace all single quoted string with double quoted string.

In my specific case this rule conflicts with electron-vue lint configuration that require singlequote.

I don't have prettier extensions installed (no prettier.singleQuote in my setting)

How to customize vscode to avoid this?

AMP Stack and VS Code [closed]

$
0
0

Previously, I had done my coding using Sublime Text to create my code and MAMP to give me the server, MySQL and PHP. The machine that I was using has developed an issue, so it was replaced. As I set up the new Mac, I have switched from Sublime Text to VS Code. I find that VS Code has the Web Server as an extension (Live Server), which works very nicely. However, for projects that require the AMP stack, (MySQL and PHP), are there extensions that offer these abilities? (I've looked, and have not been able to find such) or should I install MAMP/XAMPP/etc.? What is the best way to get the AMP stack in the VS Code environment?

How do I set the directory for the test folder in Visual Studio Code with Mocha?

$
0
0

I've been trying to learn unit-testing with Mocha using Visual Studio Code, as per this tutorial. But when I click the Play button to start Mocha Tests, I get an error about not finding the test files.

It apparently wants me to put the test files in a directory that'd kind of mess up the way I have things organized in my project.

So, is there a way for me to point it to the test folder I have set up elsewhere?

Pug comments highlighting in VS Code

$
0
0

Why VS Code dont see standard comments in pug files?

Standard comment (token type String but not Comment)

enter image description here

Comments that will be hided in HTML is ok (token type Comment)

enter image description here

I just want comments like // my comment to be green

Can't open VSCode with other user

$
0
0

Well basically i created another user, and i'm tring to open a node project, but i can't use "code ." (i think it's because vscode is installed in the other user, but idk) without having the following error:

~/amq-javascript-2.5.0/node_modules/rhea$ code .

2020/02/12 10:02:20.859002 cmd_run.go:884: WARNING: cannot create user data directory: cannot create "/home/amq-broker/snap/code/24": mkdir /home/amq-broker/snap: permission denied cannot create user data directory: /home/amq-broker/snap/code/24: Permission denied

I already tryed with sudo, and got this:

~/amq-javascript-2.5.0/node_modules/rhea$ sudo code .

You are trying to start vscode as a super user which is not recommended. If you really want to, you must specify an alternate user data directory using the --user-data-dir argument.

I'm kinda lost here...


Disallow barrel file imports within the same library in Nrwl Nx

$
0
0

Suppose we have an app and a library in Nrwl Nx.

/apps
  /myApp

/libs
  /myLib
    /components
       /my.component.ts
       /other.component.ts
    /index.ts

I have already set tags in nx.json and nx-enforce-module-boundaries rule to block importing the app inside the lib. It works and this part is fine.

Another thing I wanted to do is enforcing using barrel files within libraries. So I created a path in tsconfig.ts

"paths": {
   "@myNs/my-lib": ["libs/myLib/index.ts"]
}

I faced the problem. Suppose we have something exported from index.ts.

// index.ts
export { MyComponent } from './components/my.component';

Now if we use some autoimporting IDE feature (e.g. from WebStorm or VS Code). They will be importing MyComponent using the path @myNs/my-lib - and this is expected, because I have just configured it like so.

A real problem appears when I want to autoimport something inside myLib (these imports should be relative, not @myNs/my-lib) - according to logic and this article ([Interesting article here]):

Never let a lib import from its own Barrel file

The TypeScript modules within a particular lib should not care what functionality that lib exposes, so it shouldn’t use its own barrel file at any point.

If a module imports something from its own barrel file, it almost always results in circular reference errors. Therefore, imports from inside of the module should use relative path imports.

So I found a workaround to block TS path-like imports inside lib. I have added a rule inside libs/myLib/tslint.json:

"rules": {
   "import-blacklist": [true, "@myNs/my-lib"]
}

Anyway, it doesn't fix autoimporting feature, just disallows to use wrong imports inside the lib.

Another problem is there are still wrong imports allowed. Suppose OtherComponent wants to import MyComponent Then there are three possibilities:

import { MyComponent } from './my.component'; // the correct way
import { MyComponent } from '.'; // not the best, but also the correct way
import { MyComponent } from '..'; // using barrel file - not correct (look at the citation above), but still successfuly validated by TSLint

Questions:

  1. How to disallow barrel file imports inside the same lib?
  2. How to configure IDEs to have relative paths inside lib and TypeScript paths outside (@myNs/my-lib)?

Setting up Python remote debugging in VSCode

$
0
0

I am having my remote(ubuntu 16.04) drive mounted on my local system(ubuntu 16.04) so that I can edit the source files by opening them in vscode.

Also, in the integrated terminal I can ssh to remote system and run the program using remote python interpreter which is installed on virtual environment like:

$ssh username@remoteip    
$workon remotevirtualenv
(remotevirtualenv)$python source.py

I want to enable remote debugging so that if I run the debug/run the remote files, the vscode which is installed on my local system uses my remote python interpreter.

I went through the docs suggesting the use of ptvsd extension(which asks to have 2 copies of source files one on local, another one server) but I am not sure how to configure it in this scenario. Appreciate the help. Thanks.

Edit 1: As, I said I have gone through the docs but I am not clear how to configure in this scenario. e.g. docs say

  1. In the source code on both computers, add the following lines, replacing my_secret with the appropriate passphrase to authenticate remote debugging, and replacing address with the appropriate IP address (or localhost) and port number:
ptvsd.enable_attach("my_secret", address = ('0.0.0.0', 3000))

But I have only one copy of source file i.e. on remote system. I have just mounted it on my local file system. So, should I give my local ip address or it should be remote system ip and which port number should I use as I am having only one copy of source and hence ptvsd, how is it going to communicate. Also, in the configuration, what should I use for localRoot location and remoteRoot location.

 3. {
     "name": "Attach (Remote Debug)",
     "type": "python",
     "request": "attach",
     "localRoot": "${workspaceFolder}",
     "remoteRoot": "${workspaceFolder}",
     "port": 3000,
     "secret": "my_secret",
     "host": "localhost" 
 }

Edit: Thanks to remote development extension in VSCode, remote debugging is super easy now.

Libman - How to install dependencies of installed library

$
0
0

I am using Libman - Asp Core - VsCode

I Installed Semantic-ui which needs jQuery,Popper and etc.

Is there a way that Libman install it's dependencies automatically while installing a library ?

Like what npm does.

why SASS @use rule is not working in vs code?

$
0
0
functions/_space.sass
// some colors
 .test 
    margin: 0


colors/_colors.sass
// some colors
$primary: #007bff


style.sass

/**
 * @application tools
 *
 */ 
@forward 'colors/colors'
@forward 'functions/space'

All of these code generates error in my style.css file. resource

Is it possible to build and test a multi target c# dotnet project in Visual Studio Code?

$
0
0

I've a multi target C# dotnet project with these frameworks defined in the csproj file:

<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0</TargetFrameworks>

However when browsing the source code, I get lot of errors like: enter image description here

Which is strange because I use the correct preprocessor defines like:

#if NET452
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
#endif

Is this even possible in Visual Studio Code ?

Edit...

Using Visual Studio 2019, the project builds fine and I can use this framework dropdown like this: enter image description here

Tell VS Code to always use relative paths for TypeScript auto imports?

$
0
0

VS Code is auto-importing everything relative to baseUrl using Node-like non-relative paths, which is what I don't want.

How do I tell VS Code to import everything with relative paths (except for Node modules of course)?

Removing the baseUrl option is not an option because I need it in order to point fs imports at a local polyfill of the fs module.

My tsconfig.json has this:

"baseUrl": "./",
        "paths": {
            "fs/*": [ "./src/util/FileSystem/*" ]
        }

If there's no other way other than removing the baseUrl option, then that doesn't do any good!

How to quickly change shell folder to match the currently open file

$
0
0

With single file opened in vscode, when I open integrated Powershell it always starts in my $HOME folder.

Is there any way to quickly switch to the directory of the currently shown file without having to manually cd into it?

Something like cd $vsCurrentFileDirectory.

Currently, I right click the tab and copy path then cd (Split-Path <CTRL-v>).


Is it possible to make vs code (files-folders)tree view like notepad++?

$
0
0

I am using vs code for a long time. But I hate this tree view system. In vs code when I hover on the sidebar it shows a sideline to the exact line Otherwise it's always hidden or I don't like this. It's hard to manage files/ folders. In notepad++ it's easy to manage files and folder. It always shows dot lines.

much better like this

├─ app
|  └─ main.js
├─ src
|  ├─ main.ts
|  └─ tsconfig.json
└─ package.json

Instead of this

  app
    main.js
  src
    main.ts
    tsconfig.json
  package.json

[NOTE] Is there any way to make vs code tree view like notepad++? I was searching for it many times but nothing found.

vs code editor

enter image description here

notepad++ editor

enter image description here

VS Code memory view with GDB debugger

$
0
0

I try to access memory viewer on VSCode with GDB debugger as suggested by the debugger to debug C++ code. However typing -exec info registers as suggested by debug console gives no response.

I am using VSCode 1.37.1

How to configure absolute imports in CRA created app via jsconfig?

$
0
0
{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": ["src"]
}

I did it just like in the official guide, but vscode gives me an error, that dotenv types file hadn't found (moreover, it gives me this error 3 times in a row). I looked for the answer in net, but didn't find a man with the same problem, most of them is trying to setup more difficult configs. How can I make it works?

VSCode IntelliSense not recognising SDL_image extension library for SDL framework

$
0
0

I am trying to include the SDL_image extension library to SDL.framework in my project but VScode's IntelliSense keeps underlining my #include<SDL_image.h> with error lines. It produces the following error:

'cannot open source file "SDL2/SDL.h" (dependency of "SDL_image.h")'

I was successfully able to edit the c_cpp_properties.json includePath so IntelliSense recognised the SDL framework, but when trying to do the same thing with SLD_image it failed.

This is my c_cpp_properties.json file:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/Library/Frameworks/SDL2_image.framework/Headers",
                "/Library/Frameworks/SDL2.framework/Headers",
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

A big thanks to anyone who can help or at least point me in the right direction!

VS Code Python debugging. How to continue from error. Repeat fromline after changes

$
0
0

During development it's often happens to me that i have pretty long script execution (which doesn't depend on me), and when error occurs at the late steps it is really annoying to rerun whole script again.
Is there an option to repeat last line execution after correcting an error?
Or i need to rerun file from beginning again?

To my understanding of scripting language Python should allow that

Viewing all 99290 articles
Browse latest View live


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