Intellisense for available 'using/import's in C# with Visual Studio Code
Asked Answered
S

3

32

Edit: Vidual Studio Code and Visual Studio are 2 different things. Yes it's confusing but I know that VS has this feature, I'm asking about VS code.

Is there some extension/setting that makes Visual Studio Code's c# have Intellisense for all available namespaces, including those that were not yet imported, and then imports them when selected?

Example: Collections are not yet imported and I want to type IEnumerable and import it. Being the average programmer this is quite tedious and I might screw up the spelling or capitalization, and then have to press ctrl+.. I would like to just be able to type "ienu" and then IEnumerable would pop up and would be autocompleted and auto imported.

This feature exists for Typescript in VScode (thanks to an extension), and even for C# but in Visual Studio with the Resharper extension.

I have searched everywhere for this feature but it seems to me like it doesn't exist. It honestly feels insane to code without this.

Stoller answered 28/12, 2018 at 20:42 Comment(2)
@Flydog57 thanks for the edit. Just don't re-use the F-word in your edit summary, this trips a lot of bots :)Hypozeuxis
reSharper does this perfectly for me - see this: imgur.com/a/JjtD9YV. Not sure why it doesn't for youGleaning
C
68

If you use "C# extension" for VSCode (this https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp)

you can try follow next steps:

  1. Right click on C# extension
  2. "Extension settings"
  3. In opened "Settings" tab, add import in search area
  4. Enable Checkbox
  5. Enjoy autoimport without "special" extension ([Screenshot][2])
Christiniachristis answered 23/11, 2020 at 0:16 Comment(6)
Thanks! This is what I needed. I don't understand why this isn't enabled by defaultDigitate
The setting ID is called omnisharp.enableImportCompletionAllegorist
Seems ridiculous that this is default-off.Cuprous
Seems like the reason for default behavior being off is due to possible? degraded performance during initialization.Juliannjulianna
Man, you are literally life-saver, couldn't find this specific setting for ages, after starting Unity development. Thanks!Patricide
@Christiniachristis I can't find this option in extension settings. Is it available in latest version of extension?Lymphocytosis
S
7

I just went ahead and made the extension:
https://marketplace.visualstudio.com/items?itemName=Fudge.auto-using#overview
Currently it supports only the base C# libraries but I can make it use additional nugget libraries as well if there is demand for that. As of 24/11/2020 the official C# extension supports this feature, see other answer.

Stoller answered 1/1, 2019 at 5:21 Comment(2)
Would be nice to have it!Riviera
but this does not show suggest from nugget packagesMicrowatt
H
-7

There are some sort of solution for your problem that might help if you write the complete key word and don't want to write the using system or any library you can just put cursor on your key word and press alt+enter it will automatically add the library .but if you are not using library and want to auto complete key word of that library it's possible with re-sharper. you can also use Ctrl+space if your visual studio is not giving you auto recommendation

Herriott answered 28/12, 2018 at 21:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.