Reindex a source code in the VSCode - visual-studio-code

I've started to get errors Unable to open 'header.h': File not found when I try to jump to var/func definition via [Ctrl+Click] after I've deleted/renamed several files.
Is it possible to force reindex source code?

This question is a few years old now, but this is an issue I've seen a lot, and can usually be fixed with one of the following 5 options:
Reload Session
You can reload the current session, with the workbench.action.reloadWindow command:
Open the Command Palette with Ctrl + Shift + P Then type Reload Window
Filter Files being Indexed
For C/C++ projects specificially, sometimes the intellisense indexing can be really slow, and feel like it's not working. One solution for this is to limit what it indexes with something like limitSymbolsToIncludedHeaders, or reduce the amount of parsed files in c_cpp_properties.json
"browse": {
"path": [
"/usr/include/",
"/usr/local/include/",
"${workspaceRoot}/../include",
"${workspaceRoot}/dir2",
"${workspaceRoot}/dir3/src/c++"
...
]
}
Set File Associations
Sometimes the file associations are incorrect, so files are not indexed as expected.
This can be fixed by adding something similar to this into your VS Code settings (settings.json):
"intelephense.files.associations": ["*.php", "*.phtml", "*.inc", "*.module", "*.install", "*.theme", ".engine", ".profile", ".info", ".test"]
Rebuild System Index
For Windows users, VS Code uses the system search index, so rebuilding that may help.
Ensure Intellisense Enabled
Finally, it may seem obvious, but just confirm that Intellisense is actually enabled, with editor.tabCompletion in your settings.json. And if you're searching with results not displaying, ensure there aren't any filters preventing results.

Related

How to get a list of all files matching search criteria in VSCode?

As per the answers in this question, there are two primary ways to search for files in VSCode:
By using CTRL/CMD + P/E to search and "go to file"
By clicking anywhere in the explorer tree and typing
Why do the above solutions not suit my needs?
I need a way to search for files and get a full list of them (in plain view) so I can easily scan them.
The 1st method returns only partial results unless I scroll down.
The 2nd method only searches the folder tree that's currently open.
I know I can use the find command in Linux to achieve this, but can I achieve something similar in the editor itself?

Prevent deleting dead code during Auto Format on Save?

