Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Dart LSP definition lookup and add comprehensive tests
Fixed Dart LSP definition lookup issues:
- Handle Dart's function/method naming convention (returns names with parentheses)
- Support qualified names like ClassName.methodName
- Extract definition text directly from workspace/symbol location
- Update hover test snapshot for comment change

Added comprehensive test coverage with 23 test cases covering classes,
functions, methods, enums, mixins, extensions, and typedefs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
  • Loading branch information
titanous and claude committed Aug 8, 2025
commit a5a3464aca01a5f262920ada8833d623eeea31aa
10 changes: 10 additions & 0 deletions integrationtests/snapshots/dart/definition/constant.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

Symbol: SHARED_CONSTANT
/TEST_OUTPUT/workspace/types.dart
Kind: Variable
Range: L29:C1 - L30:C46

29|/// A constant value
30|const String SHARED_CONSTANT = 'shared_value'

14 changes: 14 additions & 0 deletions integrationtests/snapshots/dart/definition/enum.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

Symbol: Color
/TEST_OUTPUT/workspace/types.dart
Kind: Enum
Range: L32:C1 - L37:C2

32|/// An enum for testing
33|enum Color {
34| red,
35| green,
36| blue
37|}

12 changes: 12 additions & 0 deletions integrationtests/snapshots/dart/definition/global-function.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

Symbol: createHelper(…)
/TEST_OUTPUT/workspace/helper.dart
Kind: Function
Range: L24:C1 - L27:C2

24|/// A helper function that creates instances
25|HelperClass createHelper(String name) {
26| return HelperClass(name);
27|}

10 changes: 10 additions & 0 deletions integrationtests/snapshots/dart/definition/global-variable.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

Symbol: globalHelper
/TEST_OUTPUT/workspace/helper.dart
Kind: Variable
Range: L29:C1 - L30:C43

29|/// Global variable for testing
30|final globalHelper = HelperClass('global')

28 changes: 28 additions & 0 deletions integrationtests/snapshots/dart/definition/local-class.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

Symbol: HelperClass
/TEST_OUTPUT/workspace/helper.dart
Kind: Class
Range: L3:C1 - L22:C2

3|/// Helper class for demonstration
4|class HelperClass implements SharedInterface {
5| final String name;
6|
7| HelperClass(this.name);
8|
9| @override
10| void doSomething() {
11| print('Doing something with $name');
12| }
13|
14| @override
15| String getName() => name;
16|
17| /// Process method specific to HelperClass
18| void process() {
19| doSomething();
20| print('Processing: ${getName()}');
21| }
22|}

73 changes: 73 additions & 0 deletions integrationtests/snapshots/dart/definition/main-function.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---

Symbol: main()
/TEST_OUTPUT/workspace/main.dart
Kind: Function
Range: L5:C1 - L24:C2

5|void main() {
6| print('Hello, World!');
7|
8| var helper = HelperClass('test');
9| helper.process();
10|
11| SharedClass shared = SharedClass(42);
12| print(shared.getValue());
13|
14| // Use types
15| Color color = Color.red;
16| print(color);
17|
18| // Use constant
19| print(SHARED_CONSTANT);
20|
21| // Use function
22| var newHelper = createHelper('new');
23| print(newHelper.getName());
24|}

---

Symbol: main()
File: /DART_SDK/lib/_internal/vm/bin/vmservice_io.dart
Kind: Function
Range: L273:C1 - L309:C2

273|@pragma('vm:entry-point', !bool.fromEnvironment('dart.vm.product'))
274|void main() {
275| // Set embedder hooks.
276| VMServiceEmbedderHooks.cleanup = cleanupCallback;
277| VMServiceEmbedderHooks.createTempDir = createTempDirCallback;
278| VMServiceEmbedderHooks.ddsConnected = ddsConnectedCallback;
279| VMServiceEmbedderHooks.ddsDisconnected = ddsDisconnectedCallback;
280| VMServiceEmbedderHooks.deleteDir = deleteDirCallback;
281| VMServiceEmbedderHooks.writeFile = writeFileCallback;
282| VMServiceEmbedderHooks.writeStreamFile = writeStreamFileCallback;
283| VMServiceEmbedderHooks.readFile = readFileCallback;
284| VMServiceEmbedderHooks.listFiles = listFilesCallback;
285| VMServiceEmbedderHooks.serverInformation = serverInformationCallback;
286| VMServiceEmbedderHooks.webServerControl = webServerControlCallback;
287| VMServiceEmbedderHooks.acceptNewWebSocketConnections =
288| webServerAcceptNewWebSocketConnections;
289| VMServiceEmbedderHooks.serveObservatory = serveObservatoryCallback;
290| VMServiceEmbedderHooks.getResidentCompilerInfoFile =
291| _getResidentCompilerInfoFile;
292|
293| server = Server(
294| // Always instantiate the vmservice object so that the exit message
295| // can be delivered and waiting loaders can be cancelled.
296| VMService(),
297| _ip,
298| _port,
299| _originCheckDisabled,
300| _authCodesDisabled,
301| _serviceInfoFilename,
302| _enableServicePortFallback,
303| );
304|
305| if (_autoStart) {
306| _toggleWebServer();
307| }
308| _registerSignalHandler();
309|}

14 changes: 14 additions & 0 deletions integrationtests/snapshots/dart/definition/method-qualified.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

Symbol: process()
/TEST_OUTPUT/workspace/helper.dart
Kind: Method
Container Name: HelperClass
Range: L17:C3 - L21:C4

17|/// Process method specific to HelperClass
18| void process() {
19| doSomething();
20| print('Processing: ${getName()}');
21| }

107 changes: 107 additions & 0 deletions integrationtests/snapshots/dart/definition/method-simple.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---

Symbol: process
File: /DART_SDK/lib/io/io_resource_info.dart
Kind: Field
Container Name: _SpawnedProcessResourceInfo
Range: L146:C3 - L146:C25

146|final _Process process

---

Symbol: process
File: /PUB_CACHE/hosted/pub.dev/test_core-0.6.12/lib/src/runner/vm/test_compiler.dart
Kind: Enum
Range: L246:C1 - L246:C35

246|enum VmTestType { isolate, process }

---

Symbol: process()
/TEST_OUTPUT/workspace/helper.dart
Kind: Method
Container Name: HelperClass
Range: L17:C3 - L21:C4

17|/// Process method specific to HelperClass
18| void process() {
19| doSomething();
20| print('Processing: ${getName()}');
21| }

---

Symbol: process()
/TEST_OUTPUT/workspace/types.dart
Kind: Method
Container Name: SharedClass
Range: L14:C3 - L17:C4

14|/// A method that processes the value
15| String process() {
16| return 'Processed: $value';
17| }

---

Symbol: process()
File: /DART_SDK/lib/ffi/dynamic_library.dart
Kind: Constructor
Container Name: DynamicLibrary
Range: L12:C3 - L16:C45

12|/// Creates a [DynamicLibrary] holding all global symbols.
13| ///
14| /// Any symbol in a library currently loaded with global visibility
15| /// (including the executable itself) may be resolved through this library.
16| external factory DynamicLibrary.process();

---

Symbol: process(…)
File: /DART_SDK/lib/io/data_transformer.dart
Kind: Method
Container Name: RawZLibFilter
Range: L436:C3 - L439:C52

436|/// Process a chunk of data.
437| ///
438| /// This method must only be called when [processed] returns `null`.
439| void process(List<int> data, int start, int end);

---

Symbol: process(…)
File: /PUB_CACHE/hosted/pub.dev/analyzer-8.1.0/lib/src/dart/element/replace_top_bottom_visitor.dart
Kind: Method
Container Name: ReplaceTopBottomVisitor
Range: L20:C3 - L44:C4

