Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpCompletionContext"/> class.
        /// </summary>
        /// <param name="document">The document, make sure the FileName property is set on the document.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="projectContent">Content of the project.</param>
        /// <param name="usings">The usings.</param>
        /// <param name="variables">The variables</param>
        /// <param name="namespace">The namespace.</param>
        public CSharpCompletionContext(IDocument document, int offset, IProjectContent projectContent, string usings = null, string variables = null, string @namespace = null)
        {
            OriginalDocument  = document;
            OriginalOffset    = offset;
            OriginalUsings    = usings;
            OriginalVariables = variables;
            OriginalNamespace = @namespace;

            //if the document is a c# script we have to soround the document with some code.
            Document = PrepareCompletionDocument(document, ref offset, usings, variables, @namespace);
            Offset   = offset;

            var syntaxTree = new CSharpParser().Parse(Document, Document.FileName);

            syntaxTree.Freeze();
            var unresolvedFile = syntaxTree.ToTypeSystem();

            ProjectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
            //note: it's important that the project content is used that is returned after adding the unresolved file
            Compilation = ProjectContent.CreateCompilation();

            var location = Document.GetLocation(Offset);

            Resolver = unresolvedFile.GetResolver(Compilation, location);
            TypeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(Compilation, location);
            CompletionContextProvider = new DefaultCompletionContextProvider(Document, unresolvedFile);
        }
Ejemplo n.º 2
0
        protected ResolveResult Resolve(string code)
        {
            CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", "")), "code.cs");

            TextLocation[] dollars = FindDollarSigns(code).ToArray();
            Assert.AreEqual(2, dollars.Length, "Expected 2 dollar signs marking start+end of desired node");

            SetUp();

            CSharpParsedFile parsedFile = cu.ToTypeSystem();

            project     = project.UpdateProjectContent(null, parsedFile);
            compilation = project.CreateCompilation();

            FindNodeVisitor fnv = new FindNodeVisitor(dollars[0], dollars[1]);

            cu.AcceptVisitor(fnv, null);
            Assert.IsNotNull(fnv.ResultNode, "Did not find DOM node at the specified location");

            Debug.WriteLine(new string('=', 70));
            Debug.WriteLine("Starting new resolver for " + fnv.ResultNode);

            CSharpAstResolver resolver = new CSharpAstResolver(compilation, cu, parsedFile);
            ResolveResult     rr       = resolver.Resolve(fnv.ResultNode);

            Assert.IsNotNull(rr, "ResolveResult is null - did something go wrong while navigating to the target node?");
            Debug.WriteLine("ResolveResult is " + rr);
            return(rr);
        }
Ejemplo n.º 3
0
 private void CompileAndResolve()
 {
     _unresolvedFile = SyntaxTree.ToTypeSystem();
     _projectContent = _projectContent.AddOrUpdateFiles(_unresolvedFile);
     _compilation    = _projectContent.CreateCompilation();
     _resolver       = new CSharpAstResolver(_compilation, SyntaxTree, _unresolvedFile);
 }
Ejemplo n.º 4
0
        public Common.DomRegion ResolveTypeByName(string typeName, string typeMemberName)
        {
            if (Project == null)
            {
                return(Common.DomRegion.Empty);
            }

            var code     = $"class dummy11111 {{ System.Type t = typeof({typeName}); }}";
            var location = new ReadOnlyDocument(code).GetLocation(code.Length - 6);

            var syntaxTree = new CSharpParser().Parse(code, "dummy11111.cs");

            syntaxTree.Freeze();
            var unresolvedFile = syntaxTree.ToTypeSystem();

            Project = Project.AddOrUpdateFiles(unresolvedFile);

            var compilation = Project.CreateCompilation();

            var result = ResolveAtLocation.Resolve(compilation, unresolvedFile, syntaxTree, location);

            var type = (result as TypeResolveResult).Type as DefaultResolvedTypeDefinition;

            if (type != null)
            {
                var asm = type.ParentAssembly;
                if (asm.UnresolvedAssembly is IUnresolvedAssembly) //referenced assembly
                {
                    FileLocation document = new Reflector().ReconstructToFile(asm, type, memberName: typeMemberName);
                    return(document.ToDomRegion().ToCommon());
                }
            }

            return(Common.DomRegion.Empty);
        }
        void Init(string program)
        {
            pc             = new CSharpProjectContent();
            pc             = pc.SetAssemblyName("MyAssembly");
            unresolvedFile = SyntaxTree.Parse(program, "program.cs").ToTypeSystem();
            pc             = pc.AddOrUpdateFiles(unresolvedFile);
            pc             = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib });

            compilation = pc.CreateCompilation();
        }
