Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Namespace Imports no longer function #6051

Closed
fmoo opened this issue Aug 6, 2023 · 6 comments · Fixed by dotnet/roslyn#69454
Closed

Automatic Namespace Imports no longer function #6051

fmoo opened this issue Aug 6, 2023 · 6 comments · Fixed by dotnet/roslyn#69454
Assignees
Milestone

Comments

@fmoo
Copy link

fmoo commented Aug 6, 2023

Type: Bug

Issue Description

After updating to 2.0.328, code-completion's automatic insertion of using namespaces no longer functions correctly. While the new subsystem does autocomplete symbols from namespaces that haven't been imported yet, it no longer automatically adds the imports to the top of the file, as 1.x was able to do when the "Enable Import Completion" option was enabled.

Reverting back to the Omnisharp language server does not help either, as the "Enable Import Completion" option appears to have been removed.

Rolling back the extension to 1.26.0 and re-enabling "Omnisharp: Enable Import completion" does resolve the issue.

Steps to Reproduce

  1. Install 2.0.328 and reload window
  2. Open a working C# project.
  3. Create a new .cs file with minimal imports.
  4. Open a typeahead to autocomplete a symbol from another namespace that has not been imported yet.
  5. Select the typeahead completion option for the symbol.

Expected Behavior

Selecting a typeahead suggestion that includes a namespace that has not yet been imported should automatically add the import to the top of the file.

If this is not a valid default behavior, then an option similar to "Enable Import completion" from 1.x should be reintroduced, perhaps named "Automatically add imports on symbol completion" or something.

Actual Behavior

Selecting a symbol from a namespace that has not yet been imported, simply inserts the symbol into the document, but does not up date the imports

Logs

C# log

Post the output from Output-->C# here

C# LSP Trace Logs

Post the output from Output-->C# LSP Trace Logs here. Requires `dotnet.server.trace` to be set to `Trace`

Environment information

VSCode version: 1.81.0
C# Extension: 2.0.328
Using OmniSharp: false

Dotnet Information

Host:
Version: 7.0.9
Architecture: x64
Commit: 8e9a17b221

.NET SDKs installed:
No SDKs were found.

.NET runtimes installed:
Microsoft.NETCore.App 7.0.9 [c:\Users\ruiba\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime.dotnet\7.0.9\shared\Microsoft.NETCore.App]

