In Visual Studio Code ( VS Code ) is there a way to have comments of different colors in the same document? (i.e. for different topics | people) - comments

Example:
Alicia and Bob are writing code together.
Alicia makes comments and they show up as green.
Bob makes comments and they show up as pink.
Potential Solution Concept that probably doesn't exist:
When Alicia comments, Alicia uses "/* comment here /" and text is green.
When Bob comments, Bob uses /. comment here .*/ and text is pink.

You can add the extension Better Comments for that.
Then, in your settings.json file you can add the rules for Alicia and Bob, as such:
{
"better-comments.tags": [
{
"tag": "Alicia",
"color": "#70C7CA",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "Bob",
"color": "#C792EA",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
}
}
You can then personalise colors and styles, and create as many tags as you want.
After that, comments that start with "Alicia" or "Bob" will have their corresponding styles.
You may need to reload VSCode for these to apply.
And mind that both Alicia and Bob need to have that extension, and configured to display the styled tags on both computers.

Related

Need help configuring TinyMCE in Laravel Voyager

I'd like to tweak the default configuration of TinyMCE in Laravel Voyager. In particular, I want to remove the option for creating H1 tags in body content, since semantically there should only be one H1 on the page and it's stored in a different field.
The Voyager instructions are pretty straightforward:
https://voyager-docs.devdojo.com/customization/tinymce
So, I:
1. created a new file in resources/js called voyager_additional.js,
2. added it to my Mix configuration (.js('resources/js/voyager_additional.js', 'public/js'),
3. added the two functions specified in the Voyager docs,
function tinymce_init_callback(editor)
{
console.log('Init!');
}
function tinymce_setup_callback(editor)
{
console.log('Setup!');
}
put console.log messages in the functions to demonstrate that they are being called, and
added 'js/voyager_additional.js' to the additional_js array in config/voyager.php.
The additional JavaScript file is being created in the right place, and my Voyager admin pages can find it, but something's not right because the console.log messages never appear (none of the TinyMCE code I've put in the functions seems to have an effect, either). There's clearly a little more to it than the documentation indicates. What am I missing?
Aaaaaahhh...don't process the extra JavaScript code as with .js in your Mix file. Just copy it:
.copy('resources/js/voyager_additional.js', 'public/js')
Now my console.log messages show up and the changes I make to the TinyMCE configuration work.
(Quick note: the format of the setting changes should be, for example:
editor.settings.style_formats = [
{ title: 'Heading 2', format: 'h2' },
{ title: 'Heading 3', format: 'h3' },
{ title: 'Paragraph', format: 'p' },
];
editor.settings.toolbar = 'removeformat | styleselect bold italic | alignleft aligncenter alignright | bullist numlist outdent indent | link image table | code';
and changes seem to want to be in the setup, rather than the init, function.)
I'm glad this turned out to be something small and simple!

Visual Studio Code multi-line comment for files with no extension

I'm editing a file with no extension (for example... or a file with an unknown extension, etc), and when i try to multi-line comment using Cmd+/ it doesn't do anything. I can change the extension to .py or .yaml to get the # comment feature i'm looking for, but that's a total pain. Is there a way to tell code "act like a .py extension on the file" type of thingy?... or maybe replace CarriageReturn+LineFeed with CarriageReturn+LineFeed plus # plus space ... or FORCE the Cmd+/ to work?
Finally found a couple of solutions that works... NO extensions, etc...
Just hold (mac)Option+Cmd (while in column 1), then click down arrow to multi-cursor select all of the lines, then simply type # to put that in col.1, and remainder will move over 1 column to right... you can do this again, to add another #, for example.
Also, another option is to:
-Go to Selection> ColumnSelectionMode, (put into column mode) then drag down, does "multi-select"!! ..then type # to comment lines, for example!!
I am a little surprised but this seems to work - test it out. You will need a macro extension of some sort. Here I am using the multi-command extension.
In your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.addCommentNoExtension",
"sequence": [
"editor.action.insertCursorAtEndOfEachLineSelected",
"cursorHome",
{
"command": "type",
"args": {
"text": "# "
}
},
"removeSecondaryCursors"
]
},
{
"command": "multiCommand.removeCommentNoExtension",
"sequence": [
"editor.action.insertCursorAtEndOfEachLineSelected",
"cursorHome",
"deleteRight",
"deleteRight",
"removeSecondaryCursors"
]
}
]
In your keybindings.json put these keybindings:
{
"key": "cmd+/",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.addCommentNoExtension" },
"when": "editorTextFocus && resourceFilename =~ /^(?!.*\\.)/"
},
{
"key": "shift+/",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.removeCommentNoExtension" },
"when": "editorTextFocus && resourceFilename =~ /^(?!.*\\.)/"
},
Here is a demo:
.
There are some limitations to this approach rather than a full-blown extension.
The last cursor position will not be remembered.
Empty lines will be commented - as you can see in the demo.
When block-commenting lines of different indentation, the comment #'s won't line up.
You have to use one keybinding Cmd+/ to add comments, and another binding Shift+/ to remove comments. I don't think there is a way to make it a one-command toggle.
The really interesting part of this answer is how files with no extension are targeted. In the keybindings there are when clauses that include resourceFilename =~ /^(?!.*\\.)/.
When clauses can take a regex to apply to certain keys like resourceFilename. See when clause operators. The regex /^(?!.*\\.)/ says to apply this keybinding when the filename does not include a literal .. It uses a negative lookahead asserting that there is no . following any characters.
I wasn't sure that was possible but it seems to work. The Cmd+/ command still works as it should with other file types.
You could use "when": "editorTextFocus && editorLangId == plaintext" and that would work as long as your files with no extension remained as plaintext langId files. It isn't quite as specific as the when clause I used above.

Automatically enclose a string within another string?

Let's say that I have some string, X, and that I want this to be enclosed within some other strings, for example like this: \emph{X}. Is there some tool that lets me do this quickly, for example through selecting the text and pressing a short-cut on my keyboard? I'm working in Sublime text in macOS Sierra.
This is something that is possible from directly within Sublime using a key binding that inserts a snippet, where the snippet body is told to include the text that is currently selected.
For your example above, the following key binding will wrap the selection in \emph{}. I used Super+W for my own testing, but you probably want to pick something better for your own purposes.
{
"keys": ["super+w"],
"command": "insert_snippet",
"args": {"contents": "\\emph{${0:$SELECTION}}"},
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
]
},
The inclusion of context here makes the key binding only active while all of the cursors have at least one character selected. If desired you can remove the context section entirely, in which case the key binding will either insert the snippet and leave the cursor between the braces, or wrap the selection, depending on the state of the selection.
If your snippet is more complex and involved than this (e.g. multiple lines), trying to insert the entire body of it into the key binding can be a little taxing. In that case, you probably want to use an external snippet instead.
To do that, you can select Tools > Developer > New Snippet... from the menu, and use a snippet such as the following, which you should save in the location that Sublime defaults to:
<snippet>
<content><![CDATA[
\emph{${0:$SELECTION}}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
With this in place, the key binding from above needs to be modified to tell the insert_snippet command to insert the snippet with a particular file name instead of with raw content:
{
"keys": ["super+w"],
"command": "insert_snippet",
"args": {"name": "Packages/User/emph.sublime-snippet"},
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
]
},
Things to note here are that the key binding files are JSON, and so the contents of the snippet need to be adjusted slightly to make them valid JSON. In the example above that means using \\ instead of just \ to specify \emph.
Snippets in general also have their own special characters in them, so if you for example need to insert a $ you need to quote it as \$ so that Sublime knows what you mean; this is true regardless of whether the snippet is in a snippet file or inline.
More information on key bindings and snippets can be found in the Unofficial Documentation for a more complete picture of everything that's possible with them.

How do I deal with rich content with the Microsoft Bot Framework?

I'm not sure how to deal with rich content. Some examples that I want to return are a list of hyperlinks or a/some image thumbnails. How do I do this? I tried formatting my text as HTML and that crashed the Bot Emulator and caused the Web Chat client to just display encoded HTML.
Is there a secret to this or some documentation explaining this?
Markdown. Bot Framework converts Markdown to the rich native formats for each channel.
Some channels support even richer content via the ChannelData field (for example, you can send Slack Cards through our Slack channel in the ChannelData field) but all of our channels do the right thing for that channel if you send Markdown.
Edit: docs here: http://docs.botframework.com/connector/message-content/#the-text-property-is-markdown
You may find github's link helpful:
https://guides.github.com/features/mastering-markdown/
Style Markdown Description Example
Bold **text** make the text bold
Italic *text* make the text italic
Header1-5 # H1 Mark a line as a header
Strikethrough ~~text~~ make the text strikethrough
Hr --- insert a horizontal rule
Unordered list * Make an unordered list item
Ordered list 1. Make an ordered list item starting at 1
Pre `text` Preformatted text(can be inline)
Block quote > text quote a section of text
link [bing](http://bing.com)
image link ![duck](http://aka.ms/Fo983c)
Note the channels will vary as to what subset of markdown they support.
You may find this thread useful with some examples and Yes MD is the answer.
https://github.com/microsoft/BotFramework-WebChat/issues/2289
so say if you want to do an unordered list.
Unordered list\r\n\r\n* An item\r\n* Another item\r\n* Yet another item\r\n* And there\'s more...\r\n\r\n
Unordered list
An item
Another item
And there\'s more...
https://docs.botframework.com/en-us/core-concepts/channeldata
example attachment https://api.slack.com/docs/message-attachments
you have to change source and twist attachment in below code.
I am able to deal with rich document in slack
refer this slack example with rich content with Microsoft bot framework
enter code here
bot.dialog('/', function (session) {
session.send('Looking into your upcoming flights to see if you check-in on any of those...');
var card = {
slack: {
"attachments": [
{
"fallback": "Required plain-text summary of the attachment.",
"color": "#36a64f",
"pretext": "Optional text that appears above the attachment block",
"author_name": "Bobby Tables",
"author_link": "http://flickr.com/bobby/",
"author_icon": "http://flickr.com/icons/bobby.jpg",
"title": "Slack API Documentation",
"title_link": "https://api.slack.com/",
"text": "Optional text that appears within the attachment",
"fields": [
{
"title": "Priority",
"value": "High",
"short": false
}
],
"image_url": "http://my-website.com/path/to/image.jpg",
"thumb_url": "http://example.com/path/to/thumb.png",
"footer": "Slack API",
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
"ts": 123456789
}
]
}
}
var msg = new builder.Message(session).sourceEvent(card);
session.send(msg);
});

Replace text in a Visual Studio Code Snippet Literal

Is it possible to replace text in a Visual Studio Snippet literal after the enter key is pressed and the snippet exits its edit mode?
For example, given a snippet like this:
public void $name$
{
$end$
}
If I were to enter $name$ as:
My function name
is it possible to have Visual Studio change it to:
My_function_name
or
MyFunctionName
After many years there is an answer, for anyone still coming across this question:
"Replace Whitespaces": {
"prefix": "wrap2",
"body": [
"${TM_SELECTED_TEXT/[' ']/_/gi}",
],
"description": "Replace all whitespaces of highlighted Text with underscores"
},
Add this to your user snippets. Or alternativly you can add a keyboard shortcut like this:
{
"key": "ctrl+shift+y",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "${TM_SELECTED_TEXT/[' ']/_/gi}"
}
},
Hope this helps anyone coming across this in the future
It's great. I used it to wrap things in a function with quotes. If a selection has quotes it can remove the quotes. In the snippet part, it seems to break down into:
TM_SELECTED_TEXT - this is the input
[ ' '] - regex find
_ - regex replace
gi - global flag for regex
So what I wanted is change: "User logged in" into: <%= gettext("User logged in") %>
For this in the snippet I used:
"body": ["<%= gettext(\"${TM_SELECTED_TEXT/['\"']//gi}\") %>"],
Note: you need to escape the quotein the regular expression, therefore: " becomes \".
In my case the goal was to replace a single instance of the word Authoring with Baker:
${TM_FILENAME_BASE/(Authoring)/Baker/}

Resources