Skip to content

Commit 5c28032

Browse files
committed
resolve comments
1 parent 7552464 commit 5c28032

3 files changed

Lines changed: 23 additions & 26 deletions

File tree

com.microsoft.copilot.eclipse.ui.terminal.tm/src/com/microsoft/copilot/eclipse/ui/terminal/tm/RunInTerminalTool.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ private boolean hasRunningForegroundCommand() {
252252

253253
private void sendInterrupt(ITerminalViewControl terminalViewControl) {
254254
Display display = terminalViewControl.getControl().getDisplay();
255+
// Ctrl+C must be delivered before the next foreground command is pasted into the reused terminal.
255256
display.syncExec(() -> {
256257
if (!terminalViewControl.isDisposed()) {
257258
terminalViewControl.sendKey(INTERRUPT_CHARACTER);

com.microsoft.copilot.eclipse.ui.terminal/src/com/microsoft/copilot/eclipse/ui/terminal/RunInTerminalTool.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ private boolean hasRunningForegroundCommand() {
254254

255255
private void sendInterrupt(ITerminalViewControl terminalViewControl) {
256256
Display display = terminalViewControl.getControl().getDisplay();
257+
// Ctrl+C must be delivered before the next foreground command is pasted into the reused terminal.
257258
display.syncExec(() -> {
258259
if (!terminalViewControl.isDisposed()) {
259260
terminalViewControl.sendKey(INTERRUPT_CHARACTER);

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/tools/RunInTerminalToolAdapter.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33

44
package com.microsoft.copilot.eclipse.ui.chat.tools;
55

6+
import java.io.File;
7+
import java.net.URI;
8+
import java.util.ArrayList;
69
import java.util.HashMap;
710
import java.util.List;
811
import java.util.Map;
912
import java.util.concurrent.CompletableFuture;
1013

1114
import org.apache.commons.lang3.StringUtils;
12-
import org.eclipse.core.resources.IProject;
1315
import org.eclipse.core.resources.IResource;
14-
import org.eclipse.core.runtime.IPath;
16+
import org.eclipse.lsp4j.WorkspaceFolder;
1517

1618
import com.microsoft.copilot.eclipse.core.lsp.protocol.ConfirmationMessages;
1719
import com.microsoft.copilot.eclipse.core.lsp.protocol.InputSchema;
@@ -27,6 +29,7 @@
2729
import com.microsoft.copilot.eclipse.ui.chat.ChatView;
2830
import com.microsoft.copilot.eclipse.ui.chat.services.ChatServiceManager;
2931
import com.microsoft.copilot.eclipse.ui.chat.services.ReferencedFileService;
32+
import com.microsoft.copilot.eclipse.ui.utils.ResourceUtils;
3033
import com.microsoft.copilot.eclipse.ui.utils.UiUtils;
3134

3235
/**
@@ -207,29 +210,25 @@ public CompletableFuture<LanguageModelToolResult[]> invoke(Map<String, Object> i
207210
}
208211

209212
static String resolveWorkingDirectoryFromResources(List<IResource> resources) {
210-
if (resources == null) {
211-
return "";
212-
}
213-
for (IResource resource : resources) {
214-
String location = resolveProjectLocation(resource);
215-
if (StringUtils.isNotBlank(location)) {
216-
return location;
217-
}
218-
}
219-
return "";
213+
return ResourceUtils.deriveWorkspaceFoldersFrom(resources).stream()
214+
.findFirst()
215+
.map(RunInTerminalToolAdapter::toLocalPath)
216+
.orElse("");
220217
}
221218

222219
private static String resolveWorkingDirectory() {
223220
ChatServiceManager manager = CopilotUi.getPlugin() != null ? CopilotUi.getPlugin().getChatServiceManager() : null;
224221
if (manager != null) {
225222
ReferencedFileService fileService = manager.getReferencedFileService();
226223
if (fileService != null) {
227-
String currentFileLocation = resolveProjectLocation(fileService.getCurrentFile());
228-
if (StringUtils.isNotBlank(currentFileLocation)) {
229-
return currentFileLocation;
224+
List<IResource> resources = new ArrayList<>();
225+
if (fileService.getCurrentFile() != null) {
226+
resources.add(fileService.getCurrentFile());
230227
}
231-
232-
String referencedLocation = resolveWorkingDirectoryFromResources(fileService.getReferencedFiles());
228+
if (fileService.getReferencedFiles() != null) {
229+
resources.addAll(fileService.getReferencedFiles());
230+
}
231+
String referencedLocation = resolveWorkingDirectoryFromResources(resources);
233232
if (StringUtils.isNotBlank(referencedLocation)) {
234233
return referencedLocation;
235234
}
@@ -239,19 +238,15 @@ private static String resolveWorkingDirectory() {
239238
return "";
240239
}
241240

242-
private static String resolveProjectLocation(IResource resource) {
243-
if (resource == null) {
241+
private static String toLocalPath(WorkspaceFolder workspaceFolder) {
242+
if (workspaceFolder == null || StringUtils.isBlank(workspaceFolder.getUri())) {
244243
return "";
245244
}
246-
return resolveProjectLocation(resource.getProject());
247-
}
248-
249-
private static String resolveProjectLocation(IProject project) {
250-
if (project == null || !project.isAccessible()) {
245+
try {
246+
return new File(URI.create(workspaceFolder.getUri())).getPath();
247+
} catch (IllegalArgumentException e) {
251248
return "";
252249
}
253-
IPath location = project.getLocation();
254-
return location != null ? location.toOSString() : "";
255250
}
256251

257252
/**

0 commit comments

Comments
 (0)