I noticed, if I define a c_cpp_properties.json for the "C/C++" plugin in my user config folder "~/.vscode" instead of the project config folder, the file is not parsed. My aim is to define some global include directories, which are used in all projects. I haven't found a clear answer whether and how this is possible (or not).
{
"configurations": [
{
"includePath": [
"/foo/*"
]
}
]
}
Related
I have been working on a vsCode extension and was able to launch and debug fine.
But now after bundling the extension with webpack I'm unable to bind breakpoints correctly
Things that I have tried
Apply the solutions mentioned in https://stackoverflow.com/a/53236103/1461862
Change the outFiles from /out/ to /dist/
removing the outFiles configuration
The dist folder contains an extension.js.map but still vscode is unable to bind the breakpoints
but the problem continues
The error I'm getting is:
We couldn't find a corresponding source location, and didn't find any
source with the name extension.ts
Here are the relevant files
lauch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
Here is the webpack.config.js
'use strict';
const path = require('path');
/**#type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output: { // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
filename: 'extension.js',
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "../[resource-path]",
},
devtool: 'source-map',
externals: {
vscode: "commonjs vscode" // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
},
resolve: { // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js']
},
module: {
rules: [{
test: /\.ts$/,
exclude: /node_modules/,
use: [{
loader: 'ts-loader',
options: {
compilerOptions: {
"module": "es6" // override `tsconfig.json` so that TypeScript emits native JavaScript modules.
}
}
}]
}]
},
}
module.exports = config;
You need to change the outFiles configuration in your launch.json file to match the output folder of your webpack bundle. In your case, it should be:
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
This will tell VSCode where to look for the source maps and the transpiled JavaScript files that correspond to your TypeScript files. The devtoolModuleFilenameTemplate option in your webpack.config.js file is also important, as it tells webpack how to generate the source map paths relative to your workspace folder.
The reason why you are getting the error We couldn't find a corresponding source location, and didn't find any source with the name extension.ts is because VSCode is looking for the source file in the out folder, which is not where webpack puts it. By changing the outFiles configuration, you are telling VSCode to look for the source file in the dist folder instead, where webpack has generated the source map and the transpiled JavaScript file.
To understand more about how VSCode debugs TypeScript files with webpack, you can read this article: https://code.visualstudio.com/docs/typescript/typescript-compiling#_webpack
I hope this answer helps you solve your problem.
Another solution that is worth trying, is to re-open visual studio directly in the folder that your project is contained within.
On windows (perhaps also mac), navigate to the folder where your project is located with a terminal and open code here with:
code .
Try your debugging tools again, and see whether or not you hit the break points this time.
I use CTRL+Click (or F12) to search and open the definitions in vscode. The problem is that my files are copied to another directory called sketch as I compile my code, so when I wanna open the definition of a function, VS shows both files (the real and the copied ones in the sketch folder), and sometimes I edit the copied file by mistake!
How can I exclude some folders from the "Go To definition"?
I had the same problem in a Javascript project.
None of the following solved it for me: files.exclude, files.watcherExclude, or search.exclude.
The solution was to add jsconfig.json to my project folder:
{
"compilerOptions": {
"target": "ES6"
},
"exclude": [
"Backup",
"Sketch"
]
}
This example specifies two folders to exclude: "Backup", and "Sketch".
If you are using TypeScript, use a tsconfig.json file instead.
Also see https://code.visualstudio.com/docs/languages/jsconfig
Add files to C:\Users\user\AppData\Roaming\Code\User\settings.json:
"files.exclude": {
"**/sketch": true
},
Or files to exclude when searching (in files):
"files.watcherExclude": {
"**/*.x": true,
},
I want to make a AMX mod X script, this modules are related which game I make, so I am using workspace as configuration. Making compiler, library and output path dependent of each game.
my source code has same folder as compiler
I've tried to write ./ and .\\ but it's won't work, vscode still can't find amxxpc.exe, here's my configuration workspace:
{
"folders": [
{
"path": "."
}
],
"settings": {
"amxxpawn.compiler.executablePath": "./amxxpc.exe",
"amxxpawn.compiler.includePaths": [
"./include"
],
"amxxpawn.compiler.outputPath": "../plugins",
"amxxpawn.compiler.outputType": "path"
}
}
amxxpawn.compiler.executablePath still can't figure amxxpc.exe until I wrote full path. since this placed in same folder as source code, I also tried to remove ./ but still can't find it.
here's my extension I use: https://marketplace.visualstudio.com/items?itemName=KliPPy.amxxpawn-language
This is not always work in every extension but I moved every configs in workspace settings to user.json and then use ${workspaceFolder} as relative variable, for e.x:
"amxxpawn.compiler.includePaths": [
"${workspaceFolder}/include"
]
workspace still used but I left it folder and path alone, also making path value to . means location of workspace file
I am putting together a simple C project in VS Code which would just compile a single C file using GCC compiler.
I have created a c_cpp_properties.json and tasks.json.
It is unclear to me where is the GCC compiler supposed to get include directories from.
When include dirs are added to c_cpp_properties.json via the includePath
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/include/path1",
"C:/include/path2"
],...
it doesn't work.
It only compiles successfully when I add the paths as compiler arguments to tasks.json:
"tasks":
[
{
"label": "Compile C file",
"type": "shell",
"command": "gcc",
"args": [
"-g",
"-I",
"C:/include/path1",
"-c",
"myfile.c"
],...
Where is the GCC compiler supposed to get include directories from?
What is the includePath in c_cpp_properties.json for?
c_cpp_properties.json Reference Guide says:
includePath:
If "C_Cpp.intelliSenseEngine" is set to "Default" in your settings file, this list of paths will be used by IntelliSense to search for headers included by your source files. This is basically the same as the list of paths you pass to your compiler with the -I switch. If a path ends with /** the IntelliSense engine will do a recursive search for includes starting from that directory. If on Windows with Visual Studio installed, or if a compiler is specified in the compilerPath setting, it is not necessary to list the system include paths in this list.
When writing a javascript app, it's possible to create an .env file in the root directory containing just e.g:
NODE_PATH=src/
Which sets up allowing for absolute paths e.g: in import statements in code.
e.g: I can be working on the file /src/actions/index.js and enter:
import { SAVE_COMMENT } from "actions/types";
..and the import works, but there is no auto-complete and I wonder: Is it possible to auto-complete after I type just:
import { SAVE_COMMENT } from "actions/
?
Relative-path lookup continues to work great. In fact, the relative path lookup is one of my favorite features of vs-code and one of the reasons I use it, so it would be very nice for it to work when absolute paths are configured, too.
VS Code does not support using NODE_PATH for intellisense. To achieve what you want, create a jsconfig.json file at the root of your project with the contents:
{
"compilerOptions": {
"target": "ES6",
"baseUrl": "./src"
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
The important setting is baseUrl. It tells VS Code to resolve non-relative paths relative to the ./src folder
After configuring jsconfig and baseUrl, you can also set "javascript.preferences.importModuleSpecifier": "non-relative" in VS Code to specify that VS Code should always try to use paths to use the baseUrl
Here is a nice guide for Vue.js and Nuxt.js projects configuration in VS Code
this is the solution that worked for me
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"core/*": ["./src/*"],
}
}
}
I am using webpack and absolute paths