-
Notifications
You must be signed in to change notification settings - Fork 358
feat(vscode): add test recognition to vscode #5019
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """ | ||
| Provides helper functions to get ranges of tests in SQLMesh LSP. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from sqlmesh.core.linter.rule import Range, Position | ||
| from ruamel import yaml | ||
| from ruamel.yaml.comments import CommentedMap | ||
| import typing as t | ||
|
|
||
|
|
||
| def get_test_ranges( | ||
| path: Path, | ||
| ) -> t.Dict[str, Range]: | ||
| """ | ||
| Test files are yaml files with a stucture of dict to test information. This returns a dictionary | ||
| with the test name as the key and the range of the test in the file as the value. | ||
| """ | ||
| test_ranges: t.Dict[str, Range] = {} | ||
|
|
||
| with open(path, "r", encoding="utf-8") as file: | ||
| content = file.read() | ||
|
|
||
| # Parse YAML to get line numbers | ||
| yaml_obj = yaml.YAML() | ||
| yaml_obj.preserve_quotes = True | ||
| data = yaml_obj.load(content) | ||
|
|
||
| if not isinstance(data, dict): | ||
| raise ValueError("Invalid test file format: expected a dictionary at the top level.") | ||
|
|
||
| # For each top-level key (test name), find its range | ||
| for test_name in data: | ||
| if isinstance(data, CommentedMap) and test_name in data.lc.data: | ||
| # Get line and column info from ruamel yaml | ||
| line_info = data.lc.data[test_name] | ||
| start_line = line_info[0] # 0-based line number | ||
| start_col = line_info[1] # 0-based column number | ||
|
|
||
| # Find the end of this test by looking for the next test or end of file | ||
| lines = content.splitlines() | ||
| end_line = start_line | ||
|
|
||
| # Find where this test ends by looking for the next top-level key | ||
| # or the end of the file | ||
| for i in range(start_line + 1, len(lines)): | ||
| line = lines[i] | ||
| # Check if this line starts a new top-level key (no leading spaces) | ||
| if line and not line[0].isspace() and ":" in line: | ||
| end_line = i - 1 | ||
| break | ||
| else: | ||
| # This test goes to the end of the file | ||
| end_line = len(lines) - 1 | ||
|
|
||
| # Create the range | ||
| test_ranges[test_name] = Range( | ||
| start=Position(line=start_line, character=start_col), | ||
| end=Position( | ||
| line=end_line, character=len(lines[end_line]) if end_line < len(lines) else 0 | ||
| ), | ||
| ) | ||
|
|
||
| return test_ranges |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.