I am writing Visual Studio Extension Color code. My code is mix of 2 languages. Only one language is colored , so I want to color the second language and I don't know how. Is there something that allows me color code on the way I want.
I want something like this
code example
Which part of code provides me to color code?
You're looking to provide what's called a "classifier". Here's one example:
https://www.codeproject.com/Articles/1245021/Extending-Visual-Studio-to-Provide-a-Colorful-Lang
In general the interface to look for is "IClassifierProvider".
In case you are talking about Visual Studio Code:
You will have to create your own extension. To do so you can follow this guide right here. More specifically you should run this command:
npm install -g yo generator-code
And once the installation is over you run:
yo code
You should the choose New Language support and answer all the questions that will appear. Once it's done you can start defining your language. To do so you should go to the syntaxes directory and start editing the <plugin_name>.tmLanguage.json.
In this file you will normally find code examples. Here is the example of an existing Python extension.
If you pay attention there is sometimes a variable called name of this style "comment.line.number-sign.python". In order to find the possible values for this variable, I would suggest you to take a look here. The choice of this name will define the color of the matching value.
I hope this was helpful to you.
Related
In Eclipse, there is a view called "ABAP Element Info", which can show details about language elements such as functions, classes, etc. when they are clicked on. It will display details such as function/method signature, class/struct members, element documentation, etc. as you can see on the image below:
It is a great help for me and it's very quick to find out details of elements, but I cannot find anything like it in Visual Studio standard package (except Object Browser, but I does not show what I click on, I need to look it up). Is there any extension or something with similar functionality I could make use of? I'm using C++ desktop version if it helps. Thanks a lot for any input.
Instead of using Visual Studio, try to check if your project is fully supported and operational in Visual Studio Code.
In VSCode there are various plugins for ABAP development, including syntax highlighting which is your main concern.
Check out the following article on how to prepare your environment:
https://blogs.sap.com/2019/12/06/abap-development-in-vs-code/
I can't figure out what VS Code's editor.autoIndent setting does. I've tried copy+pasting unindented code with the settings turned on and off and the code is just pasted as it was copied - unindented.
Can someone please explain to me what this setting does and a clear use case?
Thanks!
I wasn't paying attention to the Extensions with indentation rules of the language must be available part of the editor.autoIndent description. I installed the Prettier extension, added it's identifier to "editor.defaultFormatter": "esbenp.prettier-vscode" and editor.autoIndent now works perfectly.
I've also created a video explaining it, which might help.
Many modules in vscode may provide some code formatting, depending on the language to format ...
And there is EditorConfig (https://EditorConfig.org) that should simplify this task, quickly, and once for all environments, as long it is largely supported by other IDE.
Any way, in order to format your code, you'll have to ask for this action, usinf either the F1 key + "format this document", or Ctrl+Maj+I
In Intellij Idea I can see documentation on intelliSense options:
Can I enable something like this in vs code for golang ?
Can I control the width and height of the two rectangles ?
Try installing the Go extension. Here's the source: https://github.com/Microsoft/vscode-go
It offers Intellisense/completion lists, though the completion lists feature is not working too well right now (I'm sure it will improve over time). The extension is able to get function signatures and documentation by mousing over their names once you've typed them in, even if they don't show up in Intellisense, however.
Be sure to read the extension documentation on how to get everything installed, as it makes use of a number of tools to offer all of its functionality.
When I write a test method, I type "testm", hit tab and magically see:
[TestMethod]
public void MethodName()
{
}
When I type the methodName it is highlighted (can't show that here) as a "field" that I'm filling in. I'm sure you're all familiar with this behavior.
Personally, I like names for my test methods like
Can_My_Method_Do_That_Thing instead of CanMyMethodDoThatThing. I find them much easier to read, and most times they're really a sentence anyway.
For reasons I'd rather not get into, I have a difficult time typing all those _ characters and I'd like to be able to use the space bar, and have the spaces in the name automatically replaced when I hit "Enter".
I hear that Visual Studio is extendable and customizable and so on. Is it extensible enough to do this?
You can implement and use your own code snippets and Microsoft provides a very nice guide on how this could be done: Walkthrough: Implementing Code Snippets
To have a quick look at how the "testm" Expansion (that's the Snippet Type) is "partially" implemented you may go to c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Test\ directory and edit the testmethod.snippet file.
I have never implemented this kind of "Expansion" myself, but Microsoft's Extending the Editor website is a really good source of info of how this can be achieved. This is where you should start lookin'.
If you install CodeRush Xpress then not only do you get some great free productivity and refactoring tools but there is also an open source community of plugins for CodeRush Xpress.
I found this plugin that does (almost) exactly what you want.
The caveat is that it is developed for NUnit and not MSTest so you will get a [Test] attribute instead of a [TestMethod] attribute. Since this is open source, it should be fairly easy to modify the code to your requirements.
The best method i would suggest is look into the Editor extensibility and work it out. Following steps is what you might need to do.
Map a key to your "underscorize" action.
Using the editor extensibility points, you can get access to the Selected text, process it.
And finally replace it.
One suggestion. Though the learning curve might be a bit high with having to go through MEF and stuff like that. But its worth it.
Another approach worth considering would be to use an external tool to remap the keyboard. For example, it should be straightforward to get AutoHotKey to react to the testm[Tab] sequence of keystrokes and switch into a mode where it maps spaces to underscores (or deletes each space as soon as it's typed and adds an underscore). Similarly, the Enter key could switch it out of that mode again.
I want code highlighting like visual studio.
If user is attaching a code snippept in the article i want to hightlight the code exactly like what visual studio will do.
How can we achieve this.
For example google-code-pretify. If you are not talking about code that is contained in a website but e.g. in a desktop application, you should clarify your question.
http://www.actiprosoftware.com/Products/DotNet/ASPNET/CodeHighlighter/default.aspx
Does this tool do what you want?
If you're in PHP you can also use FSHL: http://code.google.com/p/fshl/. Examples are included.