Ejemplo n.º 6
0
		void Init(string program)
		{
			pc = new CSharpProjectContent();
			pc = pc.SetAssemblyName("MyAssembly");
			unresolvedFile = SyntaxTree.Parse(program, "program.cs").ToTypeSystem();
			pc = pc.AddOrUpdateFiles(unresolvedFile);
			pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib });
			
			compilation = pc.CreateCompilation();
		}
		public virtual void SetUp()
		{
			SD.InitializeForUnitTests();
			project = MockRepository.GenerateStrictMock<IProject>();
			project.Stub(p => p.RootNamespace).Return("RootNamespace");
			testProject = new NUnitTestProject(project);
			projectContent = new CSharpProjectContent().AddAssemblyReferences(NRefactoryHelper.Corlib, NRefactoryHelper.NUnitFramework);
			
			SD.Services.AddStrictMockService<IParserService>();
			SD.ParserService.Stub(p => p.GetCompilation(project)).WhenCalled(m => m.ReturnValue = projectContent.CreateCompilation());
		}
Ejemplo n.º 8
0
        public void SetUp()
        {
            SD.InitializeForUnitTests();
            SD.Services.AddService(typeof(IParserService), MockRepository.GenerateStrictMock <IParserService>());
            project        = MockRepository.GenerateStrictMock <IProject>();
            projectContent = new CSharpProjectContent();

            SD.ParserService
            .Stub(p => p.GetCompilation(project))
            .WhenCalled(c => c.ReturnValue = projectContent.CreateCompilation());
        }
Ejemplo n.º 9
0
		public void SetUp()
		{
			SD.InitializeForUnitTests();
			SD.Services.AddService(typeof(IParserService), MockRepository.GenerateStrictMock<IParserService>());
			project = MockRepository.GenerateStrictMock<IProject>();
			projectContent = new CSharpProjectContent();
			
			SD.ParserService
				.Stub(p => p.GetCompilation(project))
				.WhenCalled(c => c.ReturnValue = projectContent.CreateCompilation());
		}
        public ICompilation GetCompilation(IProjectContent project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (!dictionary.ContainsKey(project))
            {
                dictionary[project] = project.CreateCompilation(this);
            }

            return(dictionary[project]);
        }
Ejemplo n.º 11
0
        private void AddOrUpdateFiles()
        {
            typeSystemCache.Clear();
            var unresolvedFiles = new IUnresolvedFile[sourceFiles.Count];

            Parallel.For(0, unresolvedFiles.Length, i =>
            {
                var syntaxTree     = sourceFiles[i].SyntaxTree;
                unresolvedFiles[i] = GetTypeSystem(syntaxTree);
            });

            project     = project.AddOrUpdateFiles(unresolvedFiles);
            compilation = project.CreateCompilation();
        }
Ejemplo n.º 12
0
		public void SetUp()
		{
			pc = new CSharpProjectContent();
			pc = pc.SetAssemblyName("MyAssembly");
			parsedFile = new CSharpParser().Parse(new StringReader(program), "program.cs").ToTypeSystem();
			pc = pc.UpdateProjectContent(null, parsedFile);
			pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib });
			
			compilation = pc.CreateCompilation();
			
			baseClass = compilation.RootNamespace.GetTypeDefinition("Base", 1);
			nestedClass = baseClass.NestedTypes.Single();
			derivedClass = compilation.RootNamespace.GetTypeDefinition("Derived", 2);
			systemClass = compilation.FindType("NS.System, MyAssembly").GetDefinition();
		}
        public void SetUp()
        {
            pc         = new CSharpProjectContent();
            pc         = pc.SetAssemblyName("MyAssembly");
            parsedFile = new CSharpParser().Parse(new StringReader(program), "program.cs").ToTypeSystem();
            pc         = pc.UpdateProjectContent(null, parsedFile);
            pc         = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib });

            compilation = pc.CreateCompilation();

            baseClass    = compilation.RootNamespace.GetTypeDefinition("Base", 1);
            nestedClass  = baseClass.NestedTypes.Single();
            derivedClass = compilation.RootNamespace.GetTypeDefinition("Derived", 2);
            systemClass  = compilation.RootNamespace.GetChildNamespace("NS").GetTypeDefinition("System", 0);
        }
