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: updated walkthrough for coding assistant #229

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
{
"id": "sourcery.login",
"title": "Login",
"description": "Unlock all of Sourcery's features, including 14 a day trial of Sourcery Pro\n[Login](command:sourcery.login)",
"description": "Unlock all of Sourcery's features, including a 14 day trial of Sourcery Pro\n[Login](command:sourcery.login)",
"media": {
"markdown": "walkthrough/login.md"
},
Expand All @@ -94,8 +94,8 @@
},
{
"id": "sourcery.openWelcomeFile",
"title": "Get your first recommendation",
"description": "Get started by opening our tutorial \n[Open tutorial](command:toSide:sourcery.welcome.open)\n Put the cursor over the underlined code to see the refactoring suggestion. \n You can see all Sourcery's recommendations in the [Problems Pane](command:workbench.actions.view.problems)",
"title": "Explore Sourcery",
"description": "Get started by opening our tutorial \n[Open tutorial](command:toSide:sourcery.welcome.open)\n Ask Sourcery a question to improve your code. \n You can enable or disable the Sourcery Code Lenses above code for easy access. \n[Toggle Code Lens](command:sourcery.chat.toggleCodeLens)\n",
"media": {
"markdown": "walkthrough/view_welcome_file.md"
},
Expand All @@ -105,8 +105,8 @@
},
{
"id": "sourcery.acceptRecommendation",
"title": "Accept your first recommendation",
"description": "Put the cursor on an underline, then click the lightbulb or use the quick fix hotkey to show the code actions.\n Take the `Sourcery - Convert for loop into list comprehension` option to accept the change.\n",
"title": "Use Sourcery's In-Line Suggestions",
"description": "Sourcery suggests ways to improve your code quality while you work. Put your cursor on an underline, then click the lightbulb or use the quick fix hotkey to show the code actions.\n To see this in action scroll down to the `refactoring_example` function and take the `Sourcery - Convert for loop into list comprehension` option to accept the change.\n",
"media": {
"markdown": "walkthrough/accept_recommendation.md"
},
Expand All @@ -124,25 +124,6 @@
"completionEvents": [
"onCommand:sourcery.config.create"
]
},
{
"id": "sourcery.customRules",
"title": "Add custom rules",
"description": "You can add your own custom rules to Sourcery!\nFollow the tutorial to find out how.",
"media": {
"markdown": "walkthrough/custom_rules_tutorial.md"
}
},
{
"id": "sourcery.advancedFeatures",
"title": "Advanced Features",
"description": "With a Sourcery Pro account you can use Sourcery's advanced features on any project. Otherwise, you can use them on any open source project. \nThese include:\nRight click on a folder and choose 'Sourcery - Scan for refactorings'\n\n You can also try out 'Sourcery - Detect Clones' to find duplicate or near-duplicate code\nTo find out about our Team plan, including pre-commit hook and CLI:\n[Open our documentation](https://docs.sourcery.ai/Plans/Sourcery-Team/)\n",
"media": {
"markdown": "walkthrough/refactoring_scan.md"
},
"completionEvents": [
"onCommand:sourcery.refactor.workspace"
]
}
]
}
Expand Down
Binary file added walkthrough/Ask_Sourcery.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added walkthrough/Sourcery_Login.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions walkthrough/accept_recommendation.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## In-Line Suggestions
In addition to interacting with Sourcery through chat or through recipes and code lenses, Sourcery will also passively review your code and make suggestions to improve your code quality, readability, and maintainability.

In Python, JavaScript, and TypeScript files you'll start to see Sourcery underline sections of your code where it has a reccomendation. You can hover over these underlined pieces of code to see the suggestion Sourcery is proposing.

![Refactoring code with Sourcery](Sourcery_3_Ways_to_Refactor_VS_Code.gif)

### Accept a Suggestion

To accept a suggestion you can:
Expand Down
22 changes: 17 additions & 5 deletions walkthrough/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ github:

Here is the full list of configurable settings

## Enabling or Disabling the Coding Assistant
You can control whether or not the Sourcery Coding Assistant (Chat, Recipes, & Code Reviews) is enabled through your user level `sourcery.yaml` file or your project level `.sourcery.yaml` file.

To enable the coding assistant add in the following lines:

```yaml
coding_assistant:
enabled: True
```

To disable it, update the code above to:

```yaml
coding_assistant:
enabled: False
```

## Ignoring Paths or Files

Any path or file you specify to be ignored will be ignored both in your IDE & in
Expand Down Expand Up @@ -290,8 +307,3 @@ For example:
github:
sourcery_branch: sourcery/{base_branch}
```

## Advanced Features

For refactorings related to the detect clones feature please see our section on
[Advanced Features](https://docs.sourcery.ai/Advanced-Features.md)
14 changes: 11 additions & 3 deletions walkthrough/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ After those 14 days you can choose to upgrade to Pro or you can keep using Sourc

Sourcery is free to use for students and educators on open source and closed source projects. Email us at [[email protected]](mailto:[email protected]) and we'll get you set up with a free plan.

### Login
### Log In

After [signing up](https://sourcery.ai/signup/?utm_source=VS-Code), login by
After [signing up](https://sourcery.ai/signup/?utm_source=VS-Code), log in by
opening the command palette (Ctrl/Cmd+Shift+P) and executing the
`Sourcery: Login` command.
`Sourcery: Login` command. Or open the Sourcery sidebar (click our hexagonal logo) and click the log in button.

![Logging in with Sourcery](Sourcery_Login.gif)

### Opting Into Sourcery's Coding Assistant

There are two main ways you can use Sourcery as a pair programmer. One is through our rules-based in-line suggestions that run fully locally and that you'll see appear in your code. The other is through our Coding Assistant which you can ask questions to, can write new code or update your existing code, and more. The Coding Assistant relies on third party large language models and you need to opt into using it before you can start.

To opt into use the Coding Assistant, open the Sourcery sidebar, and click the Opt In button. If you choose not to opt in, you can still use the rules-based suggestions from Sourcery fully locally
36 changes: 15 additions & 21 deletions walkthrough/view_welcome_file.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
## Finding Your First Refactoring
## Using Sourcery as Your Pair Programmer

Sourcery continually checks your code and looks for opportunities to refactor it
to make it clearer, cleaner, and easier to work with. In your IDE, Sourcery will
underline or highlight any section of code where it can make a refactoring.
Sourcery works in 2 ways:
1. Gives you instant suggestions for improvements and refactorings to your Python, JavaScript, and TypeScript code.
2. Acts as an AI powered pair programmer allowing you to ask it questions, write new code, and interact with existing code

Let's take a look at how you can interact with it in VS Code

### In the tutorial

Once you open the tutorial you should see this example:

```python
def refactoring_example(spellbook):
result = []
for spell in spellbook:
if spell.is_awesome:
result.append(spell)
return result
def days_between_dates(date1, date2):
d1 = datetime.datetime.strptime(date1, '%Y-%m-%d').date()
d2 = datetime.datetime.strptime(date2, '%Y-%m-%d').date()
delta = d2 - d1
return delta.days
```

You should see Sourcery immediately highlight the `result = []` line with a
refactoring suggestion.

Hover your mouse over the underlined section to see a description of the change
and a diff of Sourcery's refactoring.
Above the function you'll see a few commands - these are Code Lenses that you can use to interact with Sourcery. Try clicking the "Ask Sourcery" Code Lens and asking it to update the code to use `dateutil`. The answer will appear in the Sourcery sidebar chat.

To accept one of Sourcery's changes, bring up the code actions/quick fix menu,
and choose to apply the changes. Or you can click on the lightbulb icon to apply
the changes.
![Sourcery updating code](Ask_Sourcery.gif)

![Accepting Changes In VS Code](Sourcery_3_Ways_to_Refactor_VS_Code.gif)
### More ways Sourcery can help

You can also bring up all of the changes Sourcery is suggesting to your open
files by opening up the Problems window.
Sourcery can interact with your code in a number of other ways. On the same function try clicking the `Generate Docstrings`, `Generate Tests`, and `Explain Code`Code Lenses.

Loading