feat - support edit/create local files outside of workspace#248
Open
xinyi-gong wants to merge 1 commit into
Open
feat - support edit/create local files outside of workspace#248xinyi-gong wants to merge 1 commit into
xinyi-gong wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for tracking and reviewing create_file / insert_edit_into_file operations targeting absolute local filesystem paths outside the Eclipse workspace, integrating them into the existing “file change summary bar” UX and diff/keep/undo flows.
Changes:
- Introduces a
ChangedFileabstraction so the summary bar can track both workspaceIFileand externalPathtargets. - Extends Create/Edit file tools and the compare-editor plumbing to support local files (including empty-baseline diffs for newly created files).
- Adds/updates unit tests and documents a SWTBot test plan for the user-visible local-file flows.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/WorkingSetBar.java | Updates summary bar UI to render and route actions for ChangedFile (workspace + local). |
| com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/tools/WorkingSetHandler.java | Extends handler contract with Path overloads for keep/undo/view-diff. |
| com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/tools/FileToolService.java | Switches change tracking to ChangedFile, adds routing for local keep/undo/diff and “created then edited” behavior. |
| com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/tools/FileToolBase.java | Adds local-file caches and compare editor handling (Path-keyed) alongside existing workspace support. |
| com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/tools/EditFileTool.java | Adds local-path resolution + local edit/write/undo/diff behavior. |
| com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/tools/EditableLocalFileCompareInput.java | New compare input to represent editable local-file content within Compare UI. |
| com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/tools/CreateFileTool.java | Adds local file creation + local diff/undo support; adjusts baseline caching for create flows. |
| com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/tools/ChangedFile.java | New model type representing either a workspace IFile or external local Path. |
| com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/WorkingSetBarTest.java | Updates UI unit tests to use ChangedFile for summary bar rendering scenarios. |
| com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/tools/EditFileToolTest.java | Adds focused unit coverage for external local-file edit and undo/baseline behavior. |
| com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/tools/CreateFileToolTest.java | Adds focused unit coverage for external local-file create and undo behavior. |
| com.microsoft.copilot.eclipse.swtbot.test/test-plans/file-system/local-file-edit-and-create-tools.md | Adds a SWTBot-oriented manual test plan for local file edit/create UX flows. |
Comment on lines
220
to
223
| @Override | ||
| public void onKeepChange(IFile file) { | ||
| closeCompareEditor(file); | ||
| } |
Comment on lines
+225
to
233
| /** | ||
| * Handles the action of keeping changes to a local file. | ||
| * | ||
| * @param file the local file to keep changes for | ||
| */ | ||
| @Override | ||
| public void onUndoAllChanges(List<IFile> files) throws CoreException { | ||
| for (IFile file : files) { | ||
| onUndoChange(file); | ||
| } | ||
| public void onKeepChange(Path file) { | ||
| closeCompareEditor(file); | ||
| } |
Comment on lines
235
to
241
| @@ -176,11 +240,43 @@ public void onUndoChange(IFile file) throws CoreException { | |||
| closeCompareEditor(file); | |||
| } | |||
Comment on lines
+249
to
+254
| @Override | ||
| public void onUndoChange(Path file) throws IOException { | ||
| Path normalizedPath = normalizeLocalPath(file); | ||
| Files.deleteIfExists(normalizedPath); | ||
| closeCompareEditor(normalizedPath); | ||
| } |
Comment on lines
+108
to
+118
| private LanguageModelToolResult createFile(String filePath, String content) { | ||
| IFile file = FileUtils.getFileFromPath(filePath, false); | ||
|
|
||
| if (file != null && file.getProject().exists()) { | ||
| return createWorkspaceFile(file, filePath, content); | ||
| } | ||
|
|
||
| Path localPath = getLocalFilePath(filePath); | ||
| if (localPath != null) { | ||
| return createLocalFile(localPath, content); | ||
| } |
Comment on lines
+146
to
+160
| private LanguageModelToolResult[] editFile(String filePath, String code) { | ||
| IFile file = FileUtils.getFileFromPath(filePath, true); | ||
|
|
||
| if (file != null && file.exists()) { | ||
| return editWorkspaceFile(file, code); | ||
| } | ||
|
|
||
| Path localPath = getLocalFilePath(filePath); | ||
| if (localPath != null && Files.isRegularFile(localPath, LinkOption.NOFOLLOW_LINKS)) { | ||
| return editLocalFile(localPath, code); | ||
| } | ||
|
|
||
| return new LanguageModelToolResult[] { | ||
| new LanguageModelToolResult("The file path provided does not exist. Please check the path and try again.", | ||
| ToolInvocationStatus.error) }; |
Comment on lines
348
to
359
| // TODO: Should share a same instance with ReferencedFile | ||
| WorkbenchLabelProvider labelProvider = new WorkbenchLabelProvider(); | ||
| fileRows = new LinkedList<>(); | ||
| for (IFile file : filesMap.keySet()) { | ||
| for (ChangedFile file : filesMap.keySet()) { | ||
| if (file == null) { | ||
| continue; | ||
| } | ||
|
|
||
| Image image = labelProvider.getImage(file); | ||
| Image image = file.isWorkspaceFile() ? labelProvider.getImage(file.getWorkspaceFile()) | ||
| : PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE); | ||
| fileRows.add(new FileRow(contentArea, SWT.NONE, image, file)); | ||
| } |
Comment on lines
525
to
533
| /** | ||
| * Creates a map of mock files with the specified count. | ||
| */ | ||
| private Map<IFile, FileChangeProperty> createMockFilesMap(int count, boolean isHandled) { | ||
| Map<IFile, FileChangeProperty> filesMap = new LinkedHashMap<>(); | ||
| private Map<ChangedFile, FileChangeProperty> createMockFilesMap(int count, boolean isHandled) { | ||
| Map<ChangedFile, FileChangeProperty> filesMap = new LinkedHashMap<>(); | ||
| for (int i = 0; i < count; i++) { | ||
| IFile mockFile = createMockFile("TestFile" + i + ".java"); | ||
| filesMap.put(mockFile, new FileChangeProperty(FileChangeType.Created)); | ||
| filesMap.put(ChangedFile.workspace(mockFile), new FileChangeProperty(FileChangeType.Created)); | ||
| } |
Comment on lines
+132
to
+136
| Map<String, Object> input = new HashMap<>(); | ||
| input.put("filePath", filePath); | ||
| input.put("code", code); | ||
| input.put("explanation", "test edit"); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
create_fileandedit_filetool when the target is an absolute local file path outside the Eclipse workspace.IFileresources before falling back to local filesystem paths.