How do you get the python colour scheme while using sage on VS code? - visual-studio-code

Currently, I name my files as .py while working on them, and then change them to .sage when I need to execute. Is there a way to get the python colour scheme for sage files on VS code?
There is an extension called SAGE enterprise management that claims to do it, but the instructions are a bit unclear:
It says:
Create a x3-code named folder inside your ~/.vscode/extensions/;
Copy all files in yours recent created folder;
Reload VS Code and enjoy;
I tried both copying my sage files into the folder, and the contents of the x3-extension into the folder, both of which didn't work.

The instructions referred to in the question are for Sage the
accounting software, not for SageMath the Sage mathematics
software system.
In the case of SageMath, we need to tell VS Code to apply Python
formatting not only to files ending in .py, but also to files
ending in .sage. One way to do that is to use the "file to
language association" setting:
https://code.visualstudio.com/updates/vMarch#_file-to-language-association
One would add associations from "*.sage" to "python".
This related question has answers explaining where Visual
Studio Code's language extension files are located on macOS
and Windows:
Stack Overflow question 42498117

Following the first link provided in the prior answer, I got it worked. In details,
go to Settings, type "files.associations" in the search box for Search settings.
It shows you a list of (item, value) in which you can add a new item (*.sage, python). See my screenshot below
Hope it works for you!

Related

Visual Studio Code Grammar files location

I'm using Visual Studio Code for development of PHP and would like to style the background color of the different embedded languages HTML/PHP/JavaScript differently, and to trigger the use of heredoc <<<sql .... sql to switch to SQL syntax. From what I can see from VSCode documentation, I need to edit the grammar files stored in storage.json, but for the life of me I cannot find where those files are. Can anyone point me in the right direction?
Sumirizing our comments, in order to modify the extension files, try to access the following folder:
./yourVSCodeFolder/extensions/resources/app/extensions
As you said, for those in windows, that folder is in:
%LocalAppData%\Programs\Microsoft VS Code\resources\app\extensions\php
There you will find a lot of folders that contains JSON files with the instructions of the custom formats and snippets that your editor uses.
For example: in mine, the /syntax/php.tmLanguage.json has all the instructions for how my php should look, and php/language-configuration.json has some parsing rules.
Find the files that allready has the rules that you are looking for, but it could be tricky because maybe you will need a prettyfier and to link or create new rules.
Also, if you didn't, check the Language Extensions Guide that VSCode provides.
Hope it was useful.
PD: As you also said:
VSCode already recognizes embedded SQL as long as the heredoc is in upper case <<<SQL .... SQL

Fuzzy file opening in vscode

I am exploring vscode after using atom for a long while. One of the things I'm missing is an equivalent of the lovely package advanced-open-file. Is there something similar to this in vscode?
I found the advanced-new-file extension, but it is only helpful when it comes to new files. I would like to be able to quickly open files from all over my local files (not only the workspace).
Edit: I found the option of workbench.action.quickOpen; but it doesn't allow opening files from the whole file system.
Sorry, but currently the answer is no. The problem is that input box doesn't provide a way to listen to key events:
GitHub issue,
so even the extensions can't do that currently. Here's the comment from advanced-new-file extension creator:
Because VSCode extensions don't yet have the ability to do type-ahead autocomplete within the text input box (See https://github.com/Microsoft/vscode/issues/426), we work around this limitation and provide autocomplete using a two-step workflow of selecting existing path, then providing new filename/path relative to the selection.
The good news is that there is a new API addressing this issue, but it's currently in 'proposed' state and can't be used for published extensions.
One workaround could be typing code -r some/path in integrated terminal and using 'tab' for autocomplete.
The Fuzzy search extension seems to work for me.
It adds a new action to the command palette which allows you to search for files in the current project and open them.

How to edit existing VS Code Snippets

Is there a way to remove or edit some of the default code snippets in Visual Studio CODE ?
For example when i type req+TAB i need require not requestAnimationFrame
The extensions snippets can be found inside each snippet directory below:
(if there are snippets in the extension)
Mac/Linux: $HOME/.vscode/extensions/
Windows: %USERPROFILE%\.vscode\extensions/
Select the extension you want to modify and then dive into the javascript.json file in snippets/ directory in there, and change whatever you like.
Just remember that if/when you choose to download and update the extension someday, all your personal modifications will get overwritten/replaced out with the updated version of the file.
(unless of course you squirrel away your changes outside of the extension's directory...)
Edit/Aside:
Looking closely at all the copied editions already present in this directory, it appears that at least some of the extension updates keep the former version around. If this is the case, when you update an extension when a new version is released, you wouldn't need to worry about storing a copy of your modified file somewhere else; returning a file to active duty might just be as easy as a copy-paste from the old into the appropriate, newer, higher numbered directory.
Resources/citations/acknowledgements:
Thanks to here for helping initially pointing me towards the relevant directory.
The suggestion item requestAnimationFrame is coming from the JavaScript language service. It's not coming from the snippets.
However, you can define your own snippets and tell Visual Studio Code to show the snippets first. How to do it:
Go to File -> Preferences -> User Snippets and select JavaScript in order to edit snippets for that language
Add this entry to the opened file javascript.json and save it
"require": {
"prefix": "req",
"body": [
"require"
],
"description": "Add 'require'"
}
Add the following line to your preferred settings.json (user or workspace settings) and save it
"editor.snippetSuggestions": "top"
Now you get your self defined require suggestion in first place as soon as you type req in a .js file.
On my Windows10 machine the log and other default javascript snippets can be found in :
C:\Users\$USER\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\javascript\snippets\javascript.json
On my Windows installation the default/built-in JavaScript snippets are located in
C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\javascript\snippets\javascript.json
I renamed that snippet to "logx" (requires admin privileges to modify the file) and restarted vsCode and now have just my user "log" snippet.
There are some threads about this on the issue tracker -
https://github.com/Microsoft/vscode/issues/10565
https://github.com/Microsoft/vscode/issues/48315
Attention everyone!
This is now possible in the latest vscode. Solution here: https://github.com/microsoft/vscode/issues/10565#issuecomment-721832613
That solution tells you how to disable any snippet (including built-in or extension snippets). While this is technically not editing the snippet, disabling the snippet and then creating your own user snippet accomplishes the same exact goal. Yay!
I found mine at ~/.config/Code/User/snippets
If you want to create a global snippet, create a file named snippet_name.code-snippets
If you want a language specific snippet, create it like php.json
Hiding default VSCode snippets is easy:
you can hide specific snippets from showing in IntelliSense (completion list) by selecting the Hide from IntelliSense button to the right of snippet items in the Insert Snippet command dropdown.
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_can-i-remove-snippets-from-intellisense

Visual Studio Code Does Not Format .cs files

couple of weeks ago I installed Visual Studio Code on my Windows machine. It is lightweight and I love it. But there is one problem that drives me crazy. The program cannot format .cs files. If I open .Net Core project, there is no problem on formatting. I changed the language from bottom right to C# and saved the file locally still no success. Is there any way to format code in single .cs file? I know there is already an asked question here for this problem but the solutions does not apply if there is no project created.
Use the command pallet (crtl-shift-P), type "format" and select "format code". Assuming the extension for the current language supports that.
TypeScript does, but C# does not.
You could raise an issue (if one does not already exist).

How to Change Netbeans Fonts and Colors Preview Document?

Within the Netbeans 6.5's Tools -> Options -> Fonts & Colors -> Syntax dialog, you have the ability to change the look and feel of the Netbeans text editor. When you select a language, you are presented with a preview of your font/color scheme. However, when I preview Java, there are far more options for syntax changes than are being displayed in that preview window. If I were able to view a more robust piece of code, I'd be able to see the immediate effect of more of the options.
How can I supply a preview document to view my font/color changes?
UPDATE:
After looking into this some more, I've been able to narrow down the problem a bit. From what I can tell, everything in Netbeans is considered a plugin. The GUI editor is a plugin, and even the text editor is a plugin. This means that what ever piece of Netbeans that actually analyzes Java code and does syntax highlights is also a plugin (since Java is just one of many languages Netbeans highlights, it makes sense this is a plugin).
I think fromvega is on the right track with his suggestion. The tutorial for creating a manifest file editing plugin pointed me in the right direction. The tutorial eludes to a file used as a sample document used for font/color previews. It tells you how to create one inside this new plugin project. (Located in "Registering the Options in the NetBeans System Filesystem", part 4. About 4/5 of the way down the page.)
My next line of thought was to look for the Java syntax editing mode plugin and find this file and update it with a richer example file. I looked in the installation directory and came up empty, but I found what looks like the appropriate files within my user settings directory. There is a config directory with a lot of subfolders within my user directory (Windows: C:\Documents and Settings\saterus.netbeans\config).
I've been poking around inside this directory a bit, but have only found the xml files the manifest tutorial talks about. I have been unable to find the extensionless sample file for the Java plugin that I believe should be there.
Since I've hit a brick wall for the moment, I thought I'd toss it back to the SO community and see if you guys might make the last leap and find the solution.
Just for anyone who wants to alter this themselves it is possible on a unix machine to use grep to locate the file i.e.
grep -lr "some part of the current sample code" /path/to/netbeans
I used this method to locate the ruby example filename and from that identified that it is kept in org-netbeans-modules-ruby.jar as a file called RubyExample. By simply altering that file I was able to construct a better sample file for my own use.
Hope this helps someone!
The document which is displayed (for each mime type) is specified in a particular folder in the "system file system" (which is a NetBeans concept which is a virtual file system composed from contributions from individual modules; this is how functionality is dynamically registered in NetBeans).
Modules typically specify their system file system contributions in a file named "layer.xml" in the plugin. The create plugin templates typically offer to create this for you.
For example, here's how the Python example is registered:
<filesystem>
...
<folder name="OptionsDialog">
<folder name="PreviewExamples">
<folder name="text">
<file name="x-python" url="PythonExample.py"/>
</folder>
</folder>
...
Here, PythonExample.py is a sample file in the same directory as the layer file.
Therefore, what you need to do is create a plugin which overrides the existing registration(s) for the mime type(s) you care about and provide alternate sample documents. You may need to hide the existing registration first (see the _hidden
part from http://doc.javanb.com/netbeans-api-javadoc-5-0-0/org-openide-filesystems/org/openide/filesystems/MultiFileSystem.html ).
Hopefully this guides you in the right direction.
However, in thinking about it, we probably ought to make the preview area editable - so people can cut & paste whatever codefragment they care about right in there. This wouldn't be persistent, so whenever you change languages you get the original samples back - but it provides a quick way to see your own code. This shouldn't be just for the Fonts & Colors customization, but for the Formatting preview panels as well.
I've filed an issue against NetBeans for this:
http://www.netbeans.org/issues/show_bug.cgi?id=155964
-- Tor
I think you can only accomplish that with a new plugin, since you need somekind of parsing to define what is what.
Give a look a these tutorials, I haven't read them in details but they seem to show you how to do what you want:
http://platform.netbeans.org/tutorials/nbm-mfsyntax.html
http://www.antonioshome.net/kitchen/netbeans/nbms-coloring.php