Ejemplo n.º 14
0
		public void SetUp()
		{
			pc = new CSharpProjectContent();
			pc = pc.SetAssemblyName("MyAssembly");
			unresolvedFile = SyntaxTree.Parse(program, "program.cs").ToTypeSystem();
			pc = pc.AddOrUpdateFiles(unresolvedFile);
			pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib });
			
			compilation = pc.CreateCompilation();
			
			baseClass = compilation.RootNamespace.GetTypeDefinition("Base", 1);
			nestedClass = baseClass.NestedTypes.Single();
			derivedClass = compilation.RootNamespace.GetTypeDefinition("Derived", 2);
			systemClass = compilation.RootNamespace.GetChildNamespace("NS").GetTypeDefinition("System", 0);
		}
Ejemplo n.º 15
0
        IEnumerable <Common.ICompletionData> GetCSharpCompletionData(ReadOnlyDocument doc, string editorText, int offset, string fileName, bool isControlSpace = true) // not the best way to put in the whole string every time
        {
            if (editorText[offset] != '.')                                                                                                                             //we may be at the partially complete word
            {
                for (int i = offset - 1; i >= 0; i--)
                {
                    if (SimpleCodeCompletion.Delimiters.Contains(editorText[i]))
                    {
                        offset = i + 1;
                        break;
                    }
                }
            }

            //test for C# completion
            var location = doc.GetLocation(offset);

            var syntaxTree = new CSharpParser().Parse(editorText, fileName);

            syntaxTree.Freeze();
            var unresolvedFile = syntaxTree.ToTypeSystem();

            Project = Project.AddOrUpdateFiles(unresolvedFile);

            //note project should be reassigned/recreated every time we add asms or file

            //IProjectContent project = new CSharpProjectContent();
            //project = project.AddAssemblyReferences(builtInLibs.Value);
            //project = project.AddOrUpdateFiles(unresolvedFile);

            //IProjectContent project = new CSharpProjectContent().AddAssemblyReferences(builtInLibs.Value).AddOrUpdateFiles(unresolvedFile);

            var completionContextProvider = new DefaultCompletionContextProvider(doc, unresolvedFile);

            var compilation = Project.CreateCompilation();
            var resolver    = unresolvedFile.GetResolver(compilation, location);

            var engine = new CSharpCompletionEngine(doc,
                                                    completionContextProvider,
                                                    new SimpleCompletionDataFactory(resolver),
                                                    Project,
                                                    resolver.CurrentTypeResolveContext);

            var data = engine.GetCompletionData(offset, isControlSpace);

            return(data.PrepareForDisplay().ToCommon());
        }
Ejemplo n.º 16
0
        protected ResolveResult ResolveAtLocation(string code)
        {
            CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", "")), "test.cs");

            TextLocation[] dollars = FindDollarSigns(code).ToArray();
            Assert.AreEqual(1, dollars.Length, "Expected 1 dollar signs marking the location");

            SetUp();

            CSharpParsedFile parsedFile = cu.ToTypeSystem();

            project     = project.UpdateProjectContent(null, parsedFile);
            compilation = project.CreateCompilation();

            ResolveResult rr = Resolver.ResolveAtLocation.Resolve(compilation, parsedFile, cu, dollars[0]);

            return(rr);
        }
Ejemplo n.º 17
0
        protected Tuple <CSharpAstResolver, AstNode> PrepareResolver(string code)
        {
            CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", "")), "code.cs");

            TextLocation[] dollars = FindDollarSigns(code).ToArray();
            Assert.AreEqual(2, dollars.Length, "Expected 2 dollar signs marking start+end of desired node");

            SetUp();

            CSharpParsedFile parsedFile = cu.ToTypeSystem();

            project     = project.UpdateProjectContent(null, parsedFile);
            compilation = project.CreateCompilation();

            CSharpAstResolver resolver = new CSharpAstResolver(compilation, cu, parsedFile);

            return(Tuple.Create(resolver, FindNode(cu, dollars[0], dollars[1])));
        }
