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"
]
}
Related
I'm writing a VSCode custom editor extension.
The extension should be activated for component.yaml files.
However I realize that there could be files named component.yaml with completely different formats.
I want to detect that the file is not in expected format and bail out, skipping my extension, so that the file opens in the default text editor or another registered extension.
How can my extension refuse/skip opening a file?
An extension cannot refuse to be opened, but you can specify a regular expression for the first line in the file, which has to match to allow your extension to be activate for that file.
{
"contributes": {
"languages": [
{
"id": "python",
"extensions": [".py"],
"aliases": ["Python", "py"],
"filenames": [],
"firstLine": "^#!/.*\\bpython[0-9.-]*\\b",
"configuration": "./language-configuration.json",
"icon": {
"light": "./icons/python-light.png",
"dark": "./icons/python-dark.png"
}
}
]
}
}
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)
In vscode I experience sometimes I can click on build errors in the integrated terminal and sometimes it is not possible to do so. This has annoyed me for quite some time because I was not able to find a pattern, until today when I was editing tasks.json.
It looks to be related to defining a problemMatcher in .vscode/tasks.json. Removing the problemMatcher section from the file and build errors in terminal were no longer clickable but putting it back did not re-enable them.
My vscode-project is located in a subfolder of the build tree and its build root for the entire project is two levels up ${workspaceFolder}/../.. which I believe maybe could confuse some build tools.
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"problemMatcher": {
"fileLocation": "relative",
"severity": "error",
"pattern":{
"regexp": "^system/mytool/(.*):(\\d+):(\\d+):\\s+(warning|error):(.*)$",
"file": 1,
"location": 2,
"column": 3,
"severity": 4,
"message": 5
},
},
"tasks": [
{
"type": "shell",
"label": "android deploy",
"command": "cd ${workspaceFolder}/../..; source build/envsetup.sh ; lunch hikey960-userdebug ; m mytool",
"args": [
],
"options": {
},
"group": "build"
},
]
}
I have seen examples putting "problemMatcher" = "$gcc" inside the task, should I define my problem matcher globally somewhere else and refer to it my name instead?
How to use it to parse the output when I build by typing make-commands in the integrated terminal?
You cannot define problem matchers globally. Instead you have to define them in each task.
This is somewhat ugly because you may have to copy the same problem matcher into a lot of tasks. There is an open issue for this: Global task properties
I have a template, which defines all the typesetting recommendations for thesis, but it uses xelatex for compilation. I want to continue using VS Code with Latex Workshops, question is how to change compiler to xelatex from pdflatex. The last one cause next error log:
C:\Users\User\AppData\Local\Programs\MiKTeX 2.9\tex/latex/fontspec\fontspec.sty:45: Fatal Package fontspec Error: The
fontspec package requires either XeTeX or
(fontspec) LuaTeX.
(fontspec)
(fontspec) You must change your typesetting engine to,
(fontspec) e.g., "xelatex" or "lualatex"instead of
(fontspec) "latex" or "pdflatex".
The simplest solution found in issues here, but in more common formulation:
Copying the content, simply go to Preferences → Extensions → LaTeX (meaning LaTeX is LaTeX workshops), find gear-wheel button with name Manage, then find in the list link to settings.json under any tag, open and type next:
"latex-workshop.latex.tools": [{
"name": "latexmk",
"command": "latexmk",
"args": [
"-xelatex",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
}],
Reloading the VSCode may be needed.
Also setting.json file could be found in C:\Users\*\AppData\Roaming\Code\User\settings.json.
Use magic comments
add the following line to the beginning of your document.
% !TEX program = xelatex
To enable magic comments, change the setting forceRecipeUsage to false.
I kept getting errors with the other solutions, apparently because I was using backend=biber in my latex code. The following configuration assumes a current MiKTeX setup (including biber) and fixes those problems (also, this does not rely on latexmk). The config uses some inspiration from that of TeXworks.
Inside latex-workshop.latex.tools
{
"name": "xelatex",
"command": "xetex",
"args": [
"-undump=xelatex",
"%DOC%.tex"
],
"env": {}
},
{
"name": "biber",
"command": "biber",
"args": [
"%DOC%"
],
"env": {}
}
Then inside latex-workshop.latex.recipes add the recipe:
{
"name": "xelatex ➞ biber ➞ xelatex x 2x",
"tools": [
"xelatex",
"biber",
"xelatex",
"xelatex"
]
}
Happy texing!
I am trying to publish a private extension for AzureDevops on Visual Studio Marketplace. It is a .vsix package. The packaging goes well, I upload a package, but it doesn't pass a verification. I obtain the following error:
Extension validation error The task.json file was not found in
contribution xxx
And I don't know why I get this one as I have a task.json file. It is the first time that I am trying to upload a package, so I really have no idea where the problem comes from.
As Shayki mentioned that is one possible cause for the issue. Another possible issue will be the folder/path name
Make sure you will give the same name for the files as the name of the properties
"contributions": [
{
"id": "..."
"types": "..."
"targets": "..."
"properties": {
"name": "buildAndReleaseTask"
}
}
],
"files": [
{
"path": "buildAndReleaseTask"
}
]
For anyone that stumbles upon this question, the JSON file with your task configuration literally needs to be named "task.json". In your extension file, you need to give the name for each of your tasks folders, in which there must be an individual task.json file.
In the vss-extension.json you have this section:
"contributions": [
{
"id": "..."
"types": "..."
"targets": "..."
"properties": {
"name": "buildAndReleaseTask"
}
}
]
In my case the task.json was in buildAndReleaseTask folder, and the name in the properties was something else (the name you got in the error message), when I changed it to the name to buildAndReleaseTask (where the task.json exist) the error disappeared.