You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/copilot/getting-started.md
+56-36Lines changed: 56 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,99 +28,89 @@ Follow these steps to [set up GitHub Copilot in VS Code](/docs/copilot/setup.md)
28
28
29
29
## Get your first code suggestion
30
30
31
-
Now that you've signed up for Copilot and activated the extension, let's see its assistance in action!
32
-
33
31
To get started with GitHub Copilot in VS Code, you don't have to do anything special. As you're typing code in the editor, Copilot automatically presents you code suggestions in the editor to help you code more efficiently.
34
32
35
-
1. Open Visual Studio Code and create a new TypeScript file `Calculator.ts`.
33
+
1. Open Visual Studio Code and create a new JavaScript file `calculator.js`.
36
34
37
-
1. In the TypeScript file, start typing the following class definition.
35
+
1. In the JavaScript file, start typing the following code:
38
36
39
-
```typescript
37
+
```javascript
40
38
classCalculator
41
39
```
42
40
43
-
Copilotautomaticallysuggestsamethodforour `Calculator` classingraydimmedtext (ghosttext). Inourexample, the `add` methodissuggested. Theexactsuggestionscanvary.
41
+
Copilot automatically suggests a method for our `Calculator`classin gray dimmed text (ghost text). In our example, the `add`and `subtract` methods are suggested. The exact suggestions you receive might vary.
44
42
45
43

46
44
47
45
1. To accept the suggestion, press the `kbstyle(Tab)` key.
48
46
49
47
Congratulations! You've just accepted your first AI-powered inline suggestion. As you continue typing, Copilot updates the inline suggestion accordingly.
1. For any given input, there might be multiple suggestions. Type the following code inside the class to add a `factorial` method:
52
50
53
-
```typescript
54
-
fibonacci(n: number): number {
51
+
```javascript
52
+
factorial(n) {
55
53
```
56
54
57
55
1. Hover over the suggestion in the editor and notice that there are multiple suggestions.
58
56
59
-

57
+

60
58
61
59
You can use the arrow controls or use the keybindings to show the next (`kb(editor.action.inlineSuggest.showNext)`) or previous (`kb(editor.action.inlineSuggest.showPrevious)`) suggestion.
62
60
63
61
AI-powered code completions can help you with generating boilerplate or repetitive code, letting you stay in the developer flow and focus on more complex coding tasks.
64
62
65
-
## GenerateasimplewebserverwithCopilot Chat
63
+
## Use Inline Chat to generate a basic web server
66
64
67
-
Withthe [CopilotChat](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot-chat) extension, you can start a chat conversations with Copilot in VS Code to ask specific tasks about your code by using natural language.
65
+
With Copilot Chat, you can start a chat conversation with Copilot in VS Code to ask specific tasks about your code by using natural language.
68
66
69
-
Let's use Copilot Chat to help us generate a simple Express web server.
67
+
Let's use **Inline Chat** to help generate a basic Express web server.
70
68
71
69
1. First, add a newTypeScript file `server.ts` to your workspace.
72
70
73
-
Let's use the Copilot Inline Chat in the editor to generate a simple Express web server.
74
-
75
71
1. Now, press `kb(inlinechat.start)` on your keyboard to bring up Copilot Inline Chat.
Notice that Copilot returns a streaming response in the editor. The response is an implementation for a simple Node.js Express web server.
84
80
85
81

86
82
87
83
1. Select **Accept** or press `kb(inlineChat.acceptChanges)` to apply the proposed code changes.
88
84
89
85
Congratulations! You've used Copilot Chat for generating code using chat and natural language.
90
86
91
-
Now, let's use Copilot Chat to help us refactor our code and return a static HTML file when users navigate to the home page.
92
-
93
87
## Refactor your code through AI chat
94
88
95
-
Asyouworkonanexisting codebase, youoftenneedtorefactororimproveexistingcode. You'll use Copilot Chat to refactor and iterate over your code.
89
+
You can also use Inline Chat to refactor or improve existing code in the editor.
96
90
97
-
Let's update the `/` route to return a static HTML page.
91
+
Notice that our web server is currently using a static port number `3000`. Let's change thisto use an environment variable for the port number.

108
100
109
101
1. Select **Accept** or press `kb(inlineChat.acceptChanges)` to apply the proposed code changes.
For example, you can ask Copilot to use a different environment variable name for the port number.
116
106
117
107
## Use Copilot Chat for general programming questions
118
108
119
109
As you're working in a newcodebase, or exploring a newprogramming language, you might have more general coding questions come up. Copilot Chat lets you open a chat conversation on the side, and which keeps track of the history of your questions.

124
114
125
115
> [!TIP]
126
116
> You can access different Copilot features from the Command Center menu at any time.
@@ -131,6 +121,34 @@ As you're working in a new codebase, or exploring a new programming language, yo
131
121
132
122
Notice how the chat response contains rich results, consisting of text and a code block. The code block in the chat response supports IntelliSense, which enables you get information about methods and symbols by hovering over them, or to go to their definition.
133
123
124
+
1. Follow the steps in the [Copilot Chat tutorial](/docs/copilot/getting-started-chat.md) to learn how you can also use Copilot Chat to ask questions about your specific codebase.
125
+
126
+
## Make edits across multiple files with Copilot Edits (preview)
127
+
128
+
Larger code changes might involve making edits to multiple files. With Copilot Edits, you can get AI-powered suggestions inline in the editor, across multiple files in your workspace.
129
+
130
+
Let's use Copilot Edits to return the contents of an HTML file in a web server response.
131
+
132
+
1. Select **Open Copilot Edits** from the Command Center Copilot menu or press `kb(workbench.action.chat.openEditSession)`.
133
+
134
+

135
+
136
+
1. The Copilot Edits view is opened. Notice that the `server.ts` file is added to the *Working Set*.
137
+
138
+
The Working Set contains the files that can be modified by Copilot Edits. If the file is not added, use **Add Files...* to add the file to the Working Set.
139
+
140
+

141
+
142
+
1. Enter *Return a static html page as the home page and implement it.* in the chat input field and press `kbstyle(Enter)` to start a new edit session.
143
+
144
+
Notice that Copilot Edits updates the `server.ts` file to return a static HTML page in the web server response. It also adds a new file `index.html` to the workspace.
145
+
146
+

147
+
148
+
1. If you're happy with the results, select **Accept** to apply all suggested changes.
149
+
150
+

151
+
134
152
## Fix coding errors with Copilot
135
153
136
154
Aside from inline completions and chat conversations, GitHub Copilot is available in different places and throughout your developer flow inVSCode. You might notice the presence of Copilot functionality through the *sparkle* icon in the VS Code user interface.
@@ -153,11 +171,13 @@ One such place is the Copilot coding actions in the editor, whenever there you h
153
171
154
172
Directly from the chat response, you can optionally select the **Insert into Terminal** button to copy the proposed command in your terminal.
155
173
156
-
## Congratulations
174
+
## Next steps
157
175
158
176
Congratulations, you've now used artificial intelligence to enhance your coding! In this tutorial, you successfully set up Copilot inVS Code, and used Copilot code completions, Copilot Chat, and code actions to help you code more efficiently.
159
177
160
-
You've started experimenting with Copilot and there'salotmoreyoucandowithit!TolearnmoreaboutCopilot Chat, proceedtothe [CopilotChatTutorial](/docs/copilot/getting-started-chat.md).
178
+
* To learn more about Copilot Chat, proceed to the [Copilot Chat Tutorial](/docs/copilot/getting-started-chat.md).
179
+
180
+
* To learn more about Copilot Edits, proceed to the [Copilot Edits](/docs/copilot/copilot-edits.md) documentation.
0 commit comments