Skip to content

Prefixed identifiers shouldn't be hidden from completion by the same identifier with no/different prefixes #5242

@FMorschel

Description

@FMorschel

Describe the bug
When you have two classes with the same name, there may be some places where you'd like one over the other because they have no relation.

To Reproduce
Add the following code to your main.dart file:

import 'my_class_name.dart' as i;

class MyClassName {}

void main() {
  f();
}

void f(i.MyClassName c) {}

Add a new file called my_class_name.dart and inside it add:

class MyClassName {}

Now inside the call for f, add My and try to fill the class, it only shows the class from this library.

Even if you only have class declarations with that name from other files like say you add a second.dart file with the same content as my_class_name.dart. Import it with the alias s and remove MyClassName declaration from inside main.dart (some changes to f as well, look the following code). It will not be able to show both declarations (not ever the second one without the s.).

import 'my_class_name.dart' as i;
import 'second.dart' as s;


void main() {
  f2(My);
}

void f1(i.MyClassName c) {}
void f2(s.MyClassName c) {}

If now you try and get the code completion it will still show only i.MyClassName.

image

Expected behavior
I expect all declarations to be visible with code completion if you try to create an instance (or if you have the defined type you could derive from that).

Also, if I have MyClassName inside main.dart and no imports, I expect it to show me there are other files I could import for the same name class (especially if I'm trying to create an instance to fill a parameter that has another class - same name - from another library). But this would probably be better if either dart-lang/sdk#55863 or dart-lang/sdk#56584 were added).

Please complete the following information:

Workspace Environment
Dart Code extension: 3.95.20240827
Flutter extension: 3.95.20240801 (activated)

App: Visual Studio Code
App Host: desktop
Version: win 1.92.2

Workspace type: Dart (LSP)
Workspace name: bug

Dart (3.6.0-175.0.dev): C:\Users\felip_0vh5fa6\.puro\shared\caches\8d248aead383a5f2efbe866db03606858b224735\dart-sdk
Flutter (999.999.888): C:\Users\felip_0vh5fa6\.puro\envs\master\flutter (No device)

Output from 'dart info'

C:\Users\felip_0vh5fa6\.puro\shared\caches\8d248aead383a5f2efbe866db03606858b224735\dart-sdk\bin\dart.exe info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

General info

  • Dart 3.6.0-175.0.dev (dev) (Fri Aug 23 09:07:06 2024 -0700) on "windows_x64"
  • on windows / "Windows 10 Pro" 10.0 (Build 22631)
  • locale is pt-BR

Project info

  • sdk constraint: '>=3.3.0 <4.0.0'
  • dependencies: collection, test, time
  • dev_dependencies: dart_code_metrics, lints

Process info

Memory CPU Elapsed time Command line
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions