feat: Display README when no code is selected
- Add feature to show README.md when no text is selected - Modify all command and main modules to support this feature - Remove 'input: required' from command.yml files for flexibility
This commit is contained in:
parent
ceb280012d
commit
852706d25d
@ -1,4 +1,3 @@
|
|||||||
description: Automatically add doc comments. Select some code and execute this command to generate comments.
|
description: Automatically add doc comments. Select some code and execute this command to generate comments.
|
||||||
input: required
|
|
||||||
steps:
|
steps:
|
||||||
- run: $devchat_python $command_path/main.py
|
- run: $devchat_python $command_path/main.py
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from devchat.ide.service import IDEService
|
from devchat.ide.service import IDEService
|
||||||
@ -6,6 +7,7 @@ from devchat.ide.vscode_services import selected_lines, visible_lines
|
|||||||
from devchat.llm import chat
|
from devchat.llm import chat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_selected_code():
|
def get_selected_code():
|
||||||
"""
|
"""
|
||||||
Retrieves the selected lines of code from the user's selection.
|
Retrieves the selected lines of code from the user's selection.
|
||||||
@ -22,6 +24,13 @@ def get_selected_code():
|
|||||||
|
|
||||||
miss_selected_error = "Please select some text."
|
miss_selected_error = "Please select some text."
|
||||||
if selected_data["text"] == "":
|
if selected_data["text"] == "":
|
||||||
|
readme_path = os.path.join(os.path.dirname(__file__), "README.md")
|
||||||
|
if os.path.exists(readme_path):
|
||||||
|
with open(readme_path, "r", encoding="utf-8") as f:
|
||||||
|
readme_text = f.read()
|
||||||
|
print(readme_text)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
print(miss_selected_error, file=sys.stderr, flush=True)
|
print(miss_selected_error, file=sys.stderr, flush=True)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
description: Automatically add docstrings. Select a function or method and execute this command to generate docstring.
|
description: Automatically add docstrings. Select a function or method and execute this command to generate docstring.
|
||||||
input: required
|
|
||||||
steps:
|
steps:
|
||||||
- run: $devchat_python $command_path/main.py
|
- run: $devchat_python $command_path/main.py
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from devchat.ide.service import IDEService
|
from devchat.ide.service import IDEService
|
||||||
@ -22,6 +23,13 @@ def get_selected_code():
|
|||||||
|
|
||||||
miss_selected_error = "Please select some text."
|
miss_selected_error = "Please select some text."
|
||||||
if selected_data["text"] == "":
|
if selected_data["text"] == "":
|
||||||
|
readme_path = os.path.join(os.path.dirname(__file__), "README.md")
|
||||||
|
if os.path.exists(readme_path):
|
||||||
|
with open(readme_path, "r", encoding="utf-8") as f:
|
||||||
|
readme_text = f.read()
|
||||||
|
print(readme_text)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
print(miss_selected_error, file=sys.stderr, flush=True)
|
print(miss_selected_error, file=sys.stderr, flush=True)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
description: Explain selected code.
|
description: Explain selected code.
|
||||||
input: required
|
|
||||||
steps:
|
steps:
|
||||||
- run: $devchat_python $command_path/explain.py
|
- run: $devchat_python $command_path/explain.py
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
from devchat.ide.service import IDEService
|
from devchat.ide.service import IDEService
|
||||||
from devchat.llm import chat
|
from devchat.llm import chat
|
||||||
@ -20,6 +21,13 @@ def get_selected_code():
|
|||||||
|
|
||||||
miss_selected_error = "Please select some text."
|
miss_selected_error = "Please select some text."
|
||||||
if selected_data["text"] == "":
|
if selected_data["text"] == "":
|
||||||
|
readme_path = os.path.join(os.path.dirname(__file__), "README.md")
|
||||||
|
if os.path.exists(readme_path):
|
||||||
|
with open(readme_path, "r", encoding="utf-8") as f:
|
||||||
|
readme_text = f.read()
|
||||||
|
print(readme_text)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
print(miss_selected_error, file=sys.stderr, flush=True)
|
print(miss_selected_error, file=sys.stderr, flush=True)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
description: Try to find out potential bugs in the selected code and try fixing these bugs automaticly.
|
description: Try to find out potential bugs in the selected code and try fixing these bugs automaticly.
|
||||||
input: required
|
|
||||||
steps:
|
steps:
|
||||||
- run: $devchat_python $command_path/main.py
|
- run: $devchat_python $command_path/main.py
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from devchat.ide.service import IDEService
|
from devchat.ide.service import IDEService
|
||||||
@ -22,6 +23,13 @@ def get_selected_code():
|
|||||||
|
|
||||||
miss_selected_error = "Please select some text."
|
miss_selected_error = "Please select some text."
|
||||||
if selected_data["text"] == "":
|
if selected_data["text"] == "":
|
||||||
|
readme_path = os.path.join(os.path.dirname(__file__), "README.md")
|
||||||
|
if os.path.exists(readme_path):
|
||||||
|
with open(readme_path, "r", encoding="utf-8") as f:
|
||||||
|
readme_text = f.read()
|
||||||
|
print(readme_text)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
print(miss_selected_error, file=sys.stderr, flush=True)
|
print(miss_selected_error, file=sys.stderr, flush=True)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from devchat.ide.service import IDEService
|
from devchat.ide.service import IDEService
|
||||||
@ -22,6 +23,13 @@ def get_selected_code():
|
|||||||
|
|
||||||
miss_selected_error = "Please select some text."
|
miss_selected_error = "Please select some text."
|
||||||
if selected_data["text"] == "":
|
if selected_data["text"] == "":
|
||||||
|
readme_path = os.path.join(os.path.dirname(__file__), "README.md")
|
||||||
|
if os.path.exists(readme_path):
|
||||||
|
with open(readme_path, "r", encoding="utf-8") as f:
|
||||||
|
readme_text = f.read()
|
||||||
|
print(readme_text)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
print(miss_selected_error, file=sys.stderr, flush=True)
|
print(miss_selected_error, file=sys.stderr, flush=True)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user