11
11
using System . Threading ;
12
12
using System . Threading . Tasks ;
13
13
using Microsoft . Extensions . Logging ;
14
+ using Microsoft . PowerShell . EditorServices . Hosting ;
14
15
using Microsoft . PowerShell . EditorServices . Services . Analysis ;
15
16
using Microsoft . PowerShell . EditorServices . Services . Configuration ;
16
17
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
@@ -52,8 +53,7 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)
52
53
. Append ( ':' )
53
54
. Append ( end . Character ) ;
54
55
55
- string id = sb . ToString ( ) ;
56
- return id ;
56
+ return sb . ToString ( ) ;
57
57
}
58
58
59
59
/// <summary>
@@ -96,20 +96,16 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)
96
96
97
97
private CancellationTokenSource _diagnosticsCancellationTokenSource ;
98
98
99
+ private readonly string _pssaModulePath ;
100
+
99
101
private string _pssaSettingsFilePath ;
100
102
101
- /// <summary>
102
- /// Construct a new AnalysisService.
103
- /// </summary>
104
- /// <param name="loggerFactory">Logger factory to create logger instances with.</param>
105
- /// <param name="languageServer">The LSP language server for notifications.</param>
106
- /// <param name="configurationService">The configuration service to query for configurations.</param>
107
- /// <param name="workspaceService">The workspace service for file handling within a workspace.</param>
108
103
public AnalysisService (
109
104
ILoggerFactory loggerFactory ,
110
105
ILanguageServerFacade languageServer ,
111
106
ConfigurationService configurationService ,
112
- WorkspaceService workspaceService )
107
+ WorkspaceService workspaceService ,
108
+ HostStartupInfo hostInfo )
113
109
{
114
110
_loggerFactory = loggerFactory ;
115
111
_logger = loggerFactory . CreateLogger < AnalysisService > ( ) ;
@@ -119,6 +115,7 @@ public AnalysisService(
119
115
_analysisDelayMillis = 750 ;
120
116
_mostRecentCorrectionsByFile = new ConcurrentDictionary < ScriptFile , CorrectionTableEntry > ( ) ;
121
117
_analysisEngineLazy = new Lazy < PssaCmdletAnalysisEngine > ( InstantiateAnalysisEngine ) ;
118
+ _pssaModulePath = Path . Combine ( hostInfo . BundledModulePath , "PSScriptAnalyzer" ) ;
122
119
_pssaSettingsFilePath = null ;
123
120
}
124
121
@@ -202,7 +199,7 @@ public async Task<string> GetCommentHelpText(string functionText, string helpLoc
202
199
return null ;
203
200
}
204
201
205
- Hashtable commentHelpSettings = AnalysisService . GetCommentHelpRuleSettings ( helpLocation , forBlockComment ) ;
202
+ Hashtable commentHelpSettings = GetCommentHelpRuleSettings ( helpLocation , forBlockComment ) ;
206
203
207
204
ScriptFileMarker [ ] analysisResults = await AnalysisEngine . AnalyzeScriptAsync ( functionText , commentHelpSettings ) . ConfigureAwait ( false ) ;
208
205
@@ -285,7 +282,7 @@ private void InitializeAnalysisEngineToCurrentSettings()
285
282
_analysisEngineLazy = new Lazy < PssaCmdletAnalysisEngine > ( ( ) => RecreateAnalysisEngine ( currentAnalysisEngine ) ) ;
286
283
}
287
284
288
- private PssaCmdletAnalysisEngine InstantiateAnalysisEngine ( )
285
+ internal PssaCmdletAnalysisEngine InstantiateAnalysisEngine ( )
289
286
{
290
287
PssaCmdletAnalysisEngine . Builder pssaCmdletEngineBuilder = new ( _loggerFactory ) ;
291
288
@@ -302,7 +299,7 @@ private PssaCmdletAnalysisEngine InstantiateAnalysisEngine()
302
299
pssaCmdletEngineBuilder . WithIncludedRules ( s_defaultRules ) ;
303
300
}
304
301
305
- return pssaCmdletEngineBuilder . Build ( ) ;
302
+ return pssaCmdletEngineBuilder . Build ( _pssaModulePath ) ;
306
303
}
307
304
308
305
private PssaCmdletAnalysisEngine RecreateAnalysisEngine ( PssaCmdletAnalysisEngine oldAnalysisEngine )
@@ -320,15 +317,15 @@ private PssaCmdletAnalysisEngine RecreateAnalysisEngine(PssaCmdletAnalysisEngine
320
317
321
318
private bool TryFindSettingsFile ( out string settingsFilePath )
322
319
{
323
- string configuredPath = _configurationService . CurrentSettings . ScriptAnalysis . SettingsPath ;
320
+ string configuredPath = _configurationService ? . CurrentSettings . ScriptAnalysis . SettingsPath ;
324
321
325
322
if ( string . IsNullOrEmpty ( configuredPath ) )
326
323
{
327
324
settingsFilePath = null ;
328
325
return false ;
329
326
}
330
327
331
- settingsFilePath = _workspaceService . ResolveWorkspacePath ( configuredPath ) ;
328
+ settingsFilePath = _workspaceService ? . ResolveWorkspacePath ( configuredPath ) ;
332
329
333
330
if ( settingsFilePath == null
334
331
|| ! File . Exists ( settingsFilePath ) )
0 commit comments