public SemanticErrorsResponse FindSemanticErrors(Request request) { var clientFilename = request.FileName.ApplyPathReplacementsForClient(); var project = _solution.ProjectContainingFile(request.FileName); project.UpdateFile(request.FileName, request.Buffer); var solutionSnapshot = new DefaultSolutionSnapshot(_solution.Projects.Select(i => i.ProjectContent)); SyntaxTree syntaxTree; if(project.CompilerSettings!=null){ syntaxTree = new CSharpParser(project.CompilerSettings).Parse(request.Buffer, request.FileName); }else{ syntaxTree = new CSharpParser().Parse(request.Buffer, request.FileName); } var resolver = new CSharpAstResolver(solutionSnapshot.GetCompilation(project.ProjectContent), syntaxTree); var navigator = new SemanticErrorsNavigator(); resolver.ApplyNavigator(navigator); var errors = navigator.GetErrors() .Where(e => ShouldIncludeIssue(e.Message)) .Select(i => new Error { FileName = clientFilename, Message = i.Message, Line = i.StartLocation.Line, Column = i.EndLocation.Column, EndLine = i.EndLocation.Line, EndColumn = i.EndLocation.Column }); return new SemanticErrorsResponse { Errors = errors, }; }
public Solution(string fileName) { this.Directory = Path.GetDirectoryName(fileName); var projectLinePattern = new Regex("Project\\(\"(?<TypeGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\""); foreach (string line in File.ReadLines(fileName)) { Match match = projectLinePattern.Match(line); if (match.Success) { string typeGuid = match.Groups["TypeGuid"].Value; string title = match.Groups["Title"].Value; string location = match.Groups["Location"].Value; string guid = match.Groups["Guid"].Value; switch (typeGuid.ToUpperInvariant()) { case "{2150E333-8FDC-42A3-9474-1A3956D46DE8}": // Solution Folder // ignore folders break; case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}": // C# project Projects.Add(new CSharpProject(this, title, Path.Combine(Directory, location))); break; default: Console.WriteLine("Project {0} has unsupported type {1}", location, typeGuid); break; } } } // Create compilations (resolved type systems) after all projects have been loaded. // (we can't do this earlier because project A might have a reference to project B, where A is loaded before B) // To allow NRefactory to resolve project references, we need to use a 'DefaultSolutionSnapshot' // instead of calling CreateCompilation() on each project individually. var solutionSnapshot = new DefaultSolutionSnapshot(this.Projects.Select(p => p.ProjectContent)); foreach (CSharpProject project in this.Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
public SemanticErrorsResponse FindSemanticErrors(Request request) { var clientFilename = request.FileName.ApplyPathReplacementsForClient(); var project = _solution.ProjectContainingFile(request.FileName); project.UpdateFile(request.FileName, request.Buffer); var solutionSnapshot = new DefaultSolutionSnapshot(_solution.Projects.Select(i => i.ProjectContent)); var syntaxTree = new CSharpParser().Parse(request.Buffer, request.FileName); var resolver = new CSharpAstResolver(solutionSnapshot.GetCompilation(project.ProjectContent), syntaxTree); var navigator = new SemanticErrorsNavigator(); resolver.ApplyNavigator(navigator); var errors = navigator.GetErrors().Select(i => new Error { FileName = clientFilename, Message = i.Message, Line = i.TextLocation.Line, Column = i.TextLocation.Column, }); return new SemanticErrorsResponse { Errors = errors, }; }
/// <summary> /// Sets <see cref="CSharpProject.Compilation"/> for every project in /// <see cref="Projects"/>. This is only valid once every project /// is fully loaded. /// </summary> public void RecreateCompilations() { var sw = Stopwatch.StartNew(); var solutionSnapshot = new DefaultSolutionSnapshot(Projects.Select(p => p.ProjectContent)); foreach (CSharpProject project in Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } _log.DebugFormat("Compilation created in [{0}] ms", sw.ElapsedMilliseconds); }
/// <summary> /// TODO: This is an expensive call - create a mechanism to suppress so a Compilations aren't recreated /// multiple times if multiple files are being added /// </summary> public void RecreateCompilations() { var solutionSnapshot = new DefaultSolutionSnapshot(Projects.Select(p => p.ProjectContent)); foreach (CSharpProject project in Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
private void LoadProjectCompilations() { var solutionSnapshot = new DefaultSolutionSnapshot(Projects.Select(p => p.ProjectContent)); foreach (var project in Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
public void CreateCompilationUnitsForAllPojects() { var solutionSnapshot = new DefaultSolutionSnapshot(Projects.Select(project => project.ProjectContent)); foreach(var project in Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }