File tree 3 files changed +30
-1
lines changed
PowerShellEditorServices/Workspace
PowerShellEditorServices.Protocol
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ public static readonly
38
38
39
39
public class ClientEditorContext
40
40
{
41
+ public string CurrentFileContent { get ; set ; }
42
+
41
43
public string CurrentFilePath { get ; set ; }
42
44
43
45
public Position CursorPosition { get ; set ; }
Original file line number Diff line number Diff line change 3
3
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
4
//
5
5
6
+ using Microsoft . PowerShell . EditorServices ;
6
7
using Microsoft . PowerShell . EditorServices . Extensions ;
7
8
using Microsoft . PowerShell . EditorServices . Protocol . LanguageServer ;
8
9
using Microsoft . PowerShell . EditorServices . Protocol . MessageProtocol ;
@@ -89,10 +90,17 @@ public Task SetSelection(BufferRange selectionRange)
89
90
public EditorContext ConvertClientEditorContext (
90
91
ClientEditorContext clientContext )
91
92
{
93
+
94
+ ScriptFile scriptFile = null ;
95
+ if ( ! this . editorSession . Workspace . TryGetFile ( clientContext . CurrentFilePath , out scriptFile ) )
96
+ {
97
+ scriptFile = this . editorSession . Workspace . GetFileBuffer ( clientContext . CurrentFilePath , clientContext . CurrentFileContent ) ;
98
+ }
99
+
92
100
return
93
101
new EditorContext (
94
102
this ,
95
- this . editorSession . Workspace . GetFile ( clientContext . CurrentFilePath ) ,
103
+ scriptFile ,
96
104
new BufferPosition (
97
105
clientContext . CursorPosition . Line + 1 ,
98
106
clientContext . CursorPosition . Character + 1 ) ,
Original file line number Diff line number Diff line change @@ -101,6 +101,25 @@ public ScriptFile GetFile(string filePath)
101
101
return scriptFile ;
102
102
}
103
103
104
+ /// <summary>
105
+ /// Tries to get an open file in the workspace. Returns true or false if it succeeds.
106
+ /// </summary>
107
+ /// <param name="filePath">The file path at which the script resides.</param>
108
+ /// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param>
109
+ public bool TryGetFile ( string filePath , out ScriptFile scriptFile )
110
+ {
111
+ try
112
+ {
113
+ scriptFile = GetFile ( filePath ) ;
114
+ return true ;
115
+ }
116
+ catch ( FileNotFoundException )
117
+ {
118
+ scriptFile = null ;
119
+ return false ;
120
+ }
121
+ }
122
+
104
123
/// <summary>
105
124
/// Gets a new ScriptFile instance which is identified by the given file path.
106
125
/// </summary>
You can’t perform that action at this time.
0 commit comments