I enabled the VS Code extension, "Code Spell Checker," and it works great. However, I wanted to include words from my custom dictionary file so the words in it aren't flagged as incorrect. I tried the following in my settings.json:
"cSpell.customUserDictionaries": [
"name": "Custom",
"description": "These are words from my custom dictionary.",
"path": "C:\\Users\\Joe\\Documents\\Custom.txt",
"addWords": false
],
But the words in Custom.txt are still marked as incorrect.
How can I configure Code Spell Checker so that it's able to load all the words in Custom.txt and ignore them?
According to their package.json that configuration is expecting a typeof array of objects, so the following should work:
"cSpell.customUserDictionaries": [
{
"name": "Custom",
"description": "My desc",
"path": "C:\\Users\\Joe\\Documents\\Custom.txt",
"addWords": false
}
],
And per their description:
File Format: Each line in the file is considered a dictionary entry
Related
I have an Azure custom task implemented with Typescript with a task.json containing a string input which is supposed to get a semantic version:
{
"name": "version",
"type": "string",
"required": true,
"label": "Version",
"defaultValue": "",
"helpMarkDown": "",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
},
Even though the regex for the version is defined (and the regex itself is correct and taken from the semantic version's official docs), the user can still enter whatever string he wants with no limitation and no error message is shown.
How do I make the input show an error message when the user enters an input which does not match the regular expression?
You need to use the validation.expression and message, like in this example:
https://github.com/microsoft/azure-pipelines-tasks/blob/b0e99b6d8c7d1b8eba65d9ec08c118832a5635e3/Tasks/KubernetesManifestV0/task.json#L90
"validation": {
"expression": "isMatch(value, '(^(([0-9]|[1-9][0-9]|100)(\\.\\d*)?)$)','Multiline')",
"message": "Enter valid percentage value i.e between 0 to 100."
}
See also:
https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/taskinputvalidation.md
I have a response object in my swagger.json file that includes a nested object as one of its fields. When I use Autorest.Powershell to generate a client for this API, it flattens the nested object. So when the service returns the following response:
{
"code": 200,
"status": "OK",
"data": {
"FileName": "gameserver.zip",
"AssetUploadUrl": "https://example.com"
}
}
my Autorest.Powershell client returns a flattened object like this:
{
"code": 200,
"status": "OK",
"dataFileName": "gameserver.zip",
"dataAssetUploadUrl": "https://example.com"
}
Is there some sort of configuration setting I can use to disable this behavior?
Here are the relevant portions of my swagger.json file, if it helps:
"definitions": {
"GetAssetUploadUrlResponse": {
"type": "object",
"properties": {
"AssetUploadUrl": {
"description": "The asset's upload URL.",
"type": "string"
},
"FileName": {
"description": "The asset's file name to get the upload URL for.",
"type": "string"
}
},
"example": {
"FileName": "gameserver.zip",
"AssetUploadUrl": "https://example.com"
}
}
},
"responses": {
"GetAssetUploadUrlResponse": {
"description": "",
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"description": "The Http status code. If X-ReportErrorAsSuccess header is set to true, this will report the actual http error code."
},
"status": {
"type": "string",
"description": "The Http status code as a string."
},
"data": {
"$ref": "#/definitions/GetAssetUploadUrlResponse"
}
},
"example": {
"code": 200,
"status": "OK",
"data": {
"FileName": "gameserver.zip",
"AssetUploadUrl": "https://example.com"
}
}
}
}
}
There are several ways, none of which is really straightforward (as, I'm starting to believe, is the case with most things AutoRest-related; sorry, couldn't resist :-P ).
There are three semi-official ways. Semi-official here means they are based on public AutoRest mechanism but are not themselves documented. Being semi-official, they might only work with certain versions of AutoRest components, so, here are the ones I used
(from autorest --info):
#autorest/core (3.0.6369)
#autorest/modelerfour (4.15.414)
#autorest/powershell (3.0.421)
Finally, here are the relevant parts of AutoRest's code base: inline properties plug-in and configuration directive definition
inlining-threshold setting
This setting control the maximum number of properties an inner object could have for it to be considered eligible for inlining. You can set it either on the command line or in the "literate config" .md file.
```yaml
inlining-threshold: 0
```
In theory, setting this to 0 should prevent any inner member's properties from being inlined, however the plug-in has a hard-coded exception that if the inner object is in a property that's itself named properties then the limit is ignored and it's still flattened.
definitions:
SomeSchema:
type: "object"
properties:
detail_info: # <-- threshold honored
$ref: "#/definitions/InfoSchema"
properties: # <-- this is always flattened because of its special name
$ref: "#/definitions/OtherSchema"
no-inline directive
The PowerShell AutoRest plug-in also defines a custom directive that is used to specify that certain schemas should never be inlined. Using "literate config", it goes like
```yaml
directive:
- no-inline:
- OtherSchema
- ThirdSchema
```
The pros of this approach are that the no-inline directive overrides the "always inline properties in a property named properties" exception mentioned above, so it can be used to alleviate the problem.
The cons are that all schema names should be listed explicitly. (It seems the directive should also support Rx name expression but I couldn't get no-inline: ".*" to work)
Low-level transform
This is approach disables inlining unconditionally in all cases, however it is coupled to the specific internal code model used by AutoRest. (In principle, the model should be stable, at least within major versions). It also relies on the PowerShell plug-in using a specific (non-contractual) property to flag schemas excluded from inlining.
```yaml
directive:
- from: code-model-v4-no-tags
where: $.schemas.objects.*
transform: |
$.language.default['skip-inline'] = true;
```
Does anyone know of a way that I can insert the current date & time in a visual studio code by snippets?
I have looked docs but did not get any information about it.
I want to create a snippets like this:
title: theFileTitle
date: 2016-08-05 09:44:16
As of Jan 2018 (release 1.20) you can use these new snippet environment variables.
Your example above would look like this:
"File Header": {
"prefix": "header",
"description": "Output a file header with the file name and date",
"body": [
"title: $TM_FILENAME",
"date: $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
]
}
Type head, press ctrl+space and it should show snippet menu.
I have created an extension for you that allows to insert formatted date and/or time string - Insert Date String.
Installation
Open Command Palette by pressing F1, type ext install + press Enter and then look for Insert Date String extension.
Usage
To insert current date and/or time at the cursor position you can:
Press ⇧+⌘+I (OS X) or Ctrl+Shift+I (Windows and Linux), or open Command Palette by pressing F1 and type Insert DateTime then press Enter.
Configuration
By default you don't have to set anything. But if you want to change the datetime format, look for insertDateString.format option in user settings.
// Date format to be used.
"insertDateString.format": "YYYY-MM-DD hh:mm:ss",
You can specify any valid ISO 8601 format. There are some examples in readme.
Snippet
Unfortunately you can't use anything more than tab stops or variables in snippets so you'll have to enter the title and date/time manually.
You can define snippets for specific languages. To open a snippet file for editing, open User Snippets under File > Preferences (Code > Preferences on Mac OS X) and select the language for which the snippets should appear.
Following example is for Plain Text files.
After opening a snippet file for Plain Text, add following definition:
{
"File header": {
"prefix": "header",
"body": [
"title: ${title:Enter title}",
"date: ${date:Insert datetime string (⇧⌘I or Ctrl+Shift+I)}"
]
}
}
Now you can open a new plaintext file, enter header and press Tab. Enter your title and use Insert DateTime command to insert current date and/or time.
Idea for a more customizable solution
One could write an extension for inserting such headers. This way some sort of templates with several predefined variables (e.g. date, filename, configurable username/email, etc.) might be used.
Hope this helps!!
if you don't want create a snippet, there is a simple way, using keybindings.
open keybindings.json (Preferences: Open Keyboard Shortcuts (JSON)), and add fellow code to your keybindings.json
[
{
"key": "cmd+k t",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND"
}
}
]
that's all.
now you can use cmd+k t to insert current data time while typing.
You can just use the following variables in your snippets:
$CURRENT_YEAR
$CURRENT_YEAR_SHORT
$CURRENT_MONTH
$CURRENT_DATE
$CURRENT_HOUR
$CURRENT_MINUTE
$CURRENT_SECOND
Links to the official VSCode docs:
date and time in snippets
user defined snippets
The env variable TM_FILENAME will fill the title with the file name automatically.
For example:
"title: ${1:$TM_FILENAME_BASE}"
You could also use a tool outside of Code, like for example Texter.
I have configured it to replace [t with [%ds %t], which gives me [9/11/2017 16:30] while I type, regardless of application.
It might be a bit of an overkill but you can check Org Mode extension which has this functionality and more:
You can use this snippet for Vscode, I used to refer to this in my code files.
"file description": {
"prefix": "template",
"body": [
"\"\"\"",
"# _* coding: utf8 *_",
"",
"filename: $TM_FILENAME",
"",
"#author: sounishnath",
"createdAt: $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
"\"\"\"",
"",
""
],
"description": "file description"
}
See https://stackoverflow.com/a/74082031/836330 for how to insert the Intl.DateTimeFormat timeStamp with options with a keybinding:
Or see Command Variable extension. It uses the Intl.DateTimeFormat format and can be used in a keybinding like so:
{
"key": "alt+d",
"when": "editorTextFocus",
"command": "extension.commandvariable.dateTimeInEditor",
"args": {
"locale": "en-US",
"options": {
"year": "numeric",
"month": "long",
"weekday": "long",
"day": "2-digit",
"hour12": false,
"hour": "2-digit",
"minute": "2-digit",
"second": "2-digit"
},
"template": "${month} ${day}, (${weekday}), ${year} - ${hour}:${minute}::${second}"
}
},
to produce
March 25, (Wednesday), 2020 - 21:16::49
and many other timestamp versions. See the possibilities at Intl.DateTimeFormat
I've been using vscode with cpptools from Microsoft. I've successfully attached the debugger (gdb) from the launch.json configuration to my project.
But I require to use the "environment": [] array to setup my project so I can start a new debugging session from within vscode. But I don't know the usage syntax for that array and the documentation doesn't cover that part.
I've figured out of parsing errors reported by vscode the first element it "Name". But what is the value tag? This at least doesn't work...
"environment": [
{
"Name": "LD_LIBRARY_PATH",
"Value": "/opt/mylibs",
}
]
How Do I've to fill this variable? Thank you
I've finally figured it out. My initial example was almost correct but needed to be lowercase... like this:
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "/opt/mylibs"
}
]
https://code.visualstudio.com/Docs/editor/debugging suggests a format of
"env": {
"LD_LIBRARY_PATH": "/opt/mylibs"
},
In launch.vs.json, under the configurations, "env": { "LD_LIBRARY_PATH": "/your/path/to/lib" }
I am attempting to access elements with a specific class name from a page using a content script of a Chrome extension. So far the content script can successfully find an element with a specific id using document.getElementById(), but using document.getElementsByClassName() or jQuery's $(".className") yields no results. For the sake of testing, I used 'header' as my class name and every website I ran the extension on resulted in an array length of 0. Any ideas what I might be missing? Here's what I have been testing with:
manifest.json
=================
{
"name": "Sample Extension",
"version": "0.0.1",
"description": "Sample extension",
"icons": {"128": "icon.png"},
"permissions": [
"tabs", "<all_urls>"
],
"browser_action": {
"default_icon": "browseraction.png",
"default_title": "Sample",
"popup": "popup.html"
},
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"js": ["scripts/contentscript.js"],
"run_at": "document_end"
}
]
}
contentscript.js
===================
var elems = document.getElementsByClassName("header");
alert( elems.length );
Your code is very basic and straightforward, it can't be a cause of problem. In fact, I just used your exact code (with "says" class and website you provided) and alert() says every and each time 1 (which is correct).
My best guess is that you haven't reloaded your extension after making changes in contentscript.js OR some other extension is interfering and causing this strange behavior. Try disabling other extensions before testing your extension.