I have a JS project with babel configuration, and it's configured to support relative paths. Instead of doing this:
import Class from '../../../../somePath/Class';
Writing the code in a more clean way:
import Class from 'app/somePath/Class';
babel.config.js
const plugins = [
[require('babel-plugin-module-resolver'), { root: ["./app/"] }],
];
That's all great, but I struggle with navigation trough files. For example when using CMD+Click on path, to navigate to file doesn't work on relative paths.
Is there a way to support navigations for relative paths in VSCode?
UPDATE
I tried the method suggested by #rioV and add HTML Related Links configuration to my project:
myapp/.vscode/settings.json
Added the following to project settings:
"html-related-links.include": {
"javascript": [
{ "find": "import [^ ]+ from '((?=app/).+?)';", "filePath": "/$1.js" },
{ "find": "import [^ ]+ from '((?!app/).+?)';", "filePath": "$1.js" }
]
},
User/settings.json
Also have included html-related-links.alwaysShow to true in the User settings:
"html-related-links.alwaysShow": true,
"html-related-links.fileroot": [
"./app"
],
And still doesn't seem to navigate when clicking the file path.
You can use the extension HTML Related Links v0.6.0. Now the name is no longer correct because it also can show related files in other file types.
If you add the following to your project/.vscode/settings.json
"html-related-links.include": {
"javascript": [
{ "find": "import [^ ]+ from '((?=src/).+?)';", "filePath": "/$1.js" },
{ "find": "import [^ ]+ from '((?!src/).+?)';", "filePath": "$1.js" }
]
}
The imports that start with src/ are treated relative to the file root folder (most likely the workspace root). If you have a different file root you also need to modify the html-related-links.fileroot setting.
The other imports (do not start with src/) are relative to the current file.
Because you use JavaScript files you also have to set html-related-links.alwaysShow to true in the User settings or the (Multi Root) Workspace settings.
In the Explorer View Container there is a view named HTML Related Links. If you click on one of the entries that file will be opened if it exists.
From VSC v1.46 you can drag/drop views to a different location
Related
My current config is the following:
"latex-workshop.latex.tools": [{
"name": "texify",
"command": "texify",
"args": [
"--synctex",
"--pdf",
"--tex-option=\"-interaction=nonstopmode\"",
"--tex-option=\"-file-line-error\"",
"%DOC%.tex"
],
"env": {}
}
]
However, I am trying to put all the files that are generated, which aren't the output pdf (so .aux and .log for now), somewhere else so it doesn't fill up everything. I don't care if it's a subfolder, or one folder for all project. How can I do this?
You probably moved on from your question but for others with this question, I have found the answer here:
https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-tools
Basically, add this to your settings.json:
"latex-workshop.latex.outDir": "<Name of your output dir>"
(Note: It will include the .pdf file there too)
I am struggling with my VS Code setup in connection with the container extension.
My project structure has one project folder and several libraries on the same level (i.e. libraries are not subfolders of my project folder). The key thing is that I would like to save all config files in my project folder so the information how to bring up the project is version controlled with the project.
If I specify the workspace file as follows (using relative paths) and open the workspace file, things work fine locally.
{
"folders": [
{
"path": "."
},
{
"path": "../library1"
},
{
"path": "../library2"
},
]
}
However, when I try to bring this in my development container, I get the error message:
The workspace cannot be opened in a container. Folder c:\..\library1 is not a subfolder of shared root folder c:\..\project.
I could pull the project definition (and devcontainer.json file) one level up but then they are not under source control of my project folder.
Any ideas how to resolve this?
It seems to be a design limitation. Even if you set the workspace root of the container accordingly, it still doesn't seem to be possible to reference workspace folders outside of the folder containing the workspace definition.
https://github.com/microsoft/vscode-remote-release/issues/387
To start, we could support an open workspace command that is the
equivalent of doing "Open Folder in Container" followed by "Open
Workspace" but does not resolve these two limitations. Specifically it
would:
Look for a .devcontainer/devcontainer.json or .devcontainer.json file
in the same folder as the .codeworkspace file. Mount this folder into
the container and open the workspace. The .codeworkspace file would
only be able to reference sub-folders.
It's 2022 - now using the updated Dev Containers extension.
I have the following structure (in short):
├───deployment
├───documentation
├───service1
│ ├───.vscode
│ └───sources
├───service2
│ ├───.vscode
│ └───sources
└───workspace
├───acme.app.code-workspace
├───.devcontainer
└───devcontainer.json
acme.app.code-workspace
{
"folders": [
{
"path": "."
},
{
"name": "Service 1",
"path": "../service1"
},
{
"name": "Service 2",
"path": "../service2"
},
{
"name": "Deployment",
"path": "../deployment"
},
{
"name": "Documentation",
"path": "../documentation"
}
]
}
devcontainer.json
Nothing really of interest here. Just put in what you need.
{
"name": "Docker in Docker",
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"enableNonRootDocker": "true",
"moby": "true"
},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {},
"ghcr.io/devcontainers/features/python:1": {
"version": "3.11"
}
}
}
So when you start the container, all should be fine.
The only drawback - whether the prompt is acceptable when starting the devcontainer:
This does not work if I bring the .devcontainer folder into it's own workspace folder.
{
"folders": [
{
"path": "."
},
{
"path": "../.devcontainer"
},
...
I installed the Run On Save extension for VS Code. I made a Workspace setting for it, and if I change a file then resave, it does not seem to run. "I run for all files" does not show up in the console or terminal.
When I chose to edit the command configuration in my Workspace settings, it automatically edited the file with the comment "Place your settings in this file to overwrite default and user settings." so it looks like this:
// Place your settings in this file to overwrite default and user settings.
{
"editor.mouseWheelZoom": false,
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
I'm new to configuring Workspace settings, so I'm not sure if this is okay or not. I ensured that Run On Save is enabled by selecting it on the command palette.
Here is the site for the extension: https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
In order to see the console output, you have to be in the Output tab and select the Run On Save option in the dropdown. The extension was created before the integrated terminal existed and hasn't seen a major update in a while.
Regarding the comment that was added to your config:
// Place your settings in this file to overwrite default and user
settings.
is unrelated to this particular extension. It is just vscode letting you know the purpose of the workspace level configuration. It allows you to override a subset of your more global user / default settings. This allows you to keep reasonable default preferences but to customize certain specific things in any given workspace.
Regarding the original RunOnSave extension, feel free to file an issue here https://github.com/emeraldwalk/vscode-runonsave/issues if you have any questions or problems. I would also welcome pull requests if anyone is interested.
I had the exact same issue. I removed that extension and am using this one instead:
https://marketplace.visualstudio.com/items?itemName=wk-j.save-and-run
It is a fork based on RunOnSave. This one works for me when I set its configuration in my user settings and then run the command "Save and Run: Enable".
This one uses the bulit-in powershell terminal.
HTH
In addition to our dear #bingles, I have accidentally discovered that the commands should be added to .vscode/settings.json file instead of .vscode/emeraldwalk.runonsave as said in the plugin documentation
Add it to settings.json and everything should work as expected.
For the extension to work on Workspace you must put the emeraldwalk.runonsave inside settings:
{
"settings": {
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
}
A related one:
Previously I used RunOnSave, this time around I used Code Runner.
Code Runner - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
Below are it's settings I used:
File: %AppData%\Code\User\keybindings.json
{
{
"key": "ctrl+s",
"command": "code-runner.run"
}
}
File: .vscode\settings.json
{
"code-runner.saveFileBeforeRun": true,
"editor.codeActionsOnSave": [
"code-runner.executorMap"
]
"code-runner.executorMap": {
"javascript": "node a.js"
},
}
If possible, you could use Code Runner with the above settings, or use a similar to the above settings for the RunOnSave.
Note that RunOnSave has its own tab which is time-consuming to switch to another tab.
With Code Runner I can see the output in the Output tab itself which is a very nice thing, saves time.
I'm trying VS Code for a few days and I've installed csscomb extension. It works fine when I put .csscomb.json on my work directory.
But I wish it worked even on file I open outside of my work directory.
Could you tell me how to configure VS Code and/or csscomb to work like this?
I use Windows 10 Pro.
According to the csscomb page on VS Code's Marketplace...
They have "Supported settings"
csscomb.preset
Type: Object or String
Defaut: {}
Config's name. Should be one of the
following: csscomb, zen, yandex or an object containing custom
configuration or path to config.
And the following warning:
Warning!
If you want to specify a file in the current directory, the path must
begin with a ./ or ../ if relative to the current directory. Also you
can use HOME directory as ~ symbol.
In other words, since there is no default, you have to set either a preset config or path to a custom config.
To configure csscomb in VS Code:
Go to File > Preferences > Settings
Select the "User Settings" tab in the right window (to apply the config globally)
Expand the options for "CSScomb configuration"
Click the pencil to the left of "csscomb.preset"
Click "Copy to Settings"
Enter the path to your custom config or choose a preset
{
"csscomb.preset": "~/.vscode/.csscomb.json"
}
OR one of ("csscomb", "zen", "yandex")
{
"csscomb.preset": "csscomb"
}
Next, you need to create the .csscomb.json file in that location. I chose the C:\Users\username\.vscode directory because that's where VS Code also downloads extensions on Windows.
Here's the config I created using csscomb's config generator:
{
"always-semicolon": true,
"color-case": "upper",
"block-indent": " ",
"color-shorthand": true,
"element-case": "lower",
"eof-newline": false,
"leading-zero": false,
"quotes": "double",
"sort-order-fallback": "abc",
"space-before-colon": "",
"space-after-colon": " ",
"space-before-combinator": " ",
"space-after-combinator": " ",
"space-between-declarations": "\n",
"space-before-opening-brace": " ",
"space-after-opening-brace": "\n",
"space-after-selector-delimiter": " ",
"space-before-selector-delimiter": "",
"space-before-closing-brace": "\n",
"strip-spaces": true,
"tab-size": true,
"vendor-prefix-align": true
}
You can also include an option for sorting tags (or copy it from one of their presets on git):
{
"sort-order": [
[
"font",
"font-family",
"font-size",
"font-weight",
"font-style"
],
[
"position",
"z-index"
]
]
}
Now you should be able to format CSS within VS Code by typing ctrl+shift+p then typing "CSScomb" then enter.
"Formatter" extensions are supposed to be recognized by the default formatting keyboard shortcut shift+alt+f, however I haven't gotten that to work. I think it's something the developer has to configure.
Instead, you can create your own keyboard shortcut in VS Code:
Go to File > Preferences > Keyboard Shortcuts
Click the link at the top to edit keybindings.json
Add your custom keybinding
{
"key": "ctrl+shift+c",
"command": "csscomb.execute"
}
Now you should be all set!
For the purposes of syntax highlighting and colouring and intellisense is it possible to treat other extensions (tpl, master, etc) as HTML?
I know it's possible on a file by file basis by pressing CTRL+SHIFT+P and selecting "Change Language Mode" BUT I want it to work off file extension, and not have to redo it every time I open a new file.
I also know it's possible for some languages by editing the json files in the plugins directory, BUT there doesn't seem to be one for HTML.
Update for VS Code 1.0:
There is a setting files.associations that can be used to assign file patterns to languages. For example:
"files.associations": {
"*.tpl": "html",
"*.master": "html"
}
Previous answer:
This is a commonly asked feature request and we are looking into this issue for the future.
As a workaround if you need to have a solutio now:
close VS Code
open C:\Users\<your name>\AppData\Local\Code\app-<latest-version>\resources\app\server\lib\mime.js
find the object literal knownTextMimes
for the file extension you want add the proper mime type
for example '.tpl': 'text/html'
save and restart code
Note: this change will not survive automatic updates but the hopes are that there is a better solution in the future update :)
(Tested on version 1.59.1)
It is also possible to set Associations through GUI:
Go to Settings->Text Editor->Files->Associations.
Set Item (file extension) and Value (language).
Open notepad as admin (just in case) by right clicking run as admin.
Click file => open => copy and paste C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\html in box.
select view all file types at bottom right.
Open package.json
Copy and paste
{
"name": "html",
"version": "0.1.0",
"publisher": "vscode",
"engines": { "vscode": "*" },
"extensionDependencies": [
"html"
],
"contributes": {
"languages": [{
"id": "html",
"aliases": ["pd"],
"extensions": [".pd"]
}]
}
}
replace everything with that.
save and quit
restart vs code.
I resolve the issue for my with installing Smarty Extension 1.1.1 + adding this settings into Settings.json
"files.associations": {
"*.tpl": "smarty",
"*.master": "smarty"
}
Jesse's answer is correct. I don't have enough reputation points to comment on his answer, but the path for Mac users is:
cd /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/extensions/html/
Note that there will already be some extensions so instead of copying and pasting the code snippets wholesale, simply add the extension you'd like to the extensions and aliases array like so:
{
"name": "html",
"version": "0.1.0",
"publisher": "vscode",
"engines": { "vscode": "*" },
"contributes": {
"languages": [{
"id": "html",
"extensions": [ ".html", ".htm", ".shtml", ".mdoc", ".jsp", ".asp", ".aspx", ".jshtm", ".ejs" ],
"aliases": [ "HTML", "htm", "html", "xhtml", "ejs" ],
"mimetypes": ["text/html", "text/x-jshtm", "text/template", "text/ng-template"]
}],
"grammars": [{
/* "language": "html", not yet enabled*/
"scopeName": "text.html.basic",
"path": "./syntaxes/HTML.plist"
}]
},
"extensionDependencies": [
"html"
]
}