Ejemplo n.º 18
0
        protected ResolveResult ResolveAtLocation(string code)
        {
            SyntaxTree syntaxTree = SyntaxTree.Parse(code.Replace("$", ""), "test.cs");

            TextLocation[] dollars = FindDollarSigns(code).ToArray();
            Assert.AreEqual(1, dollars.Length, "Expected 1 dollar signs marking the location");

            SetUp();

            CSharpUnresolvedFile unresolvedFile = syntaxTree.ToTypeSystem();

            project     = project.AddOrUpdateFiles(unresolvedFile);
            compilation = project.CreateCompilation();

            ResolveResult rr = Resolver.ResolveAtLocation.Resolve(compilation, unresolvedFile, syntaxTree, dollars[0]);

            return(rr);
        }
Ejemplo n.º 19
0
        protected Tuple <CSharpAstResolver, AstNode> PrepareResolver(string code)
        {
            SyntaxTree syntaxTree = new CSharpParser().Parse(code.Replace("$", ""), "code.cs");

            TextLocation[] dollars = FindDollarSigns(code).ToArray();
            Assert.AreEqual(2, dollars.Length, "Expected 2 dollar signs marking start+end of desired node");

            SetUp();

            CSharpUnresolvedFile unresolvedFile = syntaxTree.ToTypeSystem();

            project     = project.AddOrUpdateFiles(unresolvedFile);
            compilation = project.CreateCompilation();

            CSharpAstResolver resolver = new CSharpAstResolver(compilation, syntaxTree, unresolvedFile);

            return(Tuple.Create(resolver, FindNode(syntaxTree, dollars[0], dollars[1])));
        }
