-
Notifications
You must be signed in to change notification settings - Fork 22
[LSP] stderr verbose logs for the thought process #718
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 23 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d8a7255
lsp silent logs
mohammedahmed18 9f8b100
override other log methods and log serialized lsp messages
mohammedahmed18 23c75fe
send the module root to the lsp client
mohammedahmed18 7f87a12
Merge branch 'main' into lsp/verbose-quiet-logs
mohammedahmed18 bae3504
lsp messages
mohammedahmed18 92c8caa
Merge branch 'lsp/verbose-quiet-logs' of github.com:codeflash-ai/code…
mohammedahmed18 0f2a8d1
code print over lsp
mohammedahmed18 b9b4664
more enhancements
mohammedahmed18 3260e4a
more enhancements
mohammedahmed18 f630096
cf optimization
mohammedahmed18 2422e9a
log tags for lsp
mohammedahmed18 3c5c706
better markdown support for lsp message logging
mohammedahmed18 5dc178c
simple markdown table
mohammedahmed18 8d54ab6
force lsp log (tag)
mohammedahmed18 f766ac6
Merge branch 'main' of github.com:codeflash-ai/codeflash into lsp/ver…
mohammedahmed18 aab0aa4
fixes for cli console logs
mohammedahmed18 47dfc3c
small fixes
mohammedahmed18 a78ea5f
small fix
mohammedahmed18 a59a77b
it should work this time
mohammedahmed18 cd42934
prevent worktree log in lsp
mohammedahmed18 42c4652
logging enhancement
mohammedahmed18 06830ed
file name for best candidate
mohammedahmed18 a07b67d
reminder
mohammedahmed18 06de6d9
lsp logs formatting and small fixes
mohammedahmed18 231352f
typo
mohammedahmed18 3a30d9e
fixes for the api key and the lsp gracefull shutdown
mohammedahmed18 6e17f04
Merge branch 'main' into lsp/verbose-quiet-logs
Saga4 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,7 +133,7 @@ def optimize_python_code( # noqa: D417 | |
| "repo_name": git_repo_name, | ||
| } | ||
|
|
||
| logger.info("Generating optimized candidates…") | ||
| logger.info("!lsp|tags|Generating optimized candidates…") | ||
| console.rule() | ||
| try: | ||
| response = self.make_ai_service_request("/optimize", payload=payload, timeout=600) | ||
|
|
@@ -144,10 +144,10 @@ def optimize_python_code( # noqa: D417 | |
|
|
||
| if response.status_code == 200: | ||
| optimizations_json = response.json()["optimizations"] | ||
| logger.info(f"Generated {len(optimizations_json)} candidate optimizations.") | ||
| logger.info(f"!lsp|tags|Generated {len(optimizations_json)} candidate optimizations.") | ||
| console.rule() | ||
| end_time = time.perf_counter() | ||
| logger.debug(f"Generating optimizations took {end_time - start_time:.2f} seconds.") | ||
| logger.debug(f"!lsp|tags|Generating optimizations took {end_time - start_time:.2f} seconds.") | ||
|
||
| return self._get_valid_candidates(optimizations_json) | ||
| try: | ||
| error = response.json()["error"] | ||
|
|
@@ -194,7 +194,6 @@ def optimize_python_code_line_profiler( # noqa: D417 | |
| "lsp_mode": is_LSP_enabled(), | ||
| } | ||
|
|
||
| logger.info("Generating optimized candidates…") | ||
| console.rule() | ||
| if line_profiler_results == "": | ||
| logger.info("No LineProfiler results were provided, Skipping optimization.") | ||
|
|
@@ -209,7 +208,9 @@ def optimize_python_code_line_profiler( # noqa: D417 | |
|
|
||
| if response.status_code == 200: | ||
| optimizations_json = response.json()["optimizations"] | ||
| logger.info(f"Generated {len(optimizations_json)} candidate optimizations using line profiler information.") | ||
| logger.info( | ||
| f"!lsp|tags|Generated {len(optimizations_json)} candidate optimizations using line profiler information." | ||
| ) | ||
| console.rule() | ||
| return self._get_valid_candidates(optimizations_json) | ||
| try: | ||
|
|
@@ -331,7 +332,7 @@ def get_new_explanation( # noqa: D417 | |
| "original_explanation": original_explanation, | ||
| "dependency_code": dependency_code, | ||
| } | ||
| logger.info("Generating explanation") | ||
| logger.info("loading|tags|Generating explanation") | ||
| console.rule() | ||
| try: | ||
| response = self.make_ai_service_request("/explain", payload=payload, timeout=60) | ||
|
|
||
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
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 |
|---|---|---|
| @@ -1,7 +1,59 @@ | ||
| import os | ||
| import re | ||
| from functools import lru_cache | ||
|
|
||
| from rich.tree import Tree | ||
|
|
||
| from codeflash.models.test_type import TestType | ||
|
|
||
| _double_quote_pat = re.compile(r'"(.*?)"') | ||
| _single_quote_pat = re.compile(r"'(.*?)'") | ||
| worktree_path_regex = re.compile(r'\/[^"]*worktrees\/[^"]\S*') | ||
|
|
||
|
|
||
| @lru_cache(maxsize=1) | ||
| def is_LSP_enabled() -> bool: | ||
| return os.getenv("CODEFLASH_LSP", default="false").lower() == "true" | ||
|
|
||
|
|
||
| def tree_to_markdown(tree: Tree, level: int = 0) -> str: | ||
| """Convert a rich Tree into a Markdown bullet list.""" | ||
| indent = " " * level | ||
| if level == 0: | ||
| lines: list[str] = [f"{indent}### {tree.label}"] | ||
| else: | ||
| lines: list[str] = [f"{indent}- {tree.label}"] | ||
| for child in tree.children: | ||
| lines.extend(tree_to_markdown(child, level + 1).splitlines()) | ||
| return "\n".join(lines) | ||
|
|
||
|
|
||
| def report_to_markdown_table(report: dict[TestType, dict[str, int]], title: str) -> str: | ||
| lines = ["| Test Type | Passed ✅ | Failed ❌ |", "|-----------|--------|--------|"] | ||
| for test_type in TestType: | ||
| if test_type is TestType.INIT_STATE_TEST: | ||
| continue | ||
| passed = report[test_type]["passed"] | ||
| failed = report[test_type]["failed"] | ||
| if passed == 0 and failed == 0: | ||
| continue | ||
| lines.append(f"| {test_type.to_name()} | {passed} | {failed} |") | ||
| table = "\n".join(lines) | ||
| return f"### {title}\n{table}" | ||
|
|
||
|
|
||
| def simplify_worktree_paths(msg: str, highlight: bool = True) -> str: # noqa: FBT001, FBT002 | ||
| path_in_msg = worktree_path_regex.search(msg) | ||
| if path_in_msg: | ||
| last_part_of_path = path_in_msg.group(0).split("/")[-1] | ||
| if highlight: | ||
| last_part_of_path = f"`{last_part_of_path}`" | ||
| return msg.replace(path_in_msg.group(0), last_part_of_path) | ||
| return msg | ||
|
|
||
|
|
||
| def replace_quotes_with_backticks(text: str) -> str: | ||
| # double-quoted strings | ||
| text = _double_quote_pat.sub(r"`\1`", text) | ||
| # single-quoted strings | ||
| return _single_quote_pat.sub(r"`\1`", text) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can just have it broken in json object with "message", component. That would be easy for anyone to use.
or lets just drop tags as its confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Saga4 the idea of tags is to use the same message in console and lsp,
sending a json, we would re-write all logger lines, so I think this is the alternative option but dropping it will just not give us control over displaying the messages in the extension (the markdown)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, lets then we can remove "tags" as delimeter as thats not helping, pipe is enough I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah right, that would be cleaner