-
Notifications
You must be signed in to change notification settings - Fork 251
Expose open LSP documents via $psEditor.Workspace.Documents
#2285
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
06342e3
Initial plan
Copilot 4db3d1d
Expose open workspace documents on PSEditor workspace API
Copilot ac47839
Add close operation to workspace documents API
Copilot c8721ba
Add ToString override for workspace documents
Copilot 9b0f372
Add Saved status to workspace documents
Copilot 9cbd9e6
Fix Saved property XML docs wording
Copilot 8afd2a5
Fix ToString filename extraction for Windows paths
Copilot 866c2aa
Harden ToString path handling for null and separators
Copilot b781fd1
Simplify methods
JustinGrote 29ae10f
Use IsInMemory for workspace document saved state
Copilot a568cf4
Clarify Saved semantics as file-backed state
Copilot 945736e
Remove unnecessary newline
JustinGrote 9b19bc2
Fix EditorWorkspaceTests for IEnumerable Documents
Copilot b82b81e
Switch to array and collection expressions
JustinGrote dd0f79f
Make EditorWorkspaceTests OS Independent
JustinGrote 38dd801
Fixup Open/Unsaved file identification
JustinGrote 8220f53
Try to fix flaky vim test
JustinGrote 2a0df44
Simplify API abstraction to just the existing WorkspaceOpenDocument
JustinGrote 9d51063
Remove dangling using
JustinGrote cfeba0e
Fix Tests
JustinGrote 9bba5bf
Additional comments and logging
JustinGrote 25e2240
Simplify IsUntitled getter (even tho I'm pretty sure this will break …
JustinGrote 7e2f5d4
Remove unnecessary collection expression
JustinGrote 8a167cb
Fix file-backed checks to use IsUntitled
Copilot f14c10d
Avoid extra recompilation for IsUntitled
JustinGrote e105ee6
Potential fix for pull request finding
JustinGrote cfead40
Add transition coverage for workspace open document saved state
Copilot 45f719c
Refine workspace document transition test semantics
Copilot 9c3ac22
Rename test helper to clarify saved-state intent
Copilot 605e82c
Assert edited content in open-document transition test
Copilot 384b313
Use expression-bodied helper to satisfy IDE0022
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
98 changes: 98 additions & 0 deletions
98
test/PowerShellEditorServices.Test/Extensions/EditorOperationsServiceTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
| using Microsoft.PowerShell.EditorServices.Extensions; | ||
| using Microsoft.PowerShell.EditorServices.Services; | ||
| using Microsoft.PowerShell.EditorServices.Services.Extension; | ||
| using Microsoft.PowerShell.EditorServices.Services.TextDocument; | ||
| using OmniSharp.Extensions.LanguageServer.Protocol; | ||
| using Xunit; | ||
|
|
||
| namespace PowerShellEditorServices.Test.Extensions | ||
| { | ||
| [Trait("Category", "Extensions")] | ||
| public class EditorOperationsServiceTests | ||
| { | ||
| [Fact] | ||
| public void GetWorkspaceOpenDocumentsReturnsOnlyOpenDocumentsAndCurrentInMemoryState() | ||
| { | ||
| WorkspaceService workspaceService = new(NullLoggerFactory.Instance); | ||
|
|
||
| ScriptFile openSaved = CreateFileBuffer(workspaceService, "open-saved.ps1"); | ||
| openSaved.IsOpen = true; | ||
| openSaved.IsInMemory = false; | ||
|
|
||
| ScriptFile openUnsaved = CreateFileBuffer(workspaceService, "open-unsaved.ps1"); | ||
| openUnsaved.IsOpen = true; | ||
| openUnsaved.IsInMemory = true; | ||
|
|
||
| ScriptFile closed = CreateFileBuffer(workspaceService, "closed.ps1"); | ||
| closed.IsOpen = false; | ||
| closed.IsInMemory = false; | ||
|
|
||
| EditorOperationsService editorOperationsService = new( | ||
| psesHost: null, | ||
| workspaceService, | ||
| languageServer: null); | ||
|
|
||
| WorkspaceOpenDocument[] documents = editorOperationsService.GetWorkspaceOpenDocuments(); | ||
|
|
||
| Assert.Equal(2, documents.Length); | ||
| Assert.Contains(documents, static document => document.Path.EndsWith("open-saved.ps1") && document.Saved); | ||
| Assert.Contains(documents, static document => document.Path.EndsWith("open-unsaved.ps1") && !document.Saved); | ||
| Assert.DoesNotContain(documents, static document => document.Path.EndsWith("closed.ps1")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetWorkspaceOpenDocumentsTracksEditedAndUntitledSaveStates() | ||
| { | ||
| WorkspaceService workspaceService = new(NullLoggerFactory.Instance); | ||
|
|
||
| ScriptFile openSaved = CreateFileBuffer(workspaceService, "open-saved.ps1"); | ||
| openSaved.IsOpen = true; | ||
|
|
||
| ScriptFile openUntitled = workspaceService.GetFileBuffer("untitled:Untitled-1", initialBuffer: string.Empty); | ||
| openUntitled.IsOpen = true; | ||
|
|
||
| EditorOperationsService editorOperationsService = new( | ||
| psesHost: null, | ||
| workspaceService, | ||
| languageServer: null); | ||
|
|
||
| WorkspaceOpenDocument[] initialDocuments = editorOperationsService.GetWorkspaceOpenDocuments(); | ||
| Assert.Contains(initialDocuments, static document => document.Path.EndsWith("open-saved.ps1") && document.Saved); | ||
| Assert.Contains(initialDocuments, static document => document.Path.StartsWith("untitled:", StringComparison.Ordinal) && !document.Saved); | ||
|
|
||
| openSaved.ApplyChange(new FileChange | ||
| { | ||
| Line = 1, | ||
| Offset = 1, | ||
| EndLine = 1, | ||
| EndOffset = 1, | ||
| InsertString = "Set-StrictMode -Version Latest" | ||
| }); | ||
| Assert.Contains("Set-StrictMode -Version Latest", openSaved.Contents, StringComparison.Ordinal); | ||
|
|
||
| WorkspaceOpenDocument[] editedDocuments = editorOperationsService.GetWorkspaceOpenDocuments(); | ||
| Assert.Contains(editedDocuments, static document => document.Path.EndsWith("open-saved.ps1") && !document.Saved); | ||
|
|
||
| MarkAsSaved(openSaved); | ||
| MarkAsSaved(openUntitled); | ||
|
|
||
| WorkspaceOpenDocument[] savedDocuments = editorOperationsService.GetWorkspaceOpenDocuments(); | ||
| Assert.Contains(savedDocuments, static document => document.Path.EndsWith("open-saved.ps1") && document.Saved); | ||
| Assert.Contains(savedDocuments, static document => document.Path.StartsWith("untitled:", StringComparison.Ordinal) && !document.Saved); | ||
| } | ||
|
|
||
| private static ScriptFile CreateFileBuffer(WorkspaceService workspaceService, string fileName) | ||
| { | ||
| string filePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"), fileName); | ||
| return workspaceService.GetFileBuffer(DocumentUri.FromFileSystemPath(filePath), initialBuffer: string.Empty); | ||
| } | ||
|
|
||
| private static void MarkAsSaved(ScriptFile scriptFile) => scriptFile.IsInMemory = scriptFile.IsUntitled; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.