Ejemplo n.º 20
0
        ResolveResult ResolveFromPosition(string editorText, int offset, string fileName)
        {
            if (Project == null)
            {
                return(null);
            }

            var location = new ReadOnlyDocument(editorText).GetLocation(offset);

            var syntaxTree = new CSharpParser().Parse(editorText, fileName);

            syntaxTree.Freeze();
            var unresolvedFile = syntaxTree.ToTypeSystem();

            Project = Project.AddOrUpdateFiles(unresolvedFile);

            var compilation = Project.CreateCompilation();

            return(ResolveAtLocation.Resolve(compilation, unresolvedFile, syntaxTree, location));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpCompletionContext"/> class.
        /// </summary>
        /// <param name="document">The document, make sure the FileName property is set on the document.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="projectContent">Content of the project.</param>
        /// <param name="usings">The usings.</param>
        public CSharpCompletionContext(IDocument document, int offset, IProjectContent projectContent, string usings = null)
        {
            OriginalDocument = document;
            OriginalOffset = offset;

            //if the document is a c# script we have to soround the document with some code.
            Document = PrepareCompletionDocument(document, ref offset, usings);
            Offset = offset;

            var syntaxTree = new CSharpParser().Parse(Document, Document.FileName);
            syntaxTree.Freeze();
            var unresolvedFile = syntaxTree.ToTypeSystem();

            ProjectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
            //note: it's important that the project content is used that is returned after adding the unresolved file
            Compilation = ProjectContent.CreateCompilation();

            var location = Document.GetLocation(Offset);
            Resolver = unresolvedFile.GetResolver(Compilation, location);
            TypeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(Compilation, location);
            CompletionContextProvider = new DefaultCompletionContextProvider(Document, unresolvedFile);
        }
Ejemplo n.º 22
0
        protected Tuple <CSharpAstResolver, AstNode> PrepareResolver(string code)
        {
            CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", "")), "code.cs");

            TextLocation[] dollars = FindDollarSigns(code).ToArray();
            Assert.AreEqual(2, dollars.Length, "Expected 2 dollar signs marking start+end of desired node");

            SetUp();

            CSharpParsedFile parsedFile = cu.ToTypeSystem();

            project     = project.UpdateProjectContent(null, parsedFile);
            compilation = project.CreateCompilation();

            FindNodeVisitor fnv = new FindNodeVisitor(dollars[0], dollars[1]);

            cu.AcceptVisitor(fnv, null);
            Assert.IsNotNull(fnv.ResultNode, "Did not find DOM node at the specified location");

            CSharpAstResolver resolver = new CSharpAstResolver(compilation, cu, parsedFile);

            return(Tuple.Create(resolver, fnv.ResultNode));
        }
Ejemplo n.º 23
0
        public async Task LoadTypesAsync()
        {
            if (OnlyCountLines)
            {
                return;
            }
            await Task.Factory.StartNew(() =>
            {
                if (_projectContent == null)
                {
                    return;
                }
                var ownCodeAssemblyNames = new HashSet <string>(_solution.Projects.Select(p => p._assemblyName));
                foreach (var cSharpFile in _files.Where(f => f.FileExists))
                {
                    _compilation    = _projectContent.CreateCompilation(_solution.Snapshot);
                    var resolver    = cSharpFile.CreateResolver();
                    var typeBuilder = new TypeSystemBuilder(resolver, _solution.Nodes, _solution.Edges, ownCodeAssemblyNames);
                    cSharpFile.AcceptAstVisitor(typeBuilder);
                }
            });

            ProgressPercentage = 50;
        }
Ejemplo n.º 24
0
		public override IEnumerable<MemberReference> FindReferences (Project project, IProjectContent content, IEnumerable<FilePath> possibleFiles, IEnumerable<object> members)
		{
			if (project == null)
				throw new ArgumentNullException ("project", "Project not set.");
			if (content == null)
				throw new ArgumentNullException ("content", "Project content not set.");
			SetPossibleFiles (possibleFiles);
			SetSearchedMembers (members);
			
			var scopes = searchedMembers.Select (e => refFinder.GetSearchScopes (e as IEntity));
			var compilation = TypeSystemService.GetCompilation (project);
			List<MemberReference> refs = new List<MemberReference> ();
			foreach (var opendoc in openDocuments) {
				foreach (var newRef in FindInDocument (opendoc.Item2)) {
					if (newRef == null || refs.Any (r => r.FileName == newRef.FileName && r.Region == newRef.Region))
						continue;
					refs.Add (newRef);
				}
			}
			
			foreach (var file in files) {
				string text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText (file);
				if (memberName != null && text.IndexOf (memberName, StringComparison.Ordinal) < 0 &&
					(keywordName == null || text.IndexOf (keywordName, StringComparison.Ordinal) < 0))
					continue;
				using (var editor = TextEditorData.CreateImmutable (text)) {
					editor.Document.FileName = file;
					var unit = new CSharpParser ().Parse (editor);
					if (unit == null)
						continue;
					
					var storedFile = content.GetFile (file);
					var parsedFile = storedFile as CSharpParsedFile;
					
					if (parsedFile == null && storedFile is ParsedDocumentDecorator) {
						parsedFile = ((ParsedDocumentDecorator)storedFile).ParsedFile as CSharpParsedFile;
					}
					
					if (parsedFile == null) {
						// for fallback purposes - should never happen.
						parsedFile = unit.ToTypeSystem ();
						content = content.UpdateProjectContent (content.GetFile (file), parsedFile);
						compilation = content.CreateCompilation ();
					}
					foreach (var scope in scopes) {
						refFinder.FindReferencesInFile (
							scope,
							parsedFile,
							unit,
							compilation,
							(astNode, result) => {
								var newRef = GetReference (result, astNode, file, editor);
								if (newRef == null || refs.Any (r => r.FileName == newRef.FileName && r.Region == newRef.Region))
									return;
								refs.Add (newRef);
							},
							CancellationToken.None
						);
					}
				}
			}
			return refs;
		}
        public virtual void SetUp()
        {
            SD.InitializeForUnitTests();
            project = MockRepository.GenerateStrictMock <IProject>();
            project.Stub(p => p.RootNamespace).Return("RootNamespace");
            testProject    = new NUnitTestProject(project);
            projectContent = new CSharpProjectContent().AddAssemblyReferences(NRefactoryHelper.Corlib, NRefactoryHelper.NUnitFramework);

            SD.Services.AddStrictMockService <IParserService>();
            SD.ParserService.Stub(p => p.GetCompilation(project)).WhenCalled(m => m.ReturnValue = projectContent.CreateCompilation());
        }
Ejemplo n.º 26
0
 public virtual void SetUp()
 {
     project     = new CSharpProjectContent().AddAssemblyReferences(new [] { mscorlib, CecilLoaderTests.SystemCore });
     compilation = project.CreateCompilation();
 }
Ejemplo n.º 27
0
        protected ITypeDefinition GetFirstTypeDefinition()
        {
            ICompilation compilation = projectContent.CreateCompilation();

            return(compilation.MainAssembly.TopLevelTypeDefinitions.First());
        }
        public virtual void SetUp()
        {
            SD.InitializeForUnitTests();
            SD.Services.AddStrictMockService <IParserService>();
            project        = MockRepository.GenerateStrictMock <IProject>();
            projectContent = new CSharpProjectContent().AddAssemblyReferences(AssemblyLoader.Corlib);
            context        = new ProjectEntityModelContext(project, ".cs");
            assemblyModel  = new AssemblyModel(context);

            SD.ParserService.Stub(p => p.GetCompilation(project)).WhenCalled(c => c.ReturnValue = projectContent.CreateCompilation());
        }
Ejemplo n.º 29
0
 private void CompileAndResolve()
 {
     _unresolvedFile = SyntaxTree.ToTypeSystem();
     _projectContent = _projectContent.AddOrUpdateFiles(_unresolvedFile);
     _compilation = _projectContent.CreateCompilation();
     _resolver = new CSharpAstResolver(_compilation, SyntaxTree, _unresolvedFile);
 }
        public override IEnumerable <MemberReference> FindReferences(Project project, IProjectContent content, IEnumerable <FilePath> possibleFiles, IProgressMonitor monitor, IEnumerable <object> members)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content", "Project content not set.");
            }
            SetPossibleFiles(possibleFiles);
            SetSearchedMembers(members);

            var scopes      = searchedMembers.Select(e => e is IEntity ? refFinder.GetSearchScopes((IEntity)e) : refFinder.GetSearchScopes((INamespace)e));
            var compilation = project != null?TypeSystemService.GetCompilation(project) : content.CreateCompilation();

            List <MemberReference> refs = new List <MemberReference> ();

            foreach (var opendoc in openDocuments)
            {
                foreach (var newRef in FindInDocument(opendoc.Item2))
                {
                    if (newRef == null || refs.Any(r => r.FileName == newRef.FileName && r.Region == newRef.Region))
                    {
                        continue;
                    }
                    refs.Add(newRef);
                }
            }
            foreach (var file in files)
            {
                if (monitor != null)
                {
                    monitor.Step(1);
                }
                string text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText(file);
                if (memberName != null && text.IndexOf(memberName, StringComparison.Ordinal) < 0 &&
                    (keywordName == null || text.IndexOf(keywordName, StringComparison.Ordinal) < 0))
                {
                    continue;
                }
                using (var editor = TextEditorData.CreateImmutable(text)) {
                    editor.Document.FileName = file;
                    var unit = new PlayScriptParser().Parse(editor);
                    if (unit == null)
                    {
                        continue;
                    }

                    var storedFile = content.GetFile(file);
                    var parsedFile = storedFile as CSharpUnresolvedFile;

                    if (parsedFile == null && storedFile is ParsedDocumentDecorator)
                    {
                        parsedFile = ((ParsedDocumentDecorator)storedFile).ParsedFile as CSharpUnresolvedFile;
                    }

                    if (parsedFile == null)
                    {
                        // for fallback purposes - should never happen.
                        parsedFile  = unit.ToTypeSystem();
                        content     = content.AddOrUpdateFiles(parsedFile);
                        compilation = content.CreateCompilation();
                    }
                    foreach (var scope in scopes)
                    {
                        refFinder.FindReferencesInFile(
                            scope,
                            parsedFile,
                            unit,
                            compilation,
                            (astNode, result) => {
                            var newRef = GetReference(project, result, astNode, unit, file, editor);
                            if (newRef == null || refs.Any(r => r.FileName == newRef.FileName && r.Region == newRef.Region))
                            {
                                return;
                            }
                            refs.Add(newRef);
                        },
                            CancellationToken.None
                            );
                    }
                }
            }
            return(refs);
        }