20|TypeImpl process(TypeImpl type, Variance variance) {
21| if (variance.isContravariant) {
22| // ...replacing every occurrence in `T` of a type `S` in a contravariant
23| // position where `S <: Never` by `Object?`
24| if (_typeSystem.isSubtypeOf(type, NeverTypeImpl.instance)) {
25| return _topType;
26| }
27| } else {
28| // ...and every occurrence in `T` of a top type in a position which
29| // is not contravariant by `Never`.
30| if (_typeSystem.isTop(type)) {
31| return _bottomType;
32| }
33| }
34|
35| var alias = type.alias;
36| if (alias != null) {
37| return _instantiatedTypeAlias(type, alias, variance);
38| } else if (type is InterfaceTypeImpl) {
39| return _interfaceType(type, variance);
40| } else if (type is FunctionTypeImpl) {
41| return _functionType(type, variance);
42| }
43| return type;
44| }

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NonExistentSymbol not found
14 changes: 14 additions & 0 deletions integrationtests/snapshots/dart/definition/query-enum-value.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

Symbol: Color
/TEST_OUTPUT/workspace/types.dart
Kind: Enum
Range: L32:C1 - L37:C2

32|/// An enum for testing
33|enum Color {
34| red,
35| green,
36| blue
37|}

28 changes: 28 additions & 0 deletions integrationtests/snapshots/dart/definition/query-exact-match.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

Symbol: HelperClass
/TEST_OUTPUT/workspace/helper.dart
Kind: Class
Range: L3:C1 - L22:C2

3|/// Helper class for demonstration
4|class HelperClass implements SharedInterface {
5| final String name;
6|
7| HelperClass(this.name);
8|
9| @override
10| void doSomething() {
11| print('Doing something with $name');
12| }
13|
14| @override
15| String getName() => name;
16|
17| /// Process method specific to HelperClass
18| void process() {
19| doSomething();
20| print('Processing: ${getName()}');
21| }
22|}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
helperclass not found
73 changes: 73 additions & 0 deletions integrationtests/snapshots/dart/definition/query-main.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---

Symbol: main()
/TEST_OUTPUT/workspace/main.dart
Kind: Function
Range: L5:C1 - L24:C2

5|void main() {
6| print('Hello, World!');
7|
8| var helper = HelperClass('test');
9| helper.process();
10|
11| SharedClass shared = SharedClass(42);
12| print(shared.getValue());
13|
14| // Use types
15| Color color = Color.red;
16| print(color);
17|
18| // Use constant
19| print(SHARED_CONSTANT);
20|
21| // Use function
22| var newHelper = createHelper('new');
23| print(newHelper.getName());
24|}

---

Symbol: main()
File: /DART_SDK/lib/_internal/vm/bin/vmservice_io.dart
Kind: Function
Range: L273:C1 - L309:C2

273|@pragma('vm:entry-point', !bool.fromEnvironment('dart.vm.product'))
274|void main() {
275| // Set embedder hooks.
276| VMServiceEmbedderHooks.cleanup = cleanupCallback;
277| VMServiceEmbedderHooks.createTempDir = createTempDirCallback;
278| VMServiceEmbedderHooks.ddsConnected = ddsConnectedCallback;
279| VMServiceEmbedderHooks.ddsDisconnected = ddsDisconnectedCallback;
280| VMServiceEmbedderHooks.deleteDir = deleteDirCallback;
281| VMServiceEmbedderHooks.writeFile = writeFileCallback;
282| VMServiceEmbedderHooks.writeStreamFile = writeStreamFileCallback;
283| VMServiceEmbedderHooks.readFile = readFileCallback;
284| VMServiceEmbedderHooks.listFiles = listFilesCallback;
285| VMServiceEmbedderHooks.serverInformation = serverInformationCallback;
286| VMServiceEmbedderHooks.webServerControl = webServerControlCallback;
287| VMServiceEmbedderHooks.acceptNewWebSocketConnections =
288| webServerAcceptNewWebSocketConnections;
289| VMServiceEmbedderHooks.serveObservatory = serveObservatoryCallback;
290| VMServiceEmbedderHooks.getResidentCompilerInfoFile =
291| _getResidentCompilerInfoFile;
292|
293| server = Server(
294| // Always instantiate the vmservice object so that the exit message
295| // can be delivered and waiting loaders can be cancelled.
296| VMService(),
297| _ip,
298| _port,
299| _originCheckDisabled,
300| _authCodesDisabled,
301| _serviceInfoFilename,
302| _enableServicePortFallback,
303| );
304|
305| if (_autoStart) {
306| _toggleWebServer();
307| }
308| _registerSignalHandler();
309|}

Loading