Other architectures found:
arm64 [C:\Program Files\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Visual Studio Code Extensions
Extension Author Version Folder Name
cmake twxs 0.0.17 twxs.cmake-0.0.17
cmake-tools ms-vscode 1.14.34 ms-vscode.cmake-tools-1.14.34
copilot GitHub 1.100.313 github.copilot-1.100.313
copilot-chat GitHub 0.7.2023072802 github.copilot-chat-0.7.2023072802
cpptools ms-vscode 1.16.3 ms-vscode.cpptools-1.16.3-win32-x64
cpptools-extension-pack ms-vscode 1.3.0 ms-vscode.cpptools-extension-pack-1.3.0
cpptools-themes ms-vscode 2.0.0 ms-vscode.cpptools-themes-2.0.0
csharp ms-dotnettools 2.0.328 ms-dotnettools.csharp-2.0.328-win32-x64
EditorConfig EditorConfig 0.16.4 editorconfig.editorconfig-0.16.4
godot-csharp-vscode neikeq 0.2.1 neikeq.godot-csharp-vscode-0.2.1
godot-tools geequlim 1.3.1 geequlim.godot-tools-1.3.1
hexeditor ms-vscode 1.9.12 ms-vscode.hexeditor-1.9.12
intellicode-api-usage-examples VisualStudioExptTeam 0.2.7 visualstudioexptteam.intellicode-api-usage-examples-0.2.7
java redhat 1.21.0 redhat.java-1.21.0-win32-x64
jupyter ms-toolsai 2023.7.1002162226 ms-toolsai.jupyter-2023.7.1002162226-win32-x64
jupyter-keymap ms-toolsai 1.1.2 ms-toolsai.jupyter-keymap-1.1.2
jupyter-renderers ms-toolsai 1.0.17 ms-toolsai.jupyter-renderers-1.0.17
mono-debug ms-vscode 0.16.3 ms-vscode.mono-debug-0.16.3
prettier-vscode esbenp 10.1.0 esbenp.prettier-vscode-10.1.0
python ms-python 2023.14.0 ms-python.python-2023.14.0
remote-explorer ms-vscode 0.4.1 ms-vscode.remote-explorer-0.4.1
remote-ssh ms-vscode-remote 0.102.0 ms-vscode-remote.remote-ssh-0.102.0
remote-ssh-edit ms-vscode-remote 0.86.0 ms-vscode-remote.remote-ssh-edit-0.86.0
remote-wsl ms-vscode-remote 0.81.0 ms-vscode-remote.remote-wsl-0.81.0
shaderlabformatter litefeel 0.4.3 litefeel.shaderlabformatter-0.4.3
unity-debug Unity 3.0.2 unity.unity-debug-3.0.2
vscode-antlr4 mike-lischke 2.3.1 mike-lischke.vscode-antlr4-2.3.1
vscode-dotnet-runtime ms-dotnettools 1.6.0 ms-dotnettools.vscode-dotnet-runtime-1.6.0
vscode-expo-tools expo 1.0.7 expo.vscode-expo-tools-1.0.7
vscode-java-debug vscjava 0.53.0 vscjava.vscode-java-debug-0.53.0
vscode-java-dependency vscjava 0.23.1 vscjava.vscode-java-dependency-0.23.1
vscode-java-pack vscjava 0.25.13 vscjava.vscode-java-pack-0.25.13
vscode-java-test vscjava 0.39.1 vscjava.vscode-java-test-0.39.1
vscode-jupyter-cell-tags ms-toolsai 0.1.8 ms-toolsai.vscode-jupyter-cell-tags-0.1.8
vscode-jupyter-slideshow ms-toolsai 0.1.5 ms-toolsai.vscode-jupyter-slideshow-0.1.5
vscode-maven vscjava 0.42.0 vscjava.vscode-maven-0.42.0
vscode-nuget-package-manager jmrog 1.1.6 jmrog.vscode-nuget-package-manager-1.1.6
vscode-pull-request-github GitHub 0.70.0 github.vscode-pull-request-github-0.70.0
vscode-pylance ms-python 2023.8.10 ms-python.vscode-pylance-2023.8.10
vscode-xml redhat 0.26.1 redhat.vscode-xml-0.26.1-win32-x64
vscodeintellicode VisualStudioExptTeam 1.2.30 visualstudioexptteam.vscodeintellicode-1.2.30
vsliveshare ms-vsliveshare 1.0.5877 ms-vsliveshare.vsliveshare-1.0.5877
vsliveshare-pack ms-vsliveshare 0.4.0 ms-vsliveshare.vsliveshare-pack-0.4.0
yarn-spinner SecretLab 2.2.122 secretlab.yarn-spinner-2.2.122

Extension version: 2.0.328
VS Code version: Code 1.81.0 (6445d93c81ebe42c4cbd7a60712e0b17d9463e97, 2023-08-02T12:37:13.485Z)
OS version: Windows_NT x64 10.0.22621
Modes:

System Info
Item Value
CPUs AMD Ryzen 9 5950X 16-Core Processor (32 x 3400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 63.92GB (19.17GB free)
Process Argv --crash-reporter-id 48886d93-cc35-481b-a03c-d2fceb1686e9
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263cf:30792227
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
vsccc:30803844
282f8724:30602487
89544117:30613380
2i9eh265:30646982
showlangstatbar:30737416
vsctsb:30748421
03d35959:30757346
ecj1e332:30736112
pythonfmttext:30731395
pythoncmvfstrcf:30756944
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
gsofb:30804716
pythonnosmt12:30797651
pythonidxptcf:30805731
pythonnoceb:30805159
e537b577:30795824
dsvsc013:30795093
dsvsc014:30804076

@fmoo fmoo changed the title "Enable Import Completion" No longer works correctly Import Completion no longer works fully Aug 6, 2023
@fmoo fmoo changed the title Import Completion no longer works fully Automatic Namespace Imports no longer function Aug 6, 2023
@TrieBr
Copy link

TrieBr commented Aug 6, 2023

This makes v2+ unusable for me. Reverting back to v1.26.0 also worked for me.

@ccastanedaucf
Copy link

Ran into this on both 2.0.x Release versions. Rolled back to Prelease v2.0.312 and imports are working again, so the bug must have just been introduced.

If I had to take a guess, might be related to this change: dotnet/roslyn#69265

@TrieBr
Copy link

TrieBr commented Aug 7, 2023

How do you switch back to prerelease 2.0.312? I agree, I've been on 2.x for a while but I don't recall imports being broken until recently so you're probably right but I don't have the option to switch to pre-release on the C# extension (Only the C# Dev Kit).

Edit:
I manually downloaded 2.0.312 and installed it and I can confirm it's working.

@ccastanedaucf
Copy link

It should be in Install another version, but while I was A/B testing the Prerelease versions disappeared (even though it let me roll back the first time). Got it to show up again after rolling back C# Dev Kit by a few weeks and reloading VSCode.

@arunchndr arunchndr added this to the August milestone Aug 7, 2023
@JustinGrote
Copy link

JustinGrote commented Aug 9, 2023

This setting does not work either even though it says it will
image

Video.mp4

As a (poor) workaround, after typing the name of the object in the namespace you want to import, hit your quick fix shortcut (e.g. ctrl-.) and select the using <namespace> quick fix and it will be added to imports.

@JustinGrote
Copy link

@genlu Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants