Skip to content

Commit c7ecec9

Browse files
committed
Refactor: use var in documentation code examples
1 parent dcce429 commit c7ecec9

5 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/site/markdown/advanced.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ var session = client.createSession(
127127
).get();
128128

129129
// Access the workspace where session state is persisted
130-
String workspace = session.getWorkspacePath();
130+
var workspace = session.getWorkspacePath();
131131
```
132132

133133
### Compaction Events
@@ -247,7 +247,7 @@ var session = client.createSession(
247247
if (request.getChoices() != null && !request.getChoices().isEmpty()) {
248248
System.out.println("Options: " + request.getChoices());
249249
// Return one of the provided choices
250-
String selectedChoice = request.getChoices().get(0);
250+
var selectedChoice = request.getChoices().get(0);
251251
return CompletableFuture.completedFuture(
252252
new UserInputResponse()
253253
.setAnswer(selectedChoice)
@@ -256,7 +256,7 @@ var session = client.createSession(
256256
}
257257

258258
// Freeform input
259-
String userAnswer = getUserInput(); // your input method
259+
var userAnswer = getUserInput(); // your input method
260260
return CompletableFuture.completedFuture(
261261
new UserInputResponse()
262262
.setAnswer(userAnswer)
@@ -345,7 +345,7 @@ Subscribe to lifecycle events to be notified when sessions are created, deleted,
345345
### Subscribing to All Lifecycle Events
346346

347347
```java
348-
AutoCloseable subscription = client.onLifecycle(event -> {
348+
var subscription = client.onLifecycle(event -> {
349349
System.out.println("Session " + event.getSessionId() + ": " + event.getType());
350350

351351
if (event.getMetadata() != null) {
@@ -363,7 +363,7 @@ subscription.close();
363363
import com.github.copilot.sdk.json.SessionLifecycleEventTypes;
364364

365365
// Listen only for session creation
366-
AutoCloseable subscription = client.onLifecycle(
366+
var subscription = client.onLifecycle(
367367
SessionLifecycleEventTypes.CREATED,
368368
event -> System.out.println("New session: " + event.getSessionId())
369369
);
@@ -385,7 +385,7 @@ When connecting to a server running in TUI+server mode (`--ui-server`), you can
385385
### Getting the Foreground Session
386386

387387
```java
388-
String sessionId = client.getForegroundSessionId().get();
388+
var sessionId = client.getForegroundSessionId().get();
389389
if (sessionId != null) {
390390
System.out.println("TUI is displaying session: " + sessionId);
391391
}

src/site/markdown/documentation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ done.get();
217217
Retrieve all messages and events from a session using `getMessages()`:
218218

219219
```java
220-
List<AbstractSessionEvent> history = session.getMessages().get();
220+
var history = session.getMessages().get();
221221

222-
for (AbstractSessionEvent event : history) {
222+
for (var event : history) {
223223
switch (event) {
224224
case UserMessageEvent user ->
225225
System.out.println("User: " + user.getData().getContent());
@@ -287,9 +287,9 @@ try {
287287
Query available models before creating a session:
288288

289289
```java
290-
List<ModelInfo> models = client.listModels().get();
290+
var models = client.listModels().get();
291291

292-
for (ModelInfo model : models) {
292+
for (var model : models) {
293293
System.out.printf("%s (%s)%n", model.getId(), model.getName());
294294
}
295295
```
@@ -329,10 +329,10 @@ System.out.println("Claude: " + future2.get().getData().getContent());
329329

330330
```java
331331
// Get the last session ID
332-
String lastSessionId = client.getLastSessionId().get();
332+
var lastSessionId = client.getLastSessionId().get();
333333

334334
// Or list all sessions
335-
List<SessionMetadata> sessions = client.listSessions().get();
335+
var sessions = client.listSessions().get();
336336

337337
// Resume a session
338338
var session = client.resumeSession(lastSessionId).get();

src/site/markdown/getting-started.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ public class ToolExample {
179179
"required", List.of("city")
180180
),
181181
invocation -> {
182-
Map<String, Object> params = invocation.getArguments();
183-
String city = (String) params.get("city");
182+
var params = invocation.getArguments();
183+
var city = (String) params.get("city");
184184

185185
// In a real app, you'd call a weather API here
186186
String[] conditions = {"sunny", "cloudy", "rainy", "partly cloudy"};
187187
int temp = new Random().nextInt(30) + 50;
188-
String condition = conditions[new Random().nextInt(conditions.length)];
188+
var condition = conditions[new Random().nextInt(conditions.length)];
189189

190190
return CompletableFuture.completedFuture(Map.of(
191191
"city", city,
@@ -258,11 +258,11 @@ public class WeatherAssistant {
258258
"required", List.of("city")
259259
),
260260
invocation -> {
261-
Map<String, Object> params = invocation.getArguments();
262-
String city = (String) params.get("city");
261+
var params = invocation.getArguments();
262+
var city = (String) params.get("city");
263263
String[] conditions = {"sunny", "cloudy", "rainy", "partly cloudy"};
264264
int temp = new Random().nextInt(30) + 50;
265-
String condition = conditions[new Random().nextInt(conditions.length)];
265+
var condition = conditions[new Random().nextInt(conditions.length)];
266266
return CompletableFuture.completedFuture(Map.of(
267267
"city", city,
268268
"temperature", temp + "°F",

src/site/markdown/hooks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ var hooks = new SessionHooks()
113113
.setOnPreToolUse((input, invocation) -> {
114114
if (input.getToolName().equals("search_code")) {
115115
// Add project root to search path
116-
ObjectMapper mapper = new ObjectMapper();
117-
ObjectNode modifiedArgs = mapper.createObjectNode();
116+
var mapper = new ObjectMapper();
117+
var modifiedArgs = mapper.createObjectNode();
118118
modifiedArgs.put("path", "/my/project/src");
119119
modifiedArgs.set("query", input.getToolArgs().get("query"));
120120

@@ -283,7 +283,7 @@ var hooks = new SessionHooks()
283283
System.out.println("Session ended: " + input.getReason());
284284

285285
// Clean up session resources
286-
ResourceManager resources = sessionResources.remove(invocation.getSessionId());
286+
var resources = sessionResources.remove(invocation.getSessionId());
287287
if (resources != null) {
288288
resources.close();
289289
}

src/site/markdown/mcp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ System.out.println(result.getData().getContent());
3434
Run a tool as a subprocess (stdin/stdout communication).
3535

3636
```java
37-
Map<String, Object> server = new HashMap<>();
37+
var server = new HashMap<String, Object>();
3838
server.put("type", "local");
3939
server.put("command", "node");
4040
server.put("args", List.of("./mcp-server.js"));

0 commit comments

Comments
 (0)