private void TraverseThroughAllTheProjectFiles(TokenParameter parameter, IFindReferenceProgress findReferenceProgressListener, Func <string, string, ISemanticModel, CommonSyntaxNode, bool> visitorAction) { findReferenceProgressListener.OnFindReferenceStarted(); var projectCodeDirectory = new DirectoryInfo(this.applicationConfigurationProvider.GetProjectSourceCodePath(parameter.Username, parameter.Project)); var solutionPath = FindSolutionPath(parameter.Username, parameter.Project); if (solutionPath == null) { findReferenceProgressListener.OnFindReferenceCompleted(0); return; } findReferenceProgressListener.OnFindReferenceInProgress(); var workspace = Roslyn.Services.Workspace.LoadSolution(solutionPath); var currentFilePath = Path.Combine(projectCodeDirectory.FullName, parameter.Path.Replace(@"/", @"\")); var solution = workspace.CurrentSolution; foreach (var project in solution.Projects) { try { bool processingCompleted = false; if (!project.HasDocuments) { continue; } foreach (var document in project.Documents) { var documentSemanticModel = document.GetSemanticModel(); var findReferenceSyntaxtWalker = new FindReferenceSyntaxWalker(); CommonSyntaxNode syntaxRoot = null; if (documentSemanticModel.SyntaxTree.TryGetRoot(out syntaxRoot)) { var documentRelativePath = new Uri(projectCodeDirectory.FullName + Path.DirectorySeparatorChar).MakeRelativeUri(new Uri(document.FilePath)).ToString(); processingCompleted = visitorAction(document.Name, documentRelativePath, documentSemanticModel, syntaxRoot); if (processingCompleted) { break; } } } if (processingCompleted) { break; } } catch (Exception ex) { this.logger.Error(ex, "An error has occured while loading the project {0}", project.Name); } } }
public List<FindReferenceResult> FindRefernces(FindReferenceParameter parameter, IFindReferenceProgress findReferenceProgressListener) { var result = new List<FindReferenceResult>(); var findReferenceSyntaxWalker = new FindReferenceSyntaxWalker(); TraverseThroughAllTheProjectFiles(parameter, findReferenceProgressListener, (documentName, documentRelativePath, syntaxRoot) => { findReferenceSyntaxWalker.DoVisit(syntaxRoot, parameter.Text, (foundlocation) => { result.Add(new FindReferenceResult { FileName = documentName, Path = documentRelativePath, Position = foundlocation }); }); }); findReferenceProgressListener.OnFindReferenceCompleted(result.Count); return result; }
public List <TokenResult> FindRefernces(TokenParameter parameter, IFindReferenceProgress findReferenceProgressListener) { var result = new List <TokenResult>(); var findReferenceSyntaxWalker = new FindReferenceSyntaxWalker(); TraverseThroughAllTheProjectFiles(parameter, findReferenceProgressListener, (documentName, documentRelativePath, semanticModel, syntaxRoot) => { findReferenceSyntaxWalker.DoVisit(syntaxRoot, parameter.Text, (foundlocation) => { result.Add(new TokenResult { FileName = documentName, Path = documentRelativePath, Position = foundlocation }); }); return(false); }); findReferenceProgressListener.OnFindReferenceCompleted(result.Count); return(result); }
private void TraverseThroughAllTheProjectFiles(TokenParameter parameter, IFindReferenceProgress findReferenceProgressListener, Func< string, string, ISemanticModel, CommonSyntaxNode, bool> visitorAction) { findReferenceProgressListener.OnFindReferenceStarted(); var projectCodeDirectory = new DirectoryInfo(this.applicationConfigurationProvider.GetProjectSourceCodePath(parameter.Username, parameter.Project)); var solutionPath = FindSolutionPath(parameter.Username, parameter.Project); if (solutionPath == null) { findReferenceProgressListener.OnFindReferenceCompleted(0); return; } findReferenceProgressListener.OnFindReferenceInProgress(); var workspace = Roslyn.Services.Workspace.LoadSolution(solutionPath); var currentFilePath = Path.Combine(projectCodeDirectory.FullName, parameter.Path.Replace(@"/", @"\")); var solution = workspace.CurrentSolution; foreach (var project in solution.Projects) { try { bool processingCompleted = false; if (!project.HasDocuments) { continue; } foreach (var document in project.Documents) { var documentSemanticModel = document.GetSemanticModel(); var findReferenceSyntaxtWalker = new FindReferenceSyntaxWalker(); CommonSyntaxNode syntaxRoot = null; if (documentSemanticModel.SyntaxTree.TryGetRoot(out syntaxRoot)) { var documentRelativePath = new Uri(projectCodeDirectory.FullName + Path.DirectorySeparatorChar).MakeRelativeUri(new Uri(document.FilePath)).ToString(); processingCompleted = visitorAction(document.Name, documentRelativePath,documentSemanticModel, syntaxRoot); if (processingCompleted) { break; } } } if (processingCompleted) { break; } } catch (Exception ex) { this.logger.Error(ex, "An error has occured while loading the project {0}", project.Name); } } }