feat: go-to-definition for dependencies in abstract graph classes#282
Open
feat: go-to-definition for dependencies in abstract graph classes#282
Conversation
Fix cmd-click navigation for @provides() parameters when the enclosing class is abstract (no @graph decorator) and the dependency is declared as an abstract method in a parent abstract class. Two bugs fixed: - getParentGraphRecursive now recognises any enclosing ClassDeclaration as a graph, not just classes decorated with @graph - resolveProvider now walks the base class chain and finds abstract method declarations as provider definitions
The server package was pinned to 2.27.0 which doesn't include the new findAbstractProvider/resolveProviderOrAbstract methods added in graph.ts. CI fetches the published npm version on a clean install, so the new go-to-definition test was failing there despite passing locally.
This reverts commit 28b2a0d.
This reverts commit 37b1076.
8625adb to
12c510b
Compare
- Add AbstractConstructor type (abstract new (...args: any[]) => any) to types/index.ts - Broaden graph decorator generic bound from Constructor to AbstractConstructor - Cast to Constructable<ObjectGraph> when calling register (abstract classes are never instantiated by the DI runtime; registration is harmless) - Add acceptance test covering @graph on an abstract class
12c510b to
1ae7987
Compare
…providers resolveProviders() in graph.ts only included @provides-decorated methods from the base class. Abstract methods without a decorator (the contract pattern used by abstract port graphs) were never added to the provider pool, causing false unresolved-provider-dependencies errors. Add resolveBaseGraphProviders() that collects both decorated and abstract methods recursively up the base class chain, mirroring the existing resolveProviderOrAbstract() logic used by the single-name lookup path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vscode-language-server-obsidian: fix cmd-click navigation when the enclosing graph class is abstract (no@graphdecorator) and the dependency is declared as anabstractmethod in a parent abstract class.Root causes fixed:
getParentGraphRecursiveonly recognised classes decorated with@graph. Abstract graph classes without the decorator were invisible to the language server, causing navigation to silently returnundefined.resolveProvideronly searched a graph's own@provides()methods and subgraphs. It never walked the base class chain, so a dependency declared as anabstractmethod in a parent class could never be resolved.Changes:
graphs.ts—getParentGraphRecursivenow accepts any enclosingClassDeclarationas a graph (theisProviderDependency()gate already guarantees we are inside a@provides()method)graph.ts—resolveProvidernow delegates to the base class via a newresolveProviderOrAbstractpath that checks both@provides()methods andabstractmethod declarationsdependencyInAbstractBaseGraphcovering the full scenarioreact-obsidian: allow@graphdecorator on abstract classesAbstractConstructortype (abstract new (...args: any[]) => any) — a supertype covering both abstract and concrete constructors@graphdecorator generic bound fromConstructortoAbstractConstructor, making it valid to annotate abstract graph classes (e.g. for ESLint plugin dependency resolution)GraphRegistryis unchanged — harmless on abstract classes since they are never instantiated by the DI runtime@graphapplied directly to an abstract classeslint-plugin-obsidian: fix falseunresolved-provider-dependencieserrors on abstract port graphsresolveProviders()ingraph.tspreviously only collected@provides-decorated methods from the base class. Abstract methods without a decorator (the contract pattern used by abstract port graphs) were never added to the provider pool, producing false errors on every provider that consumed them.resolveBaseGraphProviders()that collects both decorated and abstract methods, recursively walking the full base class chain — mirroring the existingresolveProviderOrAbstract()logic used by the single-name lookup path.validGraphWithAbstractBaseProvider.tscovering the pattern.