当前位置: 首页>>代码示例>>C#>>正文


C# DocumentContext类代码示例

本文整理汇总了C#中DocumentContext的典型用法代码示例。如果您正苦于以下问题:C# DocumentContext类的具体用法?C# DocumentContext怎么用?C# DocumentContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DocumentContext类属于命名空间,在下文中一共展示了DocumentContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSymbolInfoAsync

		public static async Task<RefactoringSymbolInfo> GetSymbolInfoAsync (DocumentContext document, int offset, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (document == null)
				throw new ArgumentNullException (nameof (document));
			if (document.ParsedDocument == null)
				return RefactoringSymbolInfo.Empty;
			var unit = await document.AnalysisDocument.GetSemanticModelAsync (cancellationToken).ConfigureAwait (false);
			if (unit != null) {
				var root = await unit.SyntaxTree.GetRootAsync (cancellationToken).ConfigureAwait (false);
				try {
					var token = root.FindToken (offset);
					if (!token.Span.IntersectsWith (offset))
						return RefactoringSymbolInfo.Empty;
					var symbol = unit.GetSymbolInfo (token.Parent);
					return new RefactoringSymbolInfo (symbol) {
						DeclaredSymbol = token.IsKind (SyntaxKind.IdentifierToken) ? unit.GetDeclaredSymbol (token.Parent) : null,
						Node = token.Parent,
						Model = unit
					};
				} catch (Exception) {
					return RefactoringSymbolInfo.Empty;
				}
			}
			return RefactoringSymbolInfo.Empty;
		}
开发者ID:zenek-y,项目名称:monodevelop,代码行数:25,代码来源:RefactoringSymbolInfo.cs

示例2: FormatStatmentAt

		public static void FormatStatmentAt (TextEditor editor, DocumentContext context, MonoDevelop.Ide.Editor.DocumentLocation location, OptionSet optionSet = null)
		{
			var offset = editor.LocationToOffset (location);
			var policyParent = context.Project != null ? context.Project.Policies : PolicyService.DefaultPolicies;
			var mimeTypeChain = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
			Format (policyParent, mimeTypeChain, editor, context, offset, offset, false, true, optionSet: optionSet);
		}
开发者ID:hbons,项目名称:monodevelop,代码行数:7,代码来源:OnTheFlyFormatter.cs

示例3: CheckOpeningPoint

		public override bool CheckOpeningPoint(TextEditor editor, DocumentContext ctx, CancellationToken cancellationToken)
		{
			var snapshot = CurrentSnapshot;
			var position = StartOffset;
			var token = FindToken(snapshot, position, cancellationToken);

			// check token at the opening point first
			if (!IsValidToken(token) ||
			    token.RawKind != OpeningTokenKind ||
			    token.SpanStart != position || token.Parent == null)
			{
				return false;
			}

			// now check whether parser think whether there is already counterpart closing parenthesis
			var pair = token.Parent.GetParentheses();

			// if pair is on the same line, then the closing parenthesis must belong to other tracker.
			// let it through
			if (Editor.GetLineByOffset (pair.Item1.SpanStart).LineNumber == Editor.GetLineByOffset(pair.Item2.Span.End).LineNumber)
			{
				return true;
			}

			return (int)pair.Item2.Kind() != ClosingTokenKind || pair.Item2.Span.Length == 0;
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:26,代码来源:ParenthesisCompletionSession.cs

示例4: GetItem

		public override async Task<TooltipItem> GetItem (TextEditor editor, DocumentContext ctx, int offset, CancellationToken token = default(CancellationToken))
		{
			if (ctx == null)
				return null;
			var analysisDocument = ctx.ParsedDocument;
			if (analysisDocument == null)
				return null;
			var unit = analysisDocument.GetAst<SemanticModel> ();
			if (unit == null)
				return null;
			
			var root = unit.SyntaxTree.GetRoot (token);
			SyntaxToken syntaxToken;
			try {
				syntaxToken = root.FindToken (offset);
			} catch (ArgumentOutOfRangeException) {
				return null;
			}
			if (!syntaxToken.Span.IntersectsWith (offset))
				return null;
			var symbolInfo = unit.GetSymbolInfo (syntaxToken.Parent, token);
			var symbol = symbolInfo.Symbol ?? unit.GetDeclaredSymbol (syntaxToken.Parent, token);
			var tooltipInformation = await CreateTooltip (symbol, syntaxToken, editor, ctx, offset);
			if (tooltipInformation == null || string.IsNullOrEmpty (tooltipInformation.SignatureMarkup))
				return null;
			return new TooltipItem (tooltipInformation, syntaxToken.Span.Start, syntaxToken.Span.Length);
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:27,代码来源:LanguageItemTooltipProvider.cs

示例5: ProjectedCompletionExtension

		public ProjectedCompletionExtension (DocumentContext ctx, IReadOnlyList<Projection> projections)
		{
			if (projections == null)
				throw new ArgumentNullException ("projections");
			this.ctx = ctx;
			this.projections = projections;
		}
开发者ID:vvarshne,项目名称:monodevelop,代码行数:7,代码来源:ProjectedCompletionExtension.cs

示例6: ProjectedDocumentContext

		public ProjectedDocumentContext (TextEditor projectedEditor, DocumentContext originalContext)
		{
			if (projectedEditor == null)
				throw new ArgumentNullException ("projectedEditor");
			if (originalContext == null)
				throw new ArgumentNullException ("originalContext");
			this.projectedEditor = projectedEditor;
			this.originalContext = originalContext;

			if (originalContext.Project != null) {
				var originalProjectId = TypeSystemService.GetProjectId (originalContext.Project);
				if (originalProjectId != null) {
					var originalProject = TypeSystemService.Workspace.CurrentSolution.GetProject (originalProjectId);
					if (originalProject != null) {
						projectedDocument = originalProject.AddDocument (
							projectedEditor.FileName,
							projectedEditor
						);
					}
				}
			}

			projectedEditor.TextChanged += delegate(object sender, TextChangeEventArgs e) {
				if (projectedDocument != null)
					projectedDocument = projectedDocument.WithText (projectedEditor);
				ReparseDocument ();
			};

			ReparseDocument ();
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:30,代码来源:ProjectedDocumentContext.cs

示例7: IsValidInContext

		public override bool IsValidInContext (DocumentContext context)
		{
			var pctx = context as ProjectedDocumentContext;
			if (pctx == null)
				return false;
			return pctx.ProjectedEditor.GetContent<CompletionTextEditorExtension> () != null;
		}
开发者ID:vvarshne,项目名称:monodevelop,代码行数:7,代码来源:ProjectedCompletionExtension.cs

示例8: NavigationVisitor

			public NavigationVisitor (DocumentContext documentContext, SemanticModel model, TextSpan region, CancellationToken token)
			{
				this.documentContext = documentContext;
				this.model = model;
				this.region = region;
				this.token = token;
			}
开发者ID:michaelc37,项目名称:monodevelop,代码行数:7,代码来源:CSharpNavigationTextEditorExtension.cs

示例9: CreateTooltipWindow

		public override Control CreateTooltipWindow (TextEditor editor, DocumentContext ctx, TooltipItem item, int offset, Xwt.ModifierKeys modifierState)
		{
			var result = new LanguageItemWindow (GetExtensibleTextEditor (editor), modifierState, null, (string)item.Item, null);
			if (result.IsEmpty)
				return null;
			return result;
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:CompileErrorTooltipProvider.cs

示例10: IsContext

		public static bool IsContext(TextEditor editor, DocumentContext ctx, int position, CancellationToken cancellationToken)
		{
			// Check to see if we're to the right of an $ or an @$
			var start = position - 1;
			if (start < 0)
			{
				return false;
			}

			if (editor[start] == '@')
			{
				start--;

				if (start < 0)
				{
					return false;
				}
			}

			if (editor[start] != '$')
			{
				return false;
			}

			var tree = ctx.AnalysisDocument.GetSyntaxTreeAsync (cancellationToken).WaitAndGetResult(cancellationToken);
			var token = tree.GetRoot(cancellationToken).FindTokenOnLeftOfPosition(start);

			return tree.IsExpressionContext(start, token, attributes: false, cancellationToken: cancellationToken)
				       || tree.IsStatementContext(start, token, cancellationToken);
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:30,代码来源:InterpolatedStringCompletionSession.cs

示例11: CreateCompletionAndUpdate

		CSharpCompletionTextEditorExtension CreateCompletionAndUpdate (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo,
			out CodeCompletionContext codeCompletionContext)
		{
			var completion = CreateCompletion (editor, context, docInfo, out codeCompletionContext);
			completion.UpdateParsedDocument ();
			return completion;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:7,代码来源:RazorCSharpCompletionBuilder.cs

示例12: HandleDocumentContextChanged

		void HandleDocumentContextChanged (object sender, EventArgs e)
		{
			if (currentContext != null)
				currentContext.DocumentParsed -= HandleDocumentParsed;
			currentContext = textEditor.DocumentContext;
			currentContext.DocumentParsed += HandleDocumentParsed;
		}
开发者ID:zenek-y,项目名称:monodevelop,代码行数:7,代码来源:TextEditorViewContent.cs

示例13: HandleCompletion

		public Task<ICompletionDataList> HandleCompletion (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context,	CodeCompletionContext completionContext,
			UnderlyingDocumentInfo docInfo, char currentChar, CancellationToken token)
		{
			CodeCompletionContext ccc;
			var completion = CreateCompletionAndUpdate (editor, context, docInfo, out ccc);
			return completion.HandleCodeCompletionAsync (completionContext, currentChar, token);
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:7,代码来源:RazorCSharpCompletionBuilder.cs

示例14: Format

		static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, TextEditor editor, DocumentContext context, int startOffset, int endOffset, bool exact, bool formatLastStatementOnly = false, OptionSet optionSet = null)
		{
			TextSpan span;
			if (exact) {
				span = new TextSpan (startOffset, endOffset - startOffset);
			} else {
				span = new TextSpan (0, endOffset);
			}

			var analysisDocument = context.AnalysisDocument;
			if (analysisDocument == null)
				return;

			using (var undo = editor.OpenUndoGroup (/*OperationType.Format*/)) {
				try {
					var syntaxTree = analysisDocument.GetSyntaxTreeAsync ().Result;

					if (formatLastStatementOnly) {
						var root = syntaxTree.GetRoot ();
						var token = root.FindToken (endOffset);
						var tokens = ICSharpCode.NRefactory6.CSharp.FormattingRangeHelper.FindAppropriateRange (token);
						if (tokens.HasValue) {
							span = new TextSpan (tokens.Value.Item1.SpanStart, tokens.Value.Item2.Span.End - tokens.Value.Item1.SpanStart);
						} else {
							var parent = token.Parent;
							if (parent != null)
								span = parent.FullSpan;
						}
					}

					if (optionSet == null) {
						var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
						var textPolicy = policyParent.Get<TextStylePolicy> (mimeTypeChain);
						optionSet = policy.CreateOptions (textPolicy);
					}

					var doc = Formatter.FormatAsync (analysisDocument, span, optionSet).Result;
					var newTree = doc.GetSyntaxTreeAsync ().Result;
					var caretOffset = editor.CaretOffset;

					int delta = 0;
					foreach (var change in newTree.GetChanges (syntaxTree)) {
						if (!exact && change.Span.Start + delta >= caretOffset)
							continue;
						var newText = change.NewText;
						editor.ReplaceText (delta + change.Span.Start, change.Span.Length, newText);
						delta = delta - change.Span.Length + newText.Length;
					}

					var caretEndOffset = caretOffset + delta;
					if (0 <= caretEndOffset && caretEndOffset < editor.Length)
						editor.CaretOffset = caretEndOffset;
					if (editor.CaretColumn == 1)
						editor.CaretColumn = editor.GetVirtualIndentationColumn (editor.CaretLine);
				} catch (Exception e) {
					LoggingService.LogError ("Error in on the fly formatter", e);
				}
			}
		}
开发者ID:xinfushe,项目名称:monodevelop,代码行数:59,代码来源:OnTheFlyFormatter.cs

示例15: Run

		internal void Run (TextEditor editor, DocumentContext ctx)
		{
			var info = RefactoringSymbolInfo.GetSymbolInfoAsync (ctx, editor.CaretOffset).Result;
			var sym = info.DeclaredSymbol ?? info.Symbol;
			if (!CanRename (sym))
				return;
			new RenameRefactoring ().Rename (sym);
		}
开发者ID:zenek-y,项目名称:monodevelop,代码行数:8,代码来源:RenameHandler.cs


注:本文中的DocumentContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。