Skip to content

Commit

Permalink
Refactored GetAssociatedPythonProject function.
Browse files Browse the repository at this point in the history
  • Loading branch information
zooba committed May 26, 2016
1 parent bc631c2 commit 2c69ea7
Showing 1 changed file with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,38 @@ internal virtual void OnConnected() { }
internal virtual void OnAttach() { }
internal virtual void OnDetach() { }

private PythonProjectNode GetAssociatedPythonProject(InterpreterConfiguration interpreter = null) {
var moniker = ProjectMoniker;
if (interpreter == null) {
interpreter = Configuration?.Interpreter;
}

if (string.IsNullOrEmpty(moniker) && interpreter != null) {
var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();
moniker = interpreterService.GetProperty(interpreter.Id, "ProjectMoniker") as string;
}

if (string.IsNullOrEmpty(moniker)) {
return null;
}

return _serviceProvider.GetProjectFromFile(moniker);
}


public VsProjectAnalyzer Analyzer {
get {
if (_analyzer != null) {
return _analyzer;
}

var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();
var config = Configuration;

if (config == null) {
_analyzer = _serviceProvider.GetPythonToolsService().DefaultAnalyzer;
} else {
Build.Evaluation.Project projectFile = null;
var moniker = ProjectMoniker ??
interpreterService.GetProperty(config.Interpreter.Id, "ProjectMoniker") as string;
if (!string.IsNullOrEmpty(moniker)) {
projectFile = _serviceProvider.GetProjectFromFile(moniker)?.BuildProject;
}
var projectFile = GetAssociatedPythonProject(config.Interpreter)?.BuildProject;
var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();
_analyzer = new VsProjectAnalyzer(
_serviceProvider,
interpreterService.FindInterpreter(config.Interpreter.Id),
Expand Down Expand Up @@ -359,18 +373,7 @@ protected virtual async Task ExecuteStartupScripts(string scriptsPath) {
}

internal void UpdatePropertiesFromProjectMoniker() {
var moniker = ProjectMoniker;
var interpreter = Configuration?.Interpreter;
if (interpreter != null && string.IsNullOrEmpty(moniker)) {
var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterRegistryService>();
moniker = interpreterService?.GetProperty(Configuration.Interpreter.Id, "ProjectMoniker") as string;
}

if (string.IsNullOrEmpty(moniker)) {
return;
}

var pyProj = _serviceProvider.GetProjectFromFile(moniker)?.GetPythonProject();
var pyProj = GetAssociatedPythonProject();
if (pyProj == null) {
return;
}
Expand Down

0 comments on commit 2c69ea7

Please sign in to comment.