What is the magic configuration for allowing a file to be auto-formatted upon a Save operation, but stop / disable / prevent VSCode from deleting dead code?
Sometimes I want to deliberately throw an exception in the middle of a function, for debugging purposes but am forced to comment out all following code in order not to get it deleted.
What's worse is that sometime I save while the editor didn't yet recover from some error in the code, thinks the code still contains an error, and causes code deletions which should not happen in the first place. I found myself too many times pulling up git in order to restore good code which was wrongly deleted.
Is there a clear "do not delete dead code" option to switch on?
UPDATE:
Running Prettier (the file's formatter) from command line did not delete dead code.
Trying to disable all extensions didn't help either. The dead code is still deleted upon save.
Case solved.
I can't pinpoint the exact package that's causing it but it seems to be related to either ESLint or Prettier.
Turns out that the project's Github repo contains a .vscode directory with a settings.json that contains the following configuration:
{
"editor.codeActionsOnSave": {
"source.fixAll": true
}
}
I already saw posts saying to add "source.fixAll": false to VSCode's general settings.json file, but it had no effect when I did.
Setting the flag to false did the trick
{
"editor.codeActionsOnSave": {
"source.fixAll": false
}
}
Note: Adding the above block to the general settings.json had no effect as well. I had to modify the local .vscode/settings.json file to get it to work.
source.fixAll activates also TS fixes, which are somehow too aggressive to use on save. Only enabling eslint fixes with source.fixAll.eslint is a good compromise - it will still report dead code (no-unreachable) but not delete it.
https://github.com/microsoft/vscode/issues/109530

How to sort searched files in visual studio code?

When we are searching using ctrl + shift + f command in visual studio code for entire project , we are getting multiple files listing in which search values found.
Is there any way so that I can sort those search files because visual studio code not showing sorted search files.
I have gone through official website but not able to find such command.
I have checked to find similiar option to sort files as you are asking in visual studio code but not able to find any but you can see that visual code already sorting those file based on folder like account,base etc...
You can try regex to search to minify your serach criteria like a*.html, bo*.html,
[abc]*.html.
Hope above help you to sort out your problem.
You can (now?) sort results by updating user settings. Settings > Search "sort order". You'll see a few options:
Search: Sort Order - Sorting search results
Explorer: Sort Order - Sorting files in the file explorer

Why is my node_modules folder greyed out after command 'npm install'?

I wonder why my node_modules folder is greyed out in my VS Code editor after I run the command npm install.
Here the picture of my folder:
Files/folders that are included in .gitignore are greyed out. Normally node_modules folder is included within .gitignore.
It's because your node_modules folder is referenced in your .gitignore file.
Visual Studio tells you that this folder is ignored by the version control by graying it out.
As was already pointed out, VSCode automatically ignores everything in .gitignore. However, it also explicitely ignores some folders by default. All of this can be configured. Here are the steps you might want to take:
Check out the official documentation on Workspace settings
Open the relevant settings (you can choose between User (global) and Workspace). I usually do this via CTRL (or Command on Mac) + SHIFT + P -> > settings, which will show you the relevant choices: . For each you can either choose the UI or the JSON variant.
Also make sure to check the default settings via Peferences: Open Default Settings (JSON). You will find that, as of now (May 2021), **/node_modules is also automatically excluded, independent of other ignore files. Currently the default settings look like this:
// Configure glob patterns for excluding files and folders in fulltext searches and quick open. Inherits all glob patterns from the `files.exclude` setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options).
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true
},
// Controls whether to use global `.gitignore` and `.ignore` files when searching for files.
"search.useGlobalIgnoreFiles": false,
// Controls whether to use `.gitignore` and `.ignore` files when searching for files.
"search.useIgnoreFiles": true,
Enabling searching node_modules
"search.exclude": {
"**/node_modules": false
},
"search.useIgnoreFiles": false
WARNING: This will slow down things a lot since node_modules takes forever to search through - at least during cold start, that is when things are not cached. (Note that it is difficult to estimate how their caching works since it keeps evolving over time.)
To mitigate this, you might want to add some additional search.exclude settings. Note you will have to explicitely list everything you don't want, because...
The big shortcoming of VSCode search
search.exclude does not support:
negative look-ahead/behind
mutually cascading queries
Things like this will not work!
// does NOT work! :((
"search.exclude": {
"**/node_modules/#types": false,
"**/node_modules": true
}
This is a MAJOR problem which has been heavily discussed in the almost famous issue #869 for 6 years already! Join in and add to the 100+ comments! :)
Update: As of 2021/8/14, the issue has been taken off the backlog queue and put in the On Deck queue (but that also might not mean much).

Sublime Text 3: Auto-Complete uses incorrect syntax for for loop

With sublime text 3, the autocomplete when typing "for" and hitting tab gives you:
for x in xrange(1,10):
pass
However, this is not a valid statement for python 3. I've tried creating a new build system using the following:
{
"cmd": ["c:/Python37/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
the auto-complete for for still gives the wrong syntax. any advice?
The short version is that the sublime-build and sublime-snippet files that ship with Sublime in support of Python target Python version 2 and not Python version 3. I don't know if that's just due to that being what was used initially or if it's being done on purpose, though.
In Sublime, resources are generally related to a particular language based on the scope provided by the syntax definition. So for example snippets for Python are associated with source.python, your example build file uses that scope to know that it applies to Python files, and so on. As such, no matter what build you happen to be using, that has no effect on the snippets that are being offered.
By way of example, if you use the View Package File command from the command palette and enter the text python for snippet, the list of package resources will filter to Python/Snippets/for.sublime-snippet; pressing Enter to view that resource shows this:
<snippet>
<tabTrigger>for</tabTrigger>
<scope>source.python</scope>
<description>For Loop</description>
<content><![CDATA[
for ${1:x} in ${2:xrange(1,10)}:
${0:pass}
]]></content>
</snippet>
Here the tabTrigger specifies how the snippet inserts, scope controls where it inserts and content controls what it is inserts. Thus, in order to change it to support Python 3, you need to either create your own snippet or modify the existing one.
An issue with creating your own snippet is that it will be added to the list of snippets including the offending one, which allows it to possibly still trigger when you don't expect it to. There is also no general purposes "easy" way to disable individual snippets.
As such, generally the best course of action would be to use the PackageResourceViewer package. Install it, select PackageResourceViewer: Open Resource from the command palette, then select the same file as outlined above and modify the content of the snippet (e.g. replace xrange with range) and save the file.
That will get Sublime to replace the existing snippet with your edited version, so that it takes the place of the existing one and works the way you want.