示例#1
0
		public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested,
		                              IProject parentProject, CancellationToken cancellationToken)
		{
			var csharpProject = parentProject as CSharpProject;
			
			CSharpParser parser = new CSharpParser(csharpProject != null ? csharpProject.CompilerSettings : null);
			
			SyntaxTree cu = parser.Parse(fileContent, fileName);
			cu.Freeze();
			
			CSharpUnresolvedFile file = cu.ToTypeSystem();
			ParseInformation parseInfo;
			
			if (fullParseInformationRequested)
				parseInfo = new CSharpFullParseInformation(file, fileContent.Version, cu);
			else
				parseInfo = new ParseInformation(file, fileContent.Version, fullParseInformationRequested);
			
			IDocument document = fileContent as IDocument;
			AddCommentTags(cu, parseInfo.TagComments, fileContent, parseInfo.FileName, ref document);
			if (fullParseInformationRequested) {
				if (document == null)
					document = new ReadOnlyDocument(fileContent, parseInfo.FileName);
				((CSharpFullParseInformation)parseInfo).newFoldings = CreateNewFoldings(cu, document);
			}
			
			return parseInfo;
		}
示例#2
0
		public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
		{
			var decompiledParseInfo = parseInfo as ILSpyFullParseInformation;
			if (decompiledParseInfo == null)
				throw new ArgumentException("ParseInfo does not have SyntaxTree");
			return ResolveAtLocation.Resolve(compilation, null, decompiledParseInfo.SyntaxTree, location, cancellationToken);
		}
 public ParseInformationEventArgs(IProject parentProject, IUnresolvedFile oldUnresolvedFile, ParseInformation newParseInformation)
 {
     if (oldUnresolvedFile == null && newParseInformation == null)
         throw new ArgumentNullException();
     if (oldUnresolvedFile != null && newParseInformation != null) {
         Debug.Assert(FileUtility.IsEqualFileName(oldUnresolvedFile.FileName, newParseInformation.FileName));
     }
     this.parentProject = parentProject;
     this.oldUnresolvedFile = oldUnresolvedFile;
     this.newParseInformation = newParseInformation;
 }
		public void UpdateFoldings(ParseInformation parseInfo)
		{
			if (!textArea.Document.Version.Equals(parseInfo.ParsedVersion)) {
				SD.Log.Debug("Folding update ignored; parse information is outdated version");
				return;
			}
			SD.Log.Debug("Update Foldings");
			int firstErrorOffset = -1;
			IEnumerable<NewFolding> newFoldings = parseInfo.GetFoldings(textArea.Document, out firstErrorOffset);
			newFoldings = newFoldings.OrderBy(f => f.StartOffset);
			foldingManager.UpdateFoldings(newFoldings, firstErrorOffset);
		}
示例#5
0
		public ICodeContext ResolveContext(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
		{
			var decompiledParseInfo = parseInfo as ILSpyFullParseInformation;
			if (decompiledParseInfo == null)
				throw new ArgumentException("ParseInfo does not have SyntaxTree");
			var syntaxTree = decompiledParseInfo.SyntaxTree;
			var node = syntaxTree.GetNodeAt(location);
			if (node == null)
				return null; // null result is allowed; the parser service will substitute a dummy context
			var resolver = new CSharpAstResolver(compilation, syntaxTree, null);
			return resolver.GetResolverStateBefore(node);
		}
 public ParseInformationEventArgs(IProject parentProject, IUnresolvedFile oldUnresolvedFile, ParseInformation newParseInformation)
 {
     if (oldUnresolvedFile == null && newParseInformation == null)
     {
         throw new ArgumentNullException();
     }
     if (oldUnresolvedFile != null && newParseInformation != null)
     {
         Debug.Assert(FileUtility.IsEqualFileName(oldUnresolvedFile.FileName, newParseInformation.FileName));
     }
     this.parentProject       = parentProject;
     this.oldUnresolvedFile   = oldUnresolvedFile;
     this.newParseInformation = newParseInformation;
 }
示例#7
0
        ResolveResult IParser.Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
        {
            VB6ParseInformation vpi = (VB6ParseInformation)parseInfo;
            IUnresolvedMember umember = vpi.UnresolvedFile.GetMember(location);
            if (umember != null)
            {
                IMember member = ConvertToMember(umember);
                if (member != null)
                {
                    return new MemberResolveResult(null, member);
                }
            }

            return null;
        }
 public ParserUpdateStepEventArgs(FileName fileName, ITextSource content, ParseInformation parseInformation)
 {
     if (fileName == null)
     {
         throw new ArgumentNullException("fileName");
     }
     if (content == null)
     {
         throw new ArgumentNullException("content");
     }
     if (parseInformation == null)
     {
         throw new ArgumentNullException("parseInformation");
     }
     this.fileName         = fileName;
     this.content          = content;
     this.parseInformation = parseInformation;
 }
示例#9
0
		public ResolveResult ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken)
		{
			var decompiledParseInfo = parseInfo as ILSpyFullParseInformation;
			if (decompiledParseInfo == null)
				throw new ArgumentException("ParseInfo does not have SyntaxTree");
			CSharpAstResolver contextResolver = new CSharpAstResolver(compilation, decompiledParseInfo.SyntaxTree, null);
			var node = decompiledParseInfo.SyntaxTree.GetNodeAt(location);
			CSharpResolver context;
			if (node != null)
				context = contextResolver.GetResolverStateAfter(node, cancellationToken);
			else
				context = new CSharpResolver(compilation);
			CSharpParser parser = new CSharpParser();
			var expr = parser.ParseExpression(codeSnippet);
			if (parser.HasErrors)
				return new ErrorResolveResult(SpecialType.UnknownType, PrintErrorsAsString(parser.Errors), TextLocation.Empty);
			CSharpAstResolver snippetResolver = new CSharpAstResolver(context, expr);
			return snippetResolver.Resolve(expr, cancellationToken);
		}
示例#10
0
		void AddTagComments(AXmlDocument xmlDocument, ParseInformation parseInfo, ITextSource fileContent)
		{
			IDocument document = null;
			foreach (var tag in TreeTraversal.PreOrder<AXmlObject>(xmlDocument, node => node.Children).OfType<AXmlTag>().Where(t => t.IsComment)) {
				int matchLength;
				string commentText = fileContent.GetText(tag.StartOffset, tag.Length);
				int index = commentText.IndexOfAny(TaskListTokens, 0, out matchLength);
				if (index > -1) {
					if (document == null)
						document = fileContent as IDocument ?? new ReadOnlyDocument(fileContent, parseInfo.FileName);
					do {
						TextLocation startLocation = document.GetLocation(tag.StartOffset + index);
						int startOffset = index + tag.StartOffset;
						int endOffset = Math.Min(document.GetLineByOffset(startOffset).EndOffset, tag.EndOffset);
						string content = document.GetText(startOffset, endOffset - startOffset);
						parseInfo.TagComments.Add(new TagComment(content.Substring(0, matchLength), new DomRegion(parseInfo.FileName, startLocation.Line, startLocation.Column), content.Substring(matchLength)));
						index = commentText.IndexOfAny(TaskListTokens, endOffset - tag.StartOffset, out matchLength);
					} while (index > -1);
				}
			}
		}
示例#11
0
		public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested,
		                              IProject parentProject, CancellationToken cancellationToken)
		{
			AXmlParser parser = new AXmlParser();
			AXmlDocument document;
			IncrementalParserState newParserState;
			if (fileContent.Version is OnDiskTextSourceVersion) {
				document = parser.Parse(fileContent, cancellationToken);
				newParserState = null;
			} else {
				document = parser.ParseIncremental(parserState, fileContent, out newParserState, cancellationToken);
			}
			parserState = newParserState;
			XamlUnresolvedFile unresolvedFile = XamlUnresolvedFile.Create(fileName, fileContent, document);
			ParseInformation parseInfo;
			if (fullParseInformationRequested)
				parseInfo = new XamlFullParseInformation(unresolvedFile, document, fileContent.CreateSnapshot());
			else
				parseInfo = new ParseInformation(unresolvedFile, fileContent.Version, false);
			AddTagComments(document, parseInfo, fileContent);
			return parseInfo;
		}
示例#12
0
		public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
		{
			return new XamlAstResolver(compilation, (XamlFullParseInformation)parseInfo)
				.ResolveAtLocation(location, cancellationToken);
		}
示例#13
0
		public void FindLocalReferences(ParseInformation parseInfo, ITextSource fileContent, IVariable variable, ICompilation compilation, Action<SearchResultMatch> callback, CancellationToken cancellationToken)
		{
			throw new NotImplementedException();
		}
 public ProjectEntry(IProject project, IUnresolvedFile unresolvedFile, ParseInformation cachedParseInformation)
 {
     this.Project                = project;
     this.UnresolvedFile         = unresolvedFile;
     this.CachedParseInformation = cachedParseInformation;
 }
示例#15
0
		public void ParseInformationUpdated(ParseInformation parseInfo)
		{
			if (parseInfo != null && CodeEditorOptions.Instance.EnableQuickClassBrowser) {
				// don't create quickClassBrowser for files that don't have any classes
				// (but do keep the quickClassBrowser when the last class is removed from a file)
				if (quickClassBrowser != null || parseInfo.UnresolvedFile.TopLevelTypeDefinitions.Count > 0) {
					if (quickClassBrowser == null) {
						quickClassBrowser = new QuickClassBrowser();
						quickClassBrowser.JumpAction = (line, col) => ActiveTextEditor.JumpTo(line, col);
						SetRow(quickClassBrowser, 0);
						this.Children.Add(quickClassBrowser);
					}
					quickClassBrowser.Update(parseInfo.UnresolvedFile);
					quickClassBrowser.SelectItemAtCaretPosition(this.ActiveTextEditor.TextArea.Caret.Location);
				}
			} else {
				if (quickClassBrowser != null) {
					this.Children.Remove(quickClassBrowser);
					quickClassBrowser = null;
				}
			}
			iconBarManager.UpdateClassMemberBookmarks(parseInfo != null ? parseInfo.UnresolvedFile : null, document);
			primaryTextEditor.UpdateParseInformationForFolding(parseInfo);
		}
示例#16
0
 ResolveResult IParser.ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
		public void RegisterUnresolvedFile(IProject project, IUnresolvedFile unresolvedFile)
		{
			if (project == null)
				throw new ArgumentNullException("project");
			if (unresolvedFile == null)
				throw new ArgumentNullException("unresolvedFile");
			FreezableHelper.Freeze(unresolvedFile);
			var newParseInfo = new ParseInformation(unresolvedFile, null, false);
			lock (this) {
				int index = FindIndexForProject(project);
				if (index >= 0) {
					currentVersion = null;
					var args = new ParseInformationEventArgs(project, entries[index].UnresolvedFile, newParseInfo);
					entries[index] = new ProjectEntry(project, unresolvedFile, null);
					project.OnParseInformationUpdated(args);
					parserService.RaiseParseInformationUpdated(args);
				}
			}
		}
示例#18
0
		public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
		{
			var csParseInfo = parseInfo as CSharpFullParseInformation;
			if (csParseInfo == null)
				throw new ArgumentException("Parse info does not have SyntaxTree");
			
			return ResolveAtLocation.Resolve(compilation, csParseInfo.UnresolvedFile, csParseInfo.SyntaxTree, location, cancellationToken);
		}
示例#19
0
		public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
		{
			var csParseInfo = parseInfo as CSharpFullParseInformation;
			if (csParseInfo == null)
				throw new ArgumentException("Parse info does not have SyntaxTree");
			
			CSharpUnresolvedFile unresolvedFile = csParseInfo.UnresolvedFile;
			var projectContents = compilation.Assemblies.Select(asm => asm.UnresolvedAssembly).OfType<IProjectContent>().ToList();
			if (projectContents.All(pc => pc.GetFile(unresolvedFile.FileName) != unresolvedFile))
				unresolvedFile = null;
			return ResolveAtLocation.Resolve(compilation, unresolvedFile, csParseInfo.SyntaxTree, location, cancellationToken);
		}
示例#20
0
		public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
		{
			throw new NotImplementedException();
		}
示例#21
0
		public void UpdateParseInformationForFolding(ParseInformation parseInfo)
		{
			if (!CodeEditorOptions.Instance.EnableFolding) {
				parseInfo = null;
			} else {
				if (parseInfo == null || !parseInfo.IsFullParseInformation)
					parseInfo = SD.ParserService.Parse(this.FileName, this.Document);
				if (parseInfo != null && !parseInfo.SupportsFolding)
					parseInfo = null;
			}
			
			IServiceContainer container = this.Adapter.GetService(typeof(IServiceContainer)) as IServiceContainer;
			ParserFoldingStrategy folding = container.GetService(typeof(ParserFoldingStrategy)) as ParserFoldingStrategy;
			if (parseInfo == null) {
				if (folding != null) {
					folding.Dispose();
					container.RemoveService(typeof(ParserFoldingStrategy));
				}
			} else {
				if (folding == null) {
					TextArea textArea = this.Adapter.GetService(typeof(TextArea)) as TextArea;
					folding = new ParserFoldingStrategy(textArea);
					container.AddService(typeof(ParserFoldingStrategy), folding);
				}
				folding.UpdateFoldings(parseInfo);
			}
		}
 public ParserUpdateStepEventArgs(FileName fileName, ITextSource content, ParseInformation parseInformation)
 {
     if (fileName == null)
         throw new ArgumentNullException("fileName");
     if (content == null)
         throw new ArgumentNullException("content");
     if (parseInformation == null)
         throw new ArgumentNullException("parseInformation");
     this.fileName = fileName;
     this.content = content;
     this.parseInformation = parseInformation;
 }
示例#23
0
 void IParser.FindLocalReferences(ParseInformation parseInfo, ITextSource fileContent, IVariable variable, ICompilation compilation, Action<SearchResultMatch> callback, CancellationToken cancellationToken)
 {
 }
示例#24
0
		public ResolveResult ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken)
		{
			return null;
		}
示例#25
0
		public ICodeContext ResolveContext(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
		{
			var csParseInfo = parseInfo as CSharpFullParseInformation;
			if (csParseInfo == null)
				throw new ArgumentException("Parse info does not have SyntaxTree");
			
			CSharpUnresolvedFile unresolvedFile = csParseInfo.UnresolvedFile;
			var projectContents = compilation.Assemblies.Select(asm => asm.UnresolvedAssembly).OfType<IProjectContent>().ToList();
			if (projectContents.All(pc => pc.GetFile(unresolvedFile.FileName) != unresolvedFile))
				unresolvedFile = null;
			var syntaxTree = csParseInfo.SyntaxTree;
			var node = syntaxTree.GetNodeAt(location);
			if (node == null)
				return null; // null result is allowed; the parser service will substitute a dummy context
			var resolver = new CSharpAstResolver(compilation, syntaxTree, unresolvedFile);
			return resolver.GetResolverStateBefore(node);
		}
示例#26
0
		public ICodeContext ResolveContext(ParseInformation parseInfo, ICSharpCode.NRefactory.TextLocation location, ICSharpCode.NRefactory.TypeSystem.ICompilation compilation, System.Threading.CancellationToken cancellationToken)
		{
			throw new NotImplementedException();
		}
示例#27
0
		public ICodeContext ResolveContext(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
		{
			return null; // null result is allowed; the parser service will substitute a dummy context
		}
示例#28
0
		public void FindLocalReferences(ParseInformation parseInfo, ITextSource fileContent, IVariable variable, ICompilation compilation, Action<SearchResultMatch> callback, CancellationToken cancellationToken)
		{
			var csParseInfo = parseInfo as CSharpFullParseInformation;
			if (csParseInfo == null)
				throw new ArgumentException("Parse info does not have SyntaxTree");
			
			ReadOnlyDocument document = null;
			IHighlighter highlighter = null;
			
			new FindReferences().FindLocalReferences(
				variable, csParseInfo.UnresolvedFile, csParseInfo.SyntaxTree, compilation,
				delegate (AstNode node, ResolveResult result) {
					if (document == null) {
						document = new ReadOnlyDocument(fileContent, parseInfo.FileName);
						highlighter = SD.EditorControlService.CreateHighlighter(document);
						highlighter.BeginHighlighting();
					}
					var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation);
					int offset = document.GetOffset(node.StartLocation);
					int length = document.GetOffset(node.EndLocation) - offset;
					var builder = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
					var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
					callback(new SearchResultMatch(parseInfo.FileName, node.StartLocation, node.EndLocation, offset, length, builder, defaultTextColor));
				}, cancellationToken);
			
			if (highlighter != null) {
				highlighter.Dispose();
			}
		}
示例#29
0
		void ParserServiceParseInformationUpdated(object sender, ParseInformationEventArgs e)
		{
			if (e.FileName != this.FileName)
				return;
			this.VerifyAccess();
			// When parse information is updated quickly in succession, only do a single update
			// to the latest version.
			updateParseInfoTo = e.NewParseInformation;
			this.Dispatcher.BeginInvoke(
				DispatcherPriority.Background,
				new Action(
					delegate {
						if (updateParseInfoTo != null) {
							ParseInformationUpdated(updateParseInfoTo);
							updateParseInfoTo = null;
						}
					}));
		}
			public ProjectEntry(IProject project, IUnresolvedFile unresolvedFile, ParseInformation cachedParseInformation)
			{
				this.Project = project;
				this.UnresolvedFile = unresolvedFile;
				this.CachedParseInformation = cachedParseInformation;
			}
示例#31
0
 ICodeContext IParser.ResolveContext(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }