Is there any way in vscode to know where the current the file has been imported? - visual-studio-code

Are there any extensions/features in vs-code which could let me know where the current file is imported? I usually do a global search of the filename but it is time consuming when the file name is similar to any variable or there are similar named files.

You can do a right-click on every function / variable or class. Then you choose "Find all references" to show where each function / variable or class is called.
For this you do not need an extension, because it is a standard feature of vscode

- find unused exports in project:
you can use this extension in vscode to find all unused exports
+ find name references (e.g. used exports) in project:
click on name then press shift+alt+F12

NO EXTENSION REQUIRED
Yes, We can find the references of a file in VSCODE like this:
Right-click on the file and then select Find References.
VSCODE will show all the references/imports of the file.
image reference

Right-click > Go to References (Shift + F12)
There is also an extension to change the appearance of how references show https://marketplace.visualstudio.com/items?itemName=jrieken.references-plusplus

If you are limiting your search to the current open workspace / folder, you can
do a search for 'import' using the magnifying glass or pressing ctrl+shift+s
open the results in editor by either clicking the link that says 'Open in editor' or by pressing alt+enter
In the document that opens, search for the name of your module.
In this way you will discover all of the imports that involve your module, regardless of whether you have used 'import mymodule' or 'from mymodule import myfunction' or anything else. I'm specifically thinking of how I'd structure a python project, but if you are using another language, you can alter the search in a way that works for the way your language does imports.

Related

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.

Markdown file path complete in VSCode

Is there any path-autocompletion extension for Markdown in VSCode?
I tried Path Intellisense but this seems to be effective only when using (double) quotation.
I want to use autocompletion when insert images stored in local directory, e.g.:
![](./img/local-img-file.png)
Yes, you can make that happen by using this extension on VS Code.
Relative Path extension
Juste type ctrl (or cmd on mac) + shift + H and type your file name.
It should be built-in to vscode soon, hopefully v1.64.
New setting: markdown.suggest.paths.enabled default is true
from Commit: Add basic markdown link completions
Only normal links for now. Will add reference links later. Should
support the forms:
[](dir/file.md)
[](./dir/file.md)
[](/root-dir/file.md)
[](#header)
[](./dir/file.md#header)
The paths suggestions work similarly to path IntelliSense in CSS and
HTML files. Paths starting with / are resolved relative to the current
workspace, while paths staring with ./ or without any prefix are
resolved relative to the current file. Path suggestions are
automatically shown when you type / or can be manually invoked by
using kb(editor.action.triggerSuggest).
Path IntelliSense can also help you link to headers within the current
file or within another Markdown file. Start the path with # to see
completions for all the headers in the file (depending on your
settings, you may need to use kb(editor.action.triggerSuggest) to see
these)
-from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_64.md#markdown-path-intellisense
For anyone else stumbling upon this answer, the Markdown All in One extension is able to perform this sort of autocomplete.

Is it possible to set open resource (ctrl-shift-R) to search full path by default in Eclipse IDE?

When using editor like atom or sublime, when trying to open resource by hot key (e.g. ctrl-P in atom), the default behavior is to search in full path. For example, when I press ctrl-P and type controller/base_controller, I will see controller/base_controller.php in the search result.
However, in Eclipse, when I press ctrl-shift_R and type controller/base_controller I will get nothing. I will need to type base_controller (if the file name is not repeating much) or *controller/base_controller to have controller/base_controller.php in the search result.
When most OS prohibit using slash ('/') in file name, I would expect Eclipse should at least know it is a full path search when I input slash. Anyway, is there a way I can set the "open resource" search to be full path search by default in Eclipse IDE?
In Eclipse a full path starts with /.
So in your example, you have to type /controller/base_controller to match base_controller.php in the project controller.
Alternatively, you can select the project or folder and use the File Search (Ctrl+H) leaving the Containing text field empty, with a file pattern and choosing the selected project or folder as scope.

How to set default file type to be All Files(*.*) in VS Code?

Now my default file type of Visual Studio Code is Plain Text.
If I save a new file with name like a.in, it will save as a.in.txt. I have to change the dropdown to All Files.
I find the same problems in github: 1, 2. However, they seem not solve my problem.
This is not possible in the general case in VSCode.
The issue is that you cannot assign "no extension" to a language, and as per the links you mentioned, the All Files (*.*) option is disabled by upstream (electron).
Therefore, you will either have to remove the extension manually, OR you can create the file first (using the terminal, Explorer, an extension, etc.) and then open that existing file.
There is a way to change the default extension (but not to All Files)
Add the following line to your settings.json
"files.defaultLanguage": "<language>",
Replace <language> with the language of your choice.
Now, whenever you make a new a file, the default file language will be <language>.
A special value for <language> is ${activeEditorLanguage} which is the language of the file last opened (useful if, say, you copy a piece of code from one file to save as another).
Unfortunately, this does not fully answer the question, but provides a partial solution.

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: