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

VSCode won't work with filewatchers

$
0
0

I am running this command to watch .scss files node-sass-chokidar ./scss -o ./build --watch

If I edit the file in notepad++ everything works fine and file compiles.

If I edit it in VSCode then after I save it gives this error:

{
  "status": 3,
  "message": "File to read not found or unreadable: E:/Clients/conversions/css/scss/mobile.scss",
  "formatted": "Internal Error: File to read not found or unreadable: E:/Clients/conversions/css/scss/mobile.scss\n"
}

I found some threads saying this is caused by atomic save but VSCode developer says in github thread that VSCode does not use atomic save. But then in another thread he says it renames files so I guess this could be issue.

Does anyone have any idea how I can fix this and just make it save normally?


Vscode live share: Run shared code locally

$
0
0

I am using Visual Studio Code Live Share to teach a student programming in Python. When they click the run button they get an error because vscode seems to be trying to run python from the command line, using my file (which doesn't exist on their file system).

I know we can have a shared terminal, but they do not know how to use terminal commands yet. Is there a way I can configure their run button to run the code locally, or alternatively, to run the code in our shared terminal by default?

Vscode live share: disable usernames over cursors when editing

$
0
0

When live sharing the username of the person editing the code always appears above their cursor, this can be big and distracting, especially for long usernames.

Is there a way to disable this feature so it only shows different colored cursors, without the username hovering over the cursor as a tooltip?

Getting error when trying to run Python in vscode

$
0
0

this is my first time using vscode. I am currently using a Macbook Pro with version 10.15.2 of macOS Catalina. Every time I try to debug, I get this "Unable to create 'launch.json' file inside the '.vscode' folder (Unable to write file '/Users/.vscode/launch.json' (NoPermissions (FileSystemError): Error: EACCES: permission denied, mkdir '/Users/.vscode'))." I have no idea what I need to do to fix this and need help because I need to work on a class project. Please explain in detail as I will most likely not understand yet. Thank you so much!

Import statement works incorrectly if directly compiled, but works okay after saving it on VS Code

$
0
0

I'm having a problem where a certain import fails to work when compiling directly, but works okay after saving the source on VS Code.

If I delete the node_modules/.cache folder and execute the command:

yarn serve

It compiles okay, but then the browser gives out an error at runtime:

Uncaught TypeError: getParamNames is not a function
    at eval (webpack-internal:///../api/src/clients/base.ts:116)
    at Array.forEach (<anonymous>)
    at exports.Remotable (webpack-internal:///../api/src/clients/base.ts:114)
    at DecorateConstructor (webpack-internal:///../api/node_modules/reflect-metadata/Reflect.js:541)
    at Object.decorate (webpack-internal:///../api/node_modules/reflect-metadata/Reflect.js:130)
    at Module.__decorate (webpack-internal:///../api/node_modules/tslib/tslib.es6.js:78)
    at eval (webpack-internal:///../api/src/clients/order.ts:26)
    at Object.../api/src/clients/order.ts (app.js:909)
    at __webpack_require__ (app.js:785)
    at fn (app.js:151)

If you keep compiling the application without changing anything, the error repeats, but then, if you edit base.ts on VS Code, change the import to something wrong, then change it back, it compiles, and even if you close the server and start it again, the error does not repeat.

If you delete node_modules/.cache again, or wait for it to expire, the cycle restarts.

base.ts:

/*eslint prefer-spread: "off"*/
/* eslint-disable no-empty */

import * as getParamNames from 'get-param-names';
import * as NamedRouter from 'named-routes';
import { fromPairs, has, get, isString } from 'lodash';
import { Config } from '../../config';
import { RestClient } from 'typed-rest-client';
import 'reflect-metadata'
import { classToPlain } from 'class-transformer';

export interface ApiResult<T> {

    status?: string;
    data?: T;
    error?;

}

// ATSTODO: Implementar conversão de retorno para classes específicas
export const LocalClient = (service) => {
    return (Client) => {
        const ParentClass = Object.getPrototypeOf(Client);

        Object.getOwnPropertyNames(ParentClass.prototype).filter(s => s !== 'constructor').forEach(propName => {
            if (ParentClass.prototype[propName] instanceof Function) {
                if (has(Client.prototype, propName)) {
                    // Já tem uma implementação específica
                    return;
                }

                Client.prototype[propName] = (...args: any[]) => {
                    return service[propName].apply(service, args);
                }
            }
        });
    }
}

export const getHost = () => {
    if (Config.dbConfig.port) {
        return Config.dbConfig.host + ':' + Config.dbConfig.port;
    } else {
        return Config.dbConfig.host;
    }
}

class RemotabeManager {
    public metadata = {};

    private getTargetName(target: any): string {
        return isString(target) ? target : target.constructor.name;
    }

    public createTarget = (target: any) => {
        const name = this.getTargetName(target);
        let targetMetadata = this.metadata[name];
        if (!targetMetadata) {
            targetMetadata = {
                name,
                target,
                methods: {}
            }
            this.metadata[name] = targetMetadata;
        }
        return targetMetadata;
    }

    public getTarget = (target: any) => {
        const name = this.getTargetName(target);
        return this.metadata[name];
    }

    public forMethod(target: any, propertyKey: string | symbol) {
        const methods = this.createTarget(target).methods;
        let method = methods[propertyKey];
        if (!method) {
            method = {
                name: propertyKey,
                path: `/rpc/${String(propertyKey)}`,
                parameters: []
            };
            methods[propertyKey] = method;
        }
        return method;
    }

    public registerParam(target: any, propertyKey: string | symbol, parameterIndex: number, value) {
        const method = this.forMethod(target, propertyKey);
        const existingInfo = method.parameters[parameterIndex] || {};
        method.parameters[parameterIndex] = { ...value, ...existingInfo };
    }

}

const remotableMetadata = new RemotabeManager();

/**
 * Decorador
 * @param constructor
 */
export const Remotable = (constructor) => {
    Object.getOwnPropertyNames(constructor.prototype)
        .filter(s => s !== 'constructor'&& constructor.prototype[s] instanceof Function)
        .forEach(name => {
            const method = constructor.prototype[name];
            getParamNames(method).forEach((parameterName, parameterIndex) =>
                remotableMetadata.registerParam(constructor.prototype, name, parameterIndex, { name: parameterName }));
        });
}

// ATSTODO: Implementar tratamento de erros
// ATSTODO: Implementar suporte a outros métodos além de GET
/**
 * Decorator
 * @param Client
 */
export const Controller = (client, service) => {
    return (Server) => {
        const metadata = remotableMetadata.getTarget(client);
        if (!metadata) {
            throw new Error(`Não encontrou os metadados para o client ${client}`);
        }

        Object.entries(metadata.methods).forEach(([methodName, info]) => {
            if (has(Server.prototype, methodName)) {
                // Já existe uma implementação específica do método
                return;
            }

            const method = service[methodName];
            if (!method) {
                throw new Error(`Método não encontrado: ${methodName}`);
            }

            Server.prototype[methodName] = async (req, res, next) => {
                try {
                    const params = get(info, 'parameters').map(({ name }) => req.params[name] || req.query[name]);
                    const result = await method.apply(service, params);

                    res.status(200).json({
                        status: 'success',
                        data: classToPlain(result)
                    });
                } catch (error) {
                    next(error);
                }
            };
        });
    }
}

/**
 * Decorator
 * @param clientInterface
 */
export const RemoteClient = (clientInterface, baseUrl) => {
    const namedRouter = new NamedRouter();

    return (Client) => {
        const metadata = remotableMetadata.getTarget(clientInterface);
        if (!metadata) {
            throw new Error(`Não encontrou os metadados para o client ${clientInterface}`);
        }

        const restClient = new RestClient('resulth-web', getHost());

        Object.entries(metadata.methods).forEach(([methodName, info]) => {
            if (has(Client.prototype, methodName)) {
                // Já existe uma implementação específica do método
                return;
            }

            const routeName = `autoClient.${metadata.name}.${methodName}`;

            // eslint-disable-next-line
            namedRouter.add('get', (info as any).path, (req, res, next) => {}, { name: routeName });

            Client.prototype[methodName] = async (...params) => {
                const paramsObj = fromPairs(get(info, 'parameters').map(({ name }, idx) => [name, params[idx]]));
                const url = namedRouter.build(routeName, paramsObj);

                const searchParams = new URLSearchParams();
                Object.entries(paramsObj).forEach(([k, v]) => v && searchParams.append(k, String(v)));

                const fullPath = `/api/v1/${baseUrl}/${url}?${searchParams}`;

                const res = await restClient.get<ApiResult<any>>(fullPath);
                return res.result.data;
            }
        });
    }
}

/**
 * Decorador
 * @param path
 */
export const Path = (path: string) => {
    return (target: any, propertyKey: string) => {
        remotableMetadata.forMethod(target, propertyKey).path = path;
    }
}

/**
 * Decorador
 * @param name
 */
export const Param = (name: string) => {
    return (target: any, propertyKey: string | symbol, parameterIndex: number) => {
        remotableMetadata.registerParam(target, propertyKey, parameterIndex, { name });
    }
}

package.json:

{
  "name": "framework-ats",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "electron:build": "vue-cli-service electron:build",
    "electron:serve": "vue-cli-service electron:serve",
    "postinstall": "electron-builder install-app-deps",
    "postuninstall": "electron-builder install-app-deps"
  },
  "main": "background.js",
  "dependencies": {
    "@rauschma/stringio": "^1.4.0",
    "@types/lodash": "^4.14.149",
    "ajv-i18n": "^3.5.0",
    "core-js": "^3.4.4",
    "lodash": "^4.17.15",
    "node-firebird": "^0.8.9",
    "typed-rest-client": "^1.7.1",
    "typescript-ioc": "^1.2.6",
    "v-money": "^0.8.1",
    "vue": "^2.6.10",
    "vue-class-component": "^7.2.2",
    "vue-form-json-schema": "^2.5.0",
    "vue-property-decorator": "^8.3.0",
    "vue-router": "^3.1.5",
    "vue-the-mask": "^0.11.1",
    "vuetify": "^2.1.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.1.0",
    "@vue/cli-plugin-eslint": "^4.1.0",
    "@vue/cli-plugin-router": "^4.1.0",
    "@vue/cli-plugin-typescript": "^4.2.2",
    "@vue/cli-service": "^4.1.0",
    "@vue/eslint-config-typescript": "^4.0.0",
    "@typescript-eslint/eslint-plugin": "^2.19.0",
    "@typescript-eslint/parser": "^2.19.0",
    "babel-eslint": "^10.0.3",
    "electron": "^6.0.0",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "material-design-icons-iconfont": "^5.0.1",
    "sass": "^1.19.0",
    "sass-loader": "^8.0.0",
    "typescript": "~3.7.5",
    "vue-cli-plugin-electron-builder": "^1.4.4",
    "vue-cli-plugin-vuetify": "^2.0.4",
    "vue-template-compiler": "^2.6.10",
    "vuetify-loader": "^1.3.0"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "allowJs": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "typeRoots": [
      "./node_modules/@types",
      "./node_modules/vuetify/types"
    ],
    "types": [
      "webpack-env",
      "vuetify"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

vue.config.js:

module.exports = {
  "devServer": {
    "disableHostCheck": true
  },
  "transpileDependencies": [
    "vuetify"
  ]
}

babel.config.js:

module.exports = {
  presets: [
    [
      '@vue/cli-plugin-babel/preset',
      {
        targets: {
          node: 'current',
        },
    },

    ]
  ],
}

Addendum (2020-03-20)

Managed to make it work partially by to creating an explicit type declaration:

import getParamNames = require('get-param-names');

declare function getParamNames(o: any): string[];

export = getParamNames;

And also changed the import from import * as getParamNames from 'get-param-names'; to import getParamNames from 'get-param-names';; this worked okay for the frontend, which is built through vue-cli, but not for the backend, which is built through ts-node-dev:

ts-node-dev --respawn -- src/index.ts

This gives this error on the backend:

[INFO] 08:15:21 Restarting: D:\Java\framework-ats\api\src\clients\base.ts has been modified
Using ts-node version 8.6.2, typescript version 3.8.2
TypeError: get_param_names_1.default is not a function
    at Object.getOwnPropertyNames.filter.forEach.name (D:\Java\framework-ats\api\src\clients\base.ts:107:26)
    at Array.forEach (<anonymous>)
    at exports.Remotable (D:\Java\framework-ats\api\src\clients\base.ts:105:10)
    at DecorateConstructor (D:\Java\framework-ats\api\node_modules\reflect-metadata\Reflect.js:541:33)
    at Object.decorate (D:\Java\framework-ats\api\node_modules\reflect-metadata\Reflect.js:130:24)
    at __decorate (D:\Java\framework-ats\api\src\clients\product.ts:4:92)
    at Object.<anonymous> (D:\Java\framework-ats\api\src\clients\product.ts:7:36)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module._compile (D:\Java\framework-ats\api\node_modules\source-map-support\source-map-support.js:541:25)
    at Module.m._compile (C:\Users\HAROLD~1\AppData\Local\Temp\ts-node-dev-hook-8308269448535168.js:57:25)
[ERROR] 08:15:21 TypeError: get_param_names_1.default is not a function

BTW, the bug seems very similar to those issues:

How do I compile and run a C# code in VSCode (Linux Ubuntu)?

$
0
0

I'm really struggling trying to compile and run a simple C# "Hello World!" code. Typing "dotnet new" in the terminal does nothing and typing "dotnet new console" simply creates a .csproj file, a "obj" folder and a .cs file (a "Hello World!" code), which I still can't run it. I've already downloaded SDK for linux and the VSCode extensions "C#" and "Code Runner".

When I try using Ctrl+Alt+N the output tab shows "/bin/sh: 1: scriptcs: not found".

VS Code Ways to prioritize HTML emmet over Laravel Blade Snippets?

$
0
0

I have a QOL issue that's really irking me where if I were to press the keys (a key => tab key) or (p key => tab key) and even (li => tab) I don't get the a, p or li HTML tags that want in .blade.php files. The emmet still exists, but the blade snippets are being prioritized which is not what I want.

I've tried jamming a bunch of settings in the settings.json file:

"emmet.includeLanguages": {
  "blade": "html",
  "blade.php": "html",
  "php": "html",
},
"emmet.syntaxProfiles": {
  "blade": "html",
  "blade.php": "html",
  "php": "html",
},
"emmet.showExpandedAbbreviation": "always"

How to make vscode debugging in the terminal less verbose?

$
0
0

When I CTRL + F5, the terminal output shows verbosity that I would like to hide:

cd /home/ ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /usr/bin/python3 /home/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --nodebug --client --host localhost --port 33907 /home/hello.pyHello

Just print Hello...


Visual Studio Code don't recognize HTML file

$
0
0

I am learning to build a Website on Python Django, but when I create a HTML file in VS code, this Editor don't recognize this file. You can see in following picture. I don't know how to solve this problem. Pls help me if you know, thank you very much enter image description here

VScode remote development: How can I run a build task to source environment variables before running the real build task?

$
0
0

I want to setup VScode so I can use build tasks to build my project. The project is build using make, en I have defined a build task that runs make. However, before running make, I normally would source a script that sets my environment variables correctly. If I add a new build task with the source command, and set my main build tasks to first execute the source command, the environment variables are not propagated properly. How can I make sure the enviroment variables are kept between build tasks?

My tasks.json file:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "make",
            "command": "make",
            "args": [],
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOn": "Set environment"
        },
        {
            "label": "Set environment",
            "type": "shell",
            "command": "source path/to/source_me.sh",
            "group": "build",
   ]
}

How can an extension obtain remote URL of file in currently connected remote server?

$
0
0

I'm writing an extension targeted for VSCode Remote environment. In this setup, one extension (UI extension) runs in client and another (workspace extension) runs in remote server.

Now, here's a question - is there any way to generate an URL that can be used by UI extension to access file on the server?

I know I can use vscode-remote://ssh-remote+<hostname>/file/on/server syntax to express this type of remote URL, but the issue here is that I cannot find any way for extension to discover one. Using vscode.Uri.file() API only generates file: URL, which is meaningless for UI extension running in client environment.

Since vscode-remote: scheme is fixed and ssh-remote part can be extracted from vscode.env.remoteName variable, the last piece I need is the hostname that was used to open current VSCode Remote session. Is there any API/variable to discover this?

Error waiting for a debug connection: Bad state: No element Flutter VS Code

$
0
0

Updated vscode today after that created new flutter projects are showing error Error waiting for a debug connection: Bad state: No elementError waiting for a debug connection: Bad state: No element

How do I add the linkers for a library in c++ in vsCODE , im on windows 10,TDM-GCC compiler

$
0
0

I want to use Graphics.h with C++ in my project , dont tell me to not use that library cuz its old,I know what im doing. Ive pasted the header files at the right place now i just need to add the linkers , ive done that before in Code::Blocks but how do I add the linkers for the library visual studio CODE.I have been searching for this for a few weeks wherever i search i get answers for visual studio not visual studio code not a single time someone had a answer for vscode . Since this is not an error I dont think i have to post my code

Ignore determined unused statements (Monobehaviour functions) in c# code with omnisharp

$
0
0

As far a I researched, you can set the configuration of vs code with the .editorconfig file. My problem is that for the unused statements that the lintern highlights because there are no referenced to them, in some cases is useful because the function you started coding might be finally unused so needs to be erased. However monobehaviour functions (Update() for example) has no reference in the code, but of course it is used. This can happen with other functions that might be in the engine, or some .dll of yours or your plugins.

Is there a way to configure in the settings functions you would like to ignore as unused by the lintern because it is known that even they're not referenced in the code to nevigate to them, they get called, so should not be erased?

I got my editor config from:

https://github.com/dotnet/roslyn/blob/1fbd48157d9196ad227f120b731d3f80b1b162de/.editorconfig#L92-L99

many thanks in advance.

How do I refer to another typescript type in comments/JSDoc?

$
0
0

I'm familiar with Javadoc. In Javadoc, you can place a link that refers to the Javadoc placed on another type like so:

/**
 * some java thingy. see this other java thingy too {@link OtherThingy}
 */
public class Thingy { /*...*/ }

/**
 * some other java thingy. see the first java thingy too {@link Thingy}
 */
public class OtherThingy{ /*...*/ }

Can I do the same in typescript's flavor of JSDoc? I know that I can use markdown in the comments and I can place web links but that's not exactly what I'm going for.

Also, any references to JSDoc/typescript documentation tools would be very helpful :)

Edit: Per the answers below, this is a feature of JSDoc but doesn't seem to be included in VSCode. Is there an valid syntax in VSCode?


vscode / sublime text make post request on save

$
0
0

For the purpose of rapid development I would like to REST POST (or websocket) changes to my server every time I save a css file. Is there an existing extension that can help me?

Disable comment with class name in Visual Studio Code

$
0
0

When I create a class like below:

enter image description here

Visual Studio Code adds the comment with Java class name above the class. How do I disable it? I mean I don't need this comment to be added at all.

enter image description here

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined raised when starting react app

$
0
0

I'm working on a project in React and ran into a problem that has me stumped.

Whenever I run yarn start I get this error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined

I have no idea why this is happening, if anyone has experienced this I would be grateful.

typescript IntelliSense not worked in my vscode

$
0
0

MacBook Pro (Retina, 13-inch, Early 2015)

Version: 1.42.1 Commit: c47d83b293181d9be64f27ff093689e8e7aed054 Date: 2020-02-11T14:44:27.652Z Electron: 6.1.6 Chrome: 76.0.3809.146 Node.js: 12.4.0 V8: 7.6.303.31-electron.0 OS: Darwin x64 17.7.0

Tried some method online but it's not worked. And my win10 works fine.

I ran vscode with code . --disable-extensions, not worked.

no typescript version info in the vscode status bar: enter image description here

Parameter areas covered by white translucent will not trigger code hints in vs code, how to fix it?

$
0
0

No hints in the parameters section, GIF here:

Text

I just want the white translucent area to not appear from the beginning.
How to do it? thanks:)

Viewing all 97420 articles
Browse latest View live


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