Repository: dbt-labs/dbt-core

Issue:
[CT-2392] [Feature] return models in `dbt ls` by patch path
### Is this your first time submitting a feature request?

- [X] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [X] I have searched the existing issues, and I could not find an existing issue for this feature
- [X] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

### Describe the feature

right now, running `dbt ls -s path/to/_resource.yml`, you get only resources defined in that yml file, which are only tests, exposures, sources, and metrics (yml only resources)

I would like to be able to see the full lineage of any resource related to that file. Specifically, if the `_resource.yml` file in question contains model blocks, I'd like to see those resources as well!

This would unblock full lineage in the dbt Cloud IDE (i.e. you should be able to see lineage when viewing `yml_with_only_model_blocks.yml`

### Describe alternatives you've considered

go to the beach, call it a day

### Who will this benefit?

dbt Cloud IDE users

### Are you interested in contributing this feature?

yeah buddy

### Anything else?

_No response_


Discussion:

Resolving patch:
diff --git a/core/dbt/graph/selector_methods.py b/core/dbt/graph/selector_methods.py
--- a/core/dbt/graph/selector_methods.py
+++ b/core/dbt/graph/selector_methods.py
@@ -312,6 +312,11 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
             ofp = Path(real_node.original_file_path)
             if ofp in paths:
                 yield node
+            if hasattr(real_node, "patch_path") and real_node.patch_path:  # type: ignore
+                pfp = real_node.patch_path.split("://")[1]  # type: ignore
+                ymlfp = Path(pfp)
+                if ymlfp in paths:
+                    yield node
             elif any(parent in paths for parent in ofp.parents):
                 yield node
 


Test patch:
diff --git a/tests/functional/graph_selection/fixtures.py b/tests/functional/graph_selection/fixtures.py
--- a/tests/functional/graph_selection/fixtures.py
+++ b/tests/functional/graph_selection/fixtures.py
@@ -71,6 +71,15 @@
       email: nope@example.com
 """
 
+patch_path_selection_schema_yml = """
+version: 2
+
+models:
+  - name: subdir
+    description: submarine sandwich directory
+
+"""
+
 base_users_sql = """
 
 {{
@@ -182,6 +191,7 @@ class SelectionFixtures:
     def models(self):
         return {
             "schema.yml": schema_yml,
+            "patch_path_selection_schema.yml": patch_path_selection_schema_yml,
             "base_users.sql": base_users_sql,
             "users.sql": users_sql,
             "users_rollup.sql": users_rollup_sql,
diff --git a/tests/functional/graph_selection/test_graph_selection.py b/tests/functional/graph_selection/test_graph_selection.py
--- a/tests/functional/graph_selection/test_graph_selection.py
+++ b/tests/functional/graph_selection/test_graph_selection.py
@@ -125,6 +125,10 @@ def test_locally_qualified_name(self, project):
         check_result_nodes_by_name(results, ["nested_users", "subdir"])
         assert_correct_schemas(project)
 
+        results = run_dbt(["build", "--select", "models/patch_path_selection_schema.yml"])
+        check_result_nodes_by_name(results, ["subdir"])
+        assert_correct_schemas(project)
+
     def test_locally_qualified_name_model_with_dots(self, project):
         results = run_dbt(["run", "--select", "alternative.users"], expect_pass=False)
         check_result_nodes_by_name(results, ["alternative.users"])