microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.26k stars 29.3k forks source link

Lower case single-letter variables are forcibly autocompleted to upper case classes with the same name. #190783

Closed genlu closed 11 months ago

genlu commented 1 year ago

Originally reported in https://github.com/dotnet/vscode-csharp/issues/6170

Type: Bug

Autocomplete replaces a valid local variable name with a single letter class name

make a class class G {} make a local var somewhere like var g = new G();

in that scope, on a new line, typing lower case g and then period should result in g.

instead, it is autocompleted to a capitalG. This does not happen if the class/variable name combo is more than one character long.

turning off Editor: Accept Suggestion On Commit Character is the only way to get it to stop doing this.

it might seem kind of silly but we have a large codebase that uses a class G as an app context that gets passed around, and a lower case g as convention for instances of that context, so this bites us a LOT

Environment information

VSCode version: 1.81.1 C# Extension: 2.0.376 Using OmniSharp: false

Dotnet Information .NET SDK: Version: 7.0.108 Commit: 31ced64b58 Runtime Environment: OS Name: Mac OS X OS Version: 13.4 OS Platform: Darwin RID: osx.13-arm64 Base Path: /usr/local/share/dotnet/sdk/7.0.108/ Host: Version: 7.0.8 Architecture: arm64 Commit: 4b0550942d .NET SDKs installed: 6.0.408 [/usr/local/share/dotnet/sdk] 7.0.108 [/usr/local/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None 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| |---|---|---|---| |copilot|GitHub|1.104.341|github.copilot-1.104.341| |csharp|ms-dotnettools|2.0.376|ms-dotnettools.csharp-2.0.376-darwin-arm64| |even-better-toml|tamasfe|0.19.2|tamasfe.even-better-toml-0.19.2| |prettier-vscode|esbenp|10.1.0|esbenp.prettier-vscode-10.1.0| |python|ms-python|2023.14.0|ms-python.python-2023.14.0| |swift-lang|sswg|1.4.0|sswg.swift-lang-1.4.0| |vscode-dotnet-runtime|ms-dotnettools|1.7.0|ms-dotnettools.vscode-dotnet-runtime-1.7.0| |vscode-lldb|vadimcn|1.9.2|vadimcn.vscode-lldb-1.9.2| |vscode-pylance|ms-python|2023.8.30|ms-python.vscode-pylance-2023.8.30|;

Extension version: 2.0.376 VS Code version: Code 1.81.1 (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:40:25.698Z) OS version: Darwin arm64 22.5.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M2 Pro (12 x 24)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
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)|2, 2, 2| |Memory (System)|16.00GB (0.10GB free)| |Process Argv|--crash-reporter-id d3331dea-0abd-4112-81ec-d5e028650357| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes627:30244334 vslsvsres303:30308271 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263cf:30335440 vscod805:30301674 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 pythonvs932:30410667 py29gd2263cf:30792227 vsclangdc:30486549 c4g48928:30535728 dsvsc012cf:30540253 pynewext54:30695312 azure-dev_surveyone:30548225 vscccc:30803845 282f8724:30602487 f6dab269:30613381 a9j8j154:30646983 showlangstatbar:30737416 03d35959:30757346 pythonfmttext:30731395 pythoncmv:30756943 fixshowwlkth:30771522 showindicator:30805244 pythongtdpath:30769146 i26e3531:30792625 gsofa:30804715 pythonnosmt12:30797651 pythonidxptcf:30805731 pythonnoceb:30805159 dsvsc013:30795093 dsvsc014:30804076 diffeditorv2:30812749 ```

===================================

In this scenario, C# server would return a list containing these two items to the client, and it is client's decision on how sorting and selection is done based on data we provided. I'd expect the client to select "g" over "G" when "g" is typed, since it's a perfect match. I'd consider this a VSCode bug.

image
manoj633 commented 1 year ago

Turning off "Editor: Accept Suggestion On Commit Character" is a workaround, but it's not an ideal long-term solution as it might hinder productivity in other contexts.

vscodenpa commented 11 months ago

Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for similar existing issues. See also our issue reporting guidelines.

Happy Coding!