Skip to content

Commit 2c69ea7

Browse files
committed
Refactored GetAssociatedPythonProject function.
1 parent bc631c2 commit 2c69ea7

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

Python/Product/PythonTools/PythonTools/Repl/PythonInteractiveEvaluator.cs

+22-19
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,38 @@ internal virtual void OnConnected() { }
122122
internal virtual void OnAttach() { }
123123
internal virtual void OnDetach() { }
124124

125+
private PythonProjectNode GetAssociatedPythonProject(InterpreterConfiguration interpreter = null) {
126+
var moniker = ProjectMoniker;
127+
if (interpreter == null) {
128+
interpreter = Configuration?.Interpreter;
129+
}
130+
131+
if (string.IsNullOrEmpty(moniker) && interpreter != null) {
132+
var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();
133+
moniker = interpreterService.GetProperty(interpreter.Id, "ProjectMoniker") as string;
134+
}
135+
136+
if (string.IsNullOrEmpty(moniker)) {
137+
return null;
138+
}
139+
140+
return _serviceProvider.GetProjectFromFile(moniker);
141+
}
142+
143+
125144
public VsProjectAnalyzer Analyzer {
126145
get {
127146
if (_analyzer != null) {
128147
return _analyzer;
129148
}
130149

131-
var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();
132150
var config = Configuration;
133151

134152
if (config == null) {
135153
_analyzer = _serviceProvider.GetPythonToolsService().DefaultAnalyzer;
136154
} else {
137-
Build.Evaluation.Project projectFile = null;
138-
var moniker = ProjectMoniker ??
139-
interpreterService.GetProperty(config.Interpreter.Id, "ProjectMoniker") as string;
140-
if (!string.IsNullOrEmpty(moniker)) {
141-
projectFile = _serviceProvider.GetProjectFromFile(moniker)?.BuildProject;
142-
}
155+
var projectFile = GetAssociatedPythonProject(config.Interpreter)?.BuildProject;
156+
var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();
143157
_analyzer = new VsProjectAnalyzer(
144158
_serviceProvider,
145159
interpreterService.FindInterpreter(config.Interpreter.Id),
@@ -359,18 +373,7 @@ protected virtual async Task ExecuteStartupScripts(string scriptsPath) {
359373
}
360374

361375
internal void UpdatePropertiesFromProjectMoniker() {
362-
var moniker = ProjectMoniker;
363-
var interpreter = Configuration?.Interpreter;
364-
if (interpreter != null && string.IsNullOrEmpty(moniker)) {
365-
var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();
366-
moniker = interpreterService?.GetProperty(Configuration.Interpreter.Id, "ProjectMoniker") as string;
367-
}
368-
369-
if (string.IsNullOrEmpty(moniker)) {
370-
return;
371-
}
372-
373-
var pyProj = _serviceProvider.GetProjectFromFile(moniker)?.GetPythonProject();
376+
var pyProj = GetAssociatedPythonProject();
374377
if (pyProj == null) {
375378
return;
376379
}

0 commit comments

Comments
 (0)