Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to specify dbt projects directly and skip discovery #1593

Closed

Conversation

OneCyrus
Copy link
Contributor

@OneCyrus OneCyrus commented Mar 4, 2025

Overview

this allows to skip the project discovery as it often fails to discover projects

Problem

the extension often didn't discover our projects and returned an empty list.

fixes #1437

Solution

allow to specify the dbt projects manually through a setting dbt.specifiedProjects

How to test

  • Add dbt project paths to dbt.specifiedProjects in settings.json
  • Restart extension and it should pickup the project without using discovery

Checklist

  • I have run this code and it appears to resolve the stated issue
  • README.md updated and added information about my change

Summary by CodeRabbit

  • New Features
    • Introduced a new configuration option that allows users to explicitly specify project paths, providing enhanced control over project management.
    • Updated project discovery to leverage these user-defined paths, offering a more flexible and personalized integration experience.

this allows to skip the project discovery as it often fails to discover projects

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/OneCyrus/vscode-dbt-power-user?shareId=XXXX-XXXX-XXXX-XXXX).
Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Walkthrough

This pull request introduces a new configuration property dbt.specifiedProjects to the extension’s settings within the package.json file. This property is an array of strings that defaults to an empty array, allowing users to explicitly specify dbt project paths. The discoverProjects methods in both the DBTCloudProjectDetection and DBTCoreProjectDetection classes have been modified to first check for user-specified project paths, returning them as URI objects if present, thereby enhancing the project discovery process.

Changes

File(s) Change Summary
package.json Added new property dbt.specifiedProjects (array of strings, default: []) with description to allow users to override discovered projects.
src/dbt_client/dbtCloudIntegration.ts
src/dbt_client/dbtCoreIntegration.ts
Updated discoverProjects methods to first retrieve the dbt.specifiedProjects config. If non-empty, returns URIs built from these paths instead of using the default discovery process.

Sequence Diagram(s)

sequenceDiagram
    participant DP as DiscoverProjects()
    participant WC as Workspace Configuration
    participant URI as URI Constructor
    participant OL as Old Discovery Logic

    DP->>WC: Retrieve "dbt.specifiedProjects" setting
    alt Specified projects provided
        WC-->>DP: Return non-empty array
        DP->>URI: Convert each path string to URI
        URI-->>DP: Return array of URIs
        DP-->>Caller: Return specified project URIs
    else No specified projects
        WC-->>DP: Return empty array
        DP->>OL: Execute default project discovery
        OL-->>DP: Return discovered project URIs
        DP-->>Caller: Return discovered project URIs
    end
Loading

Possibly related PRs

Suggested reviewers

  • mdesmet

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8133da5 and 03f2228.

📒 Files selected for processing (1)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 8133da5 in 1 minute and 31 seconds

More details
  • Looked at 57 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 11 drafted comments based on config settings.
1. src/dbt_client/dbtCloudIntegration.ts:151
  • Draft comment:
    Great use of an early return to bypass discovery when 'dbt.specifiedProjects' is set. Consider updating documentation (README) to detail this new setting.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
2. src/dbt_client/dbtCoreIntegration.ts:178
  • Draft comment:
    Nice early return in 'discoverProjects' when 'dbt.specifiedProjects' is provided. Ensure that users are aware of absolute vs relative paths.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
3. package.json:287
  • Draft comment:
    New configuration property 'dbt.specifiedProjects' is added. Please update the README/documentation to explain how this setting works.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
4. src/dbt_client/dbtCloudIntegration.ts:151
  • Draft comment:
    Good use of an early return based on 'specifiedProjects'. Consider adding a debug log here to indicate that manual project specification is active, which would aid in troubleshooting.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
5. src/dbt_client/dbtCoreIntegration.ts:177
  • Draft comment:
    The early return based on 'specifiedProjects' is duplicated here. Consider refactoring this check into a shared utility function to reduce code duplication and improve maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
6. src/dbt_client/dbtCloudIntegration.ts:336
  • Draft comment:
    Typo found: 'Could not initalize Python environemnt' should be 'Could not initialize Python environment'.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
7. src/dbt_client/dbtCloudIntegration.ts:1151
  • Draft comment:
    Typo found: 'Error occured while reading file:' should be 'Error occurred while reading file:'.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
8. src/dbt_client/dbtCloudIntegration.ts:1233
  • Draft comment:
    Typo found: 'An error occured while parsing following json:' should be 'An error occurred while parsing the following JSON:'.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
9. src/dbt_client/dbtCloudIntegration.ts:245
  • Draft comment:
    Typo found in comment: 'First time let,s block' should be 'First time let's block'.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
10. src/dbt_client/dbtCoreIntegration.ts:64
  • Draft comment:
    Typographical error: In the comment on line 64, 'shouold' should be corrected to 'should'.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
11. src/dbt_client/dbtCoreIntegration.ts:215
  • Draft comment:
    Typographical error: The word 'occured' appears in several error messages (e.g., near line 215, 520, and 1202). It should be spelled 'occurred'.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_k4XDTbNBUAjpAXeq


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/dbt_client/dbtCoreIntegration.ts (1)

186-240: Consider adding logging for when using specified projects.

The implementation is functionally correct, but adding debug logging (similar to line 214) specifically for when using specified projects would help with troubleshooting.

Consider adding logging when the specified projects are being used:

  if (specifiedProjects.length > 0) {
+   this.dbtTerminal.debug(
+     "dbtCoreIntegration:discoverProjects",
+     `Using specified projects: ${specifiedProjects.join(', ')}`,
+   );
    return specifiedProjects.map((projectPath) => Uri.file(projectPath));
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55e9892 and 8133da5.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/dbt_client/dbtCloudIntegration.ts (1 hunks)
  • src/dbt_client/dbtCoreIntegration.ts (1 hunks)
🔇 Additional comments (3)
package.json (1)

287-294: Well-implemented configuration property for user-specified projects.

This addition allows users to manually specify dbt project paths, which directly addresses the PR objective of bypassing the automatic project discovery feature when it fails. The property is correctly defined as an array of strings with an appropriate default value and clear description.

src/dbt_client/dbtCloudIntegration.ts (1)

153-159: Good implementation of the user-specified projects feature.

This code correctly retrieves the specified projects from the workspace configuration and returns them as Uri objects if present, bypassing the automatic discovery logic. This is exactly what's needed to address the issue mentioned in the PR description.

The early return pattern used here is appropriate - if the user has explicitly specified projects, we return those immediately rather than attempting automatic discovery.

src/dbt_client/dbtCoreIntegration.ts (1)

178-184: Consistent implementation across DBT integrations.

This implementation mirrors the approach used in the cloud integration, ensuring consistent behavior regardless of whether users are using dbt core or dbt cloud. The code correctly retrieves user-specified projects from the configuration and prioritizes them over automatic discovery.

@anandgupta42
Copy link
Contributor

anandgupta42 commented Mar 4, 2025

@OneCyrus The auto discovery logic is designed to automatically identify projects. I was curious if you investigated why some projects aren't being discovered. I believe this could help us address the root cause of the problem without needing to pass any direct paths.

@mdesmet
Copy link
Contributor

mdesmet commented Mar 5, 2025

Thanks @OneCyrus, have you tried to run the extension in debug mode and check why the projects are not detected in the first place?

@OneCyrus
Copy link
Contributor Author

OneCyrus commented Mar 5, 2025

the issue is that the workspace.findFiles isn't somehow reliable. about 1 in 5 times it finds the files and the other 4 times it returns nothing. also our workspace is quite large with multiple dbt projects. maybe it just runs into a timeout randomly. unfortunately there is no error in the debug logs.

https://github.com/OneCyrus/vscode-dbt-power-user/blob/8133da53b895fc107e41ec1c4bbc4de8e5e93ff8/src/manifest/dbtWorkspaceFolder.ts#L87-L93

@mdesmet
Copy link
Contributor

mdesmet commented Mar 13, 2025

@OneCyrus : Can you make the changes to retry the project detection? Also can you link the underlying issue to the vscode issue that you found where findInFiles is not reliable.

@OneCyrus
Copy link
Contributor Author

@mdesmet i made a new PR with the retry logic instead of the custom project config

#1615

@mdesmet mdesmet closed this Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extension can't find projects
3 participants