How do I see all current file associations? - visual-studio-code

VS Code is aware of many file types, but I cannot find any information on where to see all file types it currently understands.
I want to see which file type is associated with which language.
If I view the file associations it's totally blank:
I want to add a new association. I want to associate *.inc as a restructured text file. But figuring this out is a guess right now, what is the "code" for the restructured text language?
Is it rst:
Or is it "restructured text"? Or another value. My VS Code currently associates *.rst files with restructured text, but I cannot see that configuration anywhere.

The easiest way I've found for a global association is simply to Ctrl + k m (or Ctrl +Shift + P and type "change language mode")` with a file of the type you're associating open.
In the first selections will be the option "Configure File Association for 'x' " (whatever file type - see image attached). Selecting this gives you the option to choose the language and will then make the filetype association permanent.
screenshot
This may have changed (probably did) since the original question and accepted answer (and I don't know when it changed) but it's so much easier than the manual editing steps in the accepted and some of the other answers, and totally avoids having to muss with IDs that may not be obvious.
Answer 2
In VScode, you can add persistent file associations for language highlighting to your settings.json file like this:
// Place your settings in this file to overwrite the default settings
{
"some_setting": custom_value,
...
"files.associations": {
"*.thor": "ruby",
"*.jsx": "javascript",
"Jenkinsfile*": "groovy"
}
}
You can use Ctrl+Shift+P (or View -> Command Palette from the menu) and then type settings JSON. Choose Preferences: Open Settings (JSON) to open your settings.json.
To find the proper language ID, use Ctrl + Shift + P (or View -> Command Palette from the menu) and then type Change Language Mode. You can see the language ID in the list, e.g. type docker to find the language ID for Docker files (dockerfile). In the first entry in the example above, .thor is the file ending, ruby is the language ID.

Related

VsCode: Is there a keyboard shortcut How to make VS Code treat files without extension as a certain language?

Is there a keyboard shortcut How to make VS Code treat/reopen/reload files without extension as a certain language?
Just to be clear, here's my use case:
Sometimes I have a big JSON I need to read so I copy it in VsCode new file but since it's a new file I have to save it a s JSON extension to read it in the correct format. So my question is: Is there a way to specify the language for this new file(without extension) to open it as JSON for example?
Thank you
I found these two options:
// The following example associates all files in a folder `somefolder` to PHP:
"files.associations": {
"**/somefolder/*.*": "php"
}
https://code.visualstudio.com/docs/languages/overview#_can-i-map-additional-file-extensions-to-a-language
// The default language mode that is assigned to new files.
"files.defaultLanguage": "html"
https://code.visualstudio.com/docs/languages/overview#_how-do-i-set-the-default-language-for-new-files
Add the lines of your choice to settings.json.
Nevermind guys I found it:
The feature is called Change Language Mode.
The default shortcut is Ctrl+K M if you want to customize it here's the name of the command:
workbench.action.editor.changeLanguageMode
You can also click in the lower right of VSCODE window to change the language mode:

VSCode search/go to definitions

I searched in vscode site but I couldn't find information on the following:
Is there any way to search definition in other files.
For example:
In sublime text I can open command pallette (ctrl+p) and write 'User.php#delete' - this will find the method and if i click enter I will go the the specific file and in the line where method 'delete' is.
Does the functionality exist in VSCode (or with extension).
Thanks
There are multiple options to search function/definition.
According to your convenience, you can choose one of the below options :
Best shortcut: Ctrl+Shift+O and type your function name.
Press Ctrl+P for "quick open", then you can use # or #: The latter is handy to see all the symbols in the file grouped by classes, constants, fields, methods
Press Ctrl+T to searches across files, not just the current file.
Hover the method and press crtl. The method will be underlined and show a tooltip with definition. Mouse left click = go to definition.
yes, in command palete enter # symbol (without preceding >) end method name.

Change title of untitled tab in Visual Studio Code

I'm building a VS Code extension which includes changing the name/title of untitled-1 tab (unsaved file).
I tried running the below code in debugger console of extension but it didn't reflect in the editor:
vscode.workspace.textDocuments[0].fileName="myFile"
Is it not possible or am I missing something?
It is still (Q1 2020) not possible, but the next VSCode 1.42 will name its Untitled editors differently.
Untitled editors in VS Code are text buffers that have not yet been saved to disk.
You can leave them open for as long as you like and all text content is stored and restored between restarts.
Untitled editors were given generic names such as Untitled-1 and counting upwards.
In this release, untitled editors will use the content of the first line of the document for the editor title, and include the generic name as part of the description:
Note: If the first line is empty or does not contain any words, the title will fall back to Untitled_* as before.
So while you cannot set the title yourself (still readonly fileName), technically... changing the first line of that file would be enough to change the title of said "Untitled" editor.
With VSCode 1.43 (Q1 2020), a new setting workbench.editor.untitled.labelFormat allows to control whether untitled editors should use the contents as title or not.
Possible values are content or name.
Configure 'workbench.editor.untitled.labelFormat': 'name' to get the previous behavior back where untitled editors would have a short title, such as Untitled-1.
It's not possible - if you check out the source code for the API definition in vscode.d.ts, you'll see that fileName is declared as readonly:
export interface TextDocument {
// ...
readonly fileName: string;
// ...
}
Unfortunately, it seems that the readonly attribute isn't reflected in the API docs on the website.
This mainly happens if we create a new file in the OPEN EDITORS section, thus they appear as unsaved. To prevent this, create a folder for storing your files, and then in that folder, create your new file then it will show options to name it, also you can add a file type extension like .cpp.
TIP: vsc-rename-files extension to rename your files.

Sublime text 2 - find file by class name in Zend Framework

When you press Ctrl+p Sublime will open popup when you can easily find the file. Sublime auto detect the file location in both situation when you press / or space between file path parts.
In Zend Framework all classes has name within follow template: Namespace_Module_Other_Part_Of_Class_Location, how can I make Sublime understand the _ as a path separator when I press Ctrl+p and copy past the class name there?
So the above class should be recognized on location: Project/Namespace/Module/Other/Part/Of/Class/Location.php
I'm still looking for the solution of it. Even if the file search is hard-coded in Sublime 3, and you have a workaround to make it works, maybe to write some plugin? you are welcome.
Thank you.
You can do this with a simple plugin and key binding. Select Tools -> New Plugin... and replace the contents with the following:
import sublime
import sublime_plugin
class UnderscoreToSpaceCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command('copy')
clipboard = sublime.get_clipboard()
clipboard = clipboard.replace('_', ' ')
sublime.set_clipboard(clipboard)
Save the file as Packages/User/underscore_to_space.py where Packages is the folder opened when clicking on Preferences -> Browse Packages....
Next, create a custom key binding for the command. Select Preferences -> Key Bindings-User and add the following:
{ "keys": ["ctrl+shift+c"], "command": "underscore_to_space" }
If the file is empty when you open it, surround the above line with square brackets [ ]. Save the file (it will automatically save to the correct location), and you're all set.
Now, all you need to do is select the text you want to convert, and hit CtrlShiftC. This will copy the text to the clipboard, replace the underscores with spaces, and put the modified text back in the clipboard. You can now hit CtrlP to open Goto Anything... and paste in the modified text with CtrlV.
If you prefer to have the underscores replaces with forward slashes /, just change the clipboard.replace() arguments from ('_', ' ') to ('_', '/').
To get to the class definition you are looking for there exist several plugins doing "code intelligence". The plugins are language specific.
The most popular is SublimeCodeIntel which provides Jump to symbol definition functionality. SublimeCodeIntel claims to do this for PHP too. However, who to setup this for your project should be another question.
Some more options for possible source code static analysis in Sublime Text 2 in this blog post:

How to remove the lock in file association in eclipse

IN Eclipse i want to chnage the default editor of some .htm files.
If i try to go to FIle Association and assiciate the default editor then file gets opened in that new editor but i don't get the syntax highlighting.
The solution is that the file association is locked ny some plugin editor
Preferences -- Context type----text ----Your editor -- reomve the extension
But i get the .htm(locked) so i cant remove it.
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-content-type.htm
Note: Certain items will be marked as "locked". An item is locked if
it is one of the associations provided by the plug-in that declares
the content type. In other words, you can remove only user-contributed
associations.
Is there any way to remove those locks even thought it can be hackish way but i want to do it
You don't need to "unlock" an existing association to add a new association and make it the default.
Add a new association via the "Add" button
Select the new entry
Hit the "Default" button to make your new entry the default editor
Could it be, that you want to change the "File Association"? This can be done in General / Editors / File Associations. BUT Eclipse uses at least one default-editor and this is the reason for the "locked"-message in the "Content Types". You could set the "Text Editor" to all unwanted types. Looks like a workaround, but makes sense, because it is the same as the file associations of your operating system, that asks you for the program to display the file.
Another question is, why do you want to unlock or remove the "Content Type"? Does it change anything in the Eclipse logic?
Go see this answer from "Greg Desmarais" (assign the desired editor to "default")
https://stackoverflow.com/a/15642583/162094