feat(Kamelets): implement getResourcesContentByType for local kamelets - #1462
feat(Kamelets): implement getResourcesContentByType for local kamelets#1462lordrip wants to merge 3 commits into
Conversation
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a helper for reading local ChangesLocal Kamelet loading
Maintenance edits
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant EditorChannel as VSCodeKaotoEditorChannelApi
participant Settings as WorkspaceConfiguration
participant Reader as KameletFileReader
participant FileSystem as vscode.workspace.fs
EditorChannel->>Settings: Read local Kamelet directories
EditorChannel->>EditorChannel: Resolve paths relative to current document
EditorChannel->>Reader: Read each resolved directory
Reader->>FileSystem: Enumerate and read .kamelet.yaml files
FileSystem-->>Reader: File contents
Reader-->>EditorChannel: Return FileTypesResponse entries
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
src/helpers/KameletFileReader.ts (1)
19-19: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer
node:pathoverpath.Static analysis flags this import; using the
node:prefix is the current idiomatic convention for built-in modules.♻️ Proposed fix
-import * as path from 'path'; +import * as path from 'node:path';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/helpers/KameletFileReader.ts` at line 19, Update the built-in path module import in KameletFileReader to use the node:path specifier instead of path, preserving the existing path namespace usage.Source: Linters/SAST tools
src/webview/VSCodeKaotoEditorChannelApi.ts (1)
178-198: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winParallelize directory reads instead of awaiting sequentially.
Each
readKameletsFromDirectorycall is independent I/O; awaiting them one at a time in the loop adds up latency linearly with the number of configured directories.♻️ Proposed fix
- const resources: FileTypesResponse[] = []; - - for (const dir of resolvedDirs) { - const dirResources = await readKameletsFromDirectory(dir); - resources.push(...dirResources); - } - - return resources; + const allResources = await Promise.all(Array.from(resolvedDirs).map((dir) => readKameletsFromDirectory(dir))); + return allResources.flat();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/webview/VSCodeKaotoEditorChannelApi.ts` around lines 178 - 198, Update getResourcesContentByType to initiate readKameletsFromDirectory for all resolvedDirs concurrently and await the combined results, then flatten them into resources while preserving the existing ordering and return behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/helpers/KameletFileReader.ts`:
- Around line 44-47: Update the entry filter in the directory-reading loop
around entries to test whether the FileType.File bit is set, rather than
requiring strict equality with FileType.File. Continue excluding non-file
entries and names without the .kamelet.yaml suffix, while allowing symbolic
links that also carry the File bit.
In `@src/test/VSCodeKaotoEditorChannelApi.test.ts`:
- Line 6: Correct the license header in VSCodeKaotoEditorChannelApi.test.ts by
removing the stray word “destination” from the parenthetical phrase, matching
the standard header used in KameletFileReader.ts.
- Around line 485-627: Move the `Deprecated Methods`, `URI and Path Utilities`,
and `Metadata File Path Normalization` suites out of the `should handle null
metadata values` test callback to the surrounding suite level so Mocha registers
them during collection. Keep only the `nullKey` metadata assertion inside that
test, preserving the existing suite contents and behavior.
---
Nitpick comments:
In `@src/helpers/KameletFileReader.ts`:
- Line 19: Update the built-in path module import in KameletFileReader to use
the node:path specifier instead of path, preserving the existing path namespace
usage.
In `@src/webview/VSCodeKaotoEditorChannelApi.ts`:
- Around line 178-198: Update getResourcesContentByType to initiate
readKameletsFromDirectory for all resolvedDirs concurrently and await the
combined results, then flatten them into resources while preserving the existing
ordering and return behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4e8827af-60b1-4c55-b980-114c8978445b
📒 Files selected for processing (8)
src/helpers/KameletFileReader.tssrc/helpers/SuggestionRegistry.tssrc/services/openapi-import.service.tssrc/test/VSCodeKaotoEditorChannelApi.test.tssrc/test/global.d.tssrc/test/helpers/KameletFileReader.test.tssrc/webview/VSCodeKaotoEditorChannelApi.tstsconfig.unit-tests.json
|
code looks good to me.
|
Implement the previously stubbed `getResourcesContentByType` method in `VSCodeKaotoEditorChannelApi` to load local `.kamelet.yaml` files from the directories configured in the `kaoto.localKameletDirectories` setting. The method resolves configured paths relative to the currently edited document, reads all `.kamelet.yaml` files from each directory, and returns their filenames and contents as `FileTypesResponse[]`. Directory-reading logic is extracted into a standalone helper `src/helpers/KameletFileReader.ts` to keep cognitive complexity within the SonarQube threshold (typescript:S3776) and to make the behaviour independently testable. A `paths` mapping for `@kaoto/kaoto/models` is added to `tsconfig.unit-tests.json` so that the new helper compiles correctly under the `moduleResolution: Node` setting used by the test build. fix: KaotoIO#1461
2818db9 to
0ab29c3
Compare
Detect `FileType.File` as a bit flag instead of comparing for strict equality, so kamelets reachable through a symbolic link are no longer skipped. VS Code reports a symlinked file as `File | SymbolicLink` (65), which never matched the previous `!==` check. Directories stay excluded, since `Directory & File` is still 0. Move the `Deprecated Methods`, `URI and Path Utilities` and `Metadata File Path Normalization` suites out of the body of the `should handle null metadata values` test and up to the top level. Mocha registers suites during collection while test callbacks only run during execution, so these eight tests were never registered and never ran, silently and with a green build. Remove a stray word from the license header of `VSCodeKaotoEditorChannelApi.test.ts`.
0ab29c3 to
41ccbbd
Compare
|



Context
Implement the previously stubbed
getResourcesContentByTypemethod inVSCodeKaotoEditorChannelApito load local.kamelet.yamlfiles from the directories configured in thekaoto.localKameletDirectoriessetting.The method resolves configured paths relative to the currently edited document, reads all
.kamelet.yamlfiles from each directory, and returns their filenames and contents asFileTypesResponse[].Directory-reading logic is extracted into a standalone helper
src/helpers/KameletFileReader.tsto keep cognitive complexity within the SonarQube threshold (typescript:S3776) and to make the behaviour independently testable.A
pathsmapping for@kaoto/kaoto/modelsis added totsconfig.unit-tests.jsonso that the new helper compiles correctly under themoduleResolution: Nodesetting used by the test build.fix: #1461
Summary by CodeRabbit
.kamelet.yamlfiles are included in editor resources.2.12.0-RC1.