I am trying to get a theme for Visual Studio Code working to what I want. Currently, I'm trying to use Obsidian working with C# rules, but I'm not sure which key word to use to override color customizations. VSCode does not seem to recognize interfaces as they're language specific.
"editor.tokenColorCustomizations": {
"functions" :{
"foreground": "#F1F2F3"
},
"interface": { //not valid
"foreground": "#B48C8C"
}
}
How can I get VSCode color customizations to recognize c# specific syntaxes?
editor.tokenColorCustomizations can use a number of values: comments, functions, keywords, numbers, strings, types and variables. If none of those work for you textMateRules is available as well. So you can do something like:
"editor.tokenColorCustomizations": {
"textMateRules": [{
"scope": "yourScopeHere",
"settings": {
"fontStyle": "italic",
"foreground": "#C69650"
}
}]
},
So you just have to figure out what scope you need for "interface".
For that, try CTRL-Shift-P and type scope: choose
Developer: Inspect Editor Tokens and Scopes
and for whichever keyword is selected, like interface you will get a listing of its textmate scope. That should be inserted as the scope value above. [In my experience, it is more accurate to open the "Inspect TM Scopes" panel and then click a couple of items and then the one, like interface, that you want - the scope panel will remain open.] You can copy from the scopes panel.
You may need only the main scope listed, but if need to narrow its scope you can include the others listed in a comma-separated list in the scopes: ..., ..., ...
Based on Davi's answer:
Edit "C:\Program Files\Microsoft VS Code\resources\app\extensions\csharp\syntaxes\csharp.tmLanguage.json":
Find:
{"name":"storage.type.cs","match":"#?[[:alpha:]][[:alnum:]]*"}
Replace with:
{"name":"storage.type.interface.cs","match":"#?[I][[:upper:]][[:alpha:]][[:alnum:]]"},{"name":"storage.type.cs","match":"#?[_[:alpha:]][_[:alnum:]]"}
Add to settings.json:
"editor.tokenColorCustomizations": {
"[Default Dark+]": { // remove scope to apply to all themes
"textMateRules": [
{
"scope": "entity.name.type.interface.cs",
"settings": {
"foreground": "#b8d7a3"
}
},
{
"scope": "storage.type.interface.cs",
"settings": {
"foreground": "#b8d7a3"
}
}
]
}
},
VSCode 1.63.2:
Ctrl + Shift + P > Open Settings (JSON)
Paste this:
"editor.tokenColorCustomizations": {
"[Default Dark+]": {
"textMateRules": [
{
"scope": "entity.name.type.interface",
"settings": {
"foreground": "#a4ddaf"
}
}
]
}
},
I believe it can be partially done by editing "Program Files\Microsoft VS Code\resources\app\extensions\csharp\syntaxes" by adding support for "storage.type.interface.cs" with a regular expression that matches the convention.
Something like [I]([A-Z][a-z][A-Za-z]*)
You could also exclude possible mismatches like
IISManager, IPhoneDevice
https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide
https://www.apeth.com/nonblog/stories/textmatebundle.html
good luck with that and please let me know if you got it done
Related
When searching files in OneDrive for Business, the path of the parentReference is empty. Is there any reason for this limitation?
Example in MS Graph explorer:
GET https://graph.microsoft.com/v1.0/me/drive/root/search(q='finance')?select=name,parentReference
snippet from result:
"value": [
{
"#odata.type": "#microsoft.graph.driveItem",
"name": "CR-227 Product Overview.pptx",
"parentReference": {
"driveId": "b!-RIj2DuyvEyV1T4NlOaMHk8XkS_I8MdFlUCq1BlcjgmhRfAj3-Z8RY2VpuvV_tpd",
"driveType": "business",
"id": "01BYE5RZ6TAJHXA5GMWZB2HDLD7SNEXFFU",
"path": "/path/to/folder" <--- THIS IS MISSING
}
},
I would be glad if the path is returned because I need it. Otherwise I need to add additional overhead to query for the parent's paths.
I am trying to use environment variables within task in my tasks.json file of a C# project in vscode.
In my launch.json file I have this code to parse a .env file:
"configurations": [
{
...
"envFile": "${workspaceFolder}/.env",
}
]
I then have in the tasks.json file this task:
{
"label": "login",
"command": "sh",
"type": "shell",
"args": [
"${workspaceFolder}/etc/login.sh",
"${env:USERNAME}",
"${env:PASSWORD}"
]
}
This seems to be the code that's implied from https://code.visualstudio.com/docs/editor/tasks, however (from testing by echoing in another task) I have found these last two args to be blank. After researching online I think I have found the reason, the configurations..env is used by the tasks themselves rather than being accessible by task.json that run and so can't be accessed.
How do I create (use) these env variables within the tasks.json?
Checkout https://code.visualstudio.com/docs/editor/tasks-appendix
/**
* The environment of the executed program or shell. If omitted
* the parent process' environment is used.
*/
env?: { [key: string]: string };
example
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "diagnostic",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/beam",
"env": {
"FOO": "baz",
}
},
"command": "printenv",
"problemMatcher": []
}
]
}
There is no way I am aware of to pull these from a file like with launch.json
I would open an issue on the vscode repo
I had the same problem.
I am using Windows.
I was able to fix it.
The issue for me was, in VSCode I had this setting set:
"terminal.integrated.automationShell.windows": "C:/Program Files/Git/bin/bash.exe"
And this was causing the env to not load properly.
I was able to access the windows settings, that you would set from that windows GUI env variable tool. But I could not access env variables set in my .bashrc.
I commented out that setting.
I also have the Terminal > Integrated > Default Profile: Windows
set to Git Bash.
With these changes, I was able to access env variables in my .bashrc file.
I have enabled the latest C# extension in my Visual Studio Code editor. Instead of formatting the code while saving or by applying the key combination Ctrl + K, Ctrl + F or Alt + Shift + F, I need to format the current line of code while hitting the Enter key. This feature is already available in Visual Studio, but not found in Visual Studio Code by default.
This is the sample code output I need to achieve:
I have found an option which makes it easier to format code while typing.
I applied the below settings in workspace settings:
{
"editor.formatOnSave": true,
"editor.formatOnType": true
}
This works fine for me.
Go to menu File → Preference → Settings.
Search for format
Select the options you would like:
Format on Paste
Format on Save
Format on Type
Close the Settings window.
You can also see it in your settings.json file:
Go to menu File → Preferences → Keyboard Shortcut (Ctrl + K, Ctrl + S)
Click on the keybindings.json link:
Enter the below binding for the Enter key. This binding will overwrite the defaults for current user.
{
"key": "enter",
"command": "editor.action.formatDocument",
"when": "editorHasSelection"
}
Another alternative solution is to use macros extension - a custom macros support for Visual Studio Code, so you will be able to do more than one command in one key binding.
Add macros to User Settings:
"macros": {
"formatWithEnter": [
"editor.action.insertLineAfter",
"editor.action.formatDocument"
]
}
And the below key binding to keybindings.json:
{
"key": "enter",
"command": "macros.formatWithEnter"
}
Code formatters available on Visual Studio default as
On Windows: Shift + Alt + F
On Mac: Shift + Option + F
If you again wish to do it when pressing Enter you need to set up your workspace preferences and then configure the key bindings:
{ "key": "enter", "command": "editor.action.format" }
It now formats the whole document if nothing is selected, and else it formats the selection.
Also there is the beautify.onSave, editor.formatOnSave option. Please try that too to make the code pretty.
Edit: This doesn't actually work because this will suppress the regular Enter key behavior
To get this to work for me I had to install two extensions
C# (powered by OmniSharp)
C# FixFormat
Without the second extension I was getting the error visual studio code there is no formatter for 'csharp'-files installed
I also made sure my Visual Studio Code was up to date (menu* → Help → Restart and Update or Check for Updates)
Then I added a custom key binding. menu File → Preferences → Keyboard Shortcuts → "For advanced customizations open and edit keybindings.json":
[{
"key": "enter",
"command": "editor.action.formatDocument",
"when": "editorTextFocus"
}
]
I had to type in the word enter because the dialog to capture keys doesn't acknowledge it.
I am creating a small window form application which will return list of videos based on query. I am using this link https://developers.google.com/youtube/v3/code_samples/dotnet Everything is working fine except for the issue that if embedding is disabled by owner of some video then I am getting an error while trying to play the video that:
"Watch this video on youtube. Playback on other websites has been disabled by the video onwer".
So now I have two questions
1) Is there any way to play that video?
2) IF anwser of the first question is no then how can I filter those videos whose embedding has been disabled by it's owner. Means I don't want to add those videos in my list.
Thanks.
According to official documentation every video has status.embeddable property, which you can check in your code.
The status.embedabble, regardless of language used, is a response anytime one of the methods used in Videos reference is successfully called.
So I would suggest using the method list for example. To demonstrate, I place a youtube video in this videos.list Try-it and place "status" as part parameter.
And true enough I get the embedabble status:
"items": [
{
"kind": "youtube#video",
"etag": "\"7991kDR-QPaa9r0pePmDjBEa2h8/7NFYOO88j54fU9aKM8MsjN4zPro\"",
"id": "kIBdpFJyFkc",
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
}
}
]
Thanks for all the answers. After exploring the documentation I finally found the solution to filter those videos whose embedding is disabled by the owner.
There is VideoEmbeddable property of YoutubeService.Search.List method which expects Google.Apis.YouTube.v3.SearchResource.ListRequest.VideoEmbeddableEnum can do the trick.
var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.Q = ""; // Replace with your search term.
searchListRequest.MaxResults = 50;
searchListRequest.Type = "video";
searchListRequest.VideoEmbeddable = SearchResource.ListRequest.VideoEmbeddableEnum.True__;
Specifying a type "video" only returns video insteal of all videos, playlists and channels.
All Visual Studios (2012 too) do not format the following:
_messageProcessor = new Dictionary<ServerDataTypes, MessageProcessor>()
{
{ServerDataTypes.FrameData, ProcessFrameData } ,
{ ServerDataTypes.ServerStatusResult,ProcessServerStatusResult },
{ ServerDataTypes.PlayerMessage, ProcessPlayerMessage},
....
};
How can I make my Visual Studio 2010 (or 2012) to auto-format that? I need the following result:
_messageProcessor = new Dictionary<ServerDataTypes, MessageProcessor>()
{
{ ServerDataTypes.FrameData, ProcessFrameData },
{ ServerDataTypes.ServerStatusResult, ProcessServerStatusResult },
{ ServerDataTypes.PlayerMessage, ProcessPlayerMessage },
...
};
It's like in the auto-properties for the newly created objects. The format is working for that. But not for this. So, how to fix it?
Short answer: you can't with VS out of the box. Resharper comes close, but it's reformatting doesn't quite do this style either. I've actually submitted a request for it do do this.
You might look for some other extension or perhaps develop a macro of some sort.