Beispiel #1
0
        protected override void OnParsedDocumentUpdated()
        {
            base.OnParsedDocumentUpdated();
            try {
                razorDocument = CU as RazorCSharpParsedDocument;
                if (razorDocument == null || razorDocument.PageInfo.CSharpSyntaxTree == null)
                {
                    return;
                }

                CreateDocType();

                // Don't update C# code in hiddenInfo when:
                // 1) We are in a RazorState, and the completion window is visible,
                // it'll freeze (or disappear if we call OnCompletionContextChanged).
                // 2) We're in the middle of writing a Razor expression - if we're in an incorrect state,
                // the generated code migh be behind what we've been already written.

                var state = Tracker.Engine.CurrentState;
                if (state is RazorState && CompletionWindowManager.IsVisible ||
                    (!updateNeeded && (state is RazorSpeculativeState || state is RazorExpressionState)))
                {
                    UpdateHiddenDocument(false);
                }
                else
                {
                    UpdateHiddenDocument();
                    updateNeeded = false;
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while updating razor completion.", e);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Used by unit tests.
 /// </summary>
 internal RazorCSharpEditorExtension(MonoDevelop.Ide.Gui.Document doc, RazorCSharpParsedDocument parsedDoc, bool cSharpContext)
 {
     razorDocument = parsedDoc;
     Initialize(doc.Editor, doc);
     if (cSharpContext)
     {
         InitializeCodeCompletion();
         SwitchToHidden();
     }
 }
        Task <IReadOnlyList <Projection> > GenerateProjections(RazorCSharpParsedDocument razorDocument, Ide.TypeSystem.ParseOptions options, CancellationToken cancellationToken = default(CancellationToken))
        {
            var code = razorDocument.PageInfo.CSharpCode;

            if (string.IsNullOrEmpty(code))
            {
                return(Task.FromResult((IReadOnlyList <Projection>) new Projection[0]));
            }

            string filename        = razorDocument.PageInfo.ParsedDocument.FileName;
            var    currentMappings = razorDocument.PageInfo.GeneratorResults.DesignTimeLineMappings;

            return(Task.Run(() => {
                var doc = TextEditorFactory.CreateNewDocument(new StringTextSource(code), filename, "text/x-csharp");
                var segments = new List <ProjectedSegment> ();

                foreach (var map in currentMappings)
                {
                    string pattern = "#line " + map.Key + " ";
                    var idx = razorDocument.PageInfo.CSharpCode.IndexOf(pattern, StringComparison.Ordinal);
                    if (idx < 0)
                    {
                        continue;
                    }
                    var line = doc.GetLineByOffset(idx);
                    var offset = line.NextLine.Offset + map.Value.StartGeneratedColumn - 1;

                    var seg = new ProjectedSegment(map.Value.StartOffset.Value, offset, map.Value.CodeLength);
                    segments.Add(seg);
                }

                var projections = new List <Projection> ();
                projections.Add(new Projection(doc, segments));
                return (IReadOnlyList <Projection>)projections;
            }));
        }
		protected override void OnParsedDocumentUpdated ()
		{
			base.OnParsedDocumentUpdated ();
			try {
				razorDocument = CU as RazorCSharpParsedDocument;
				if (razorDocument == null || razorDocument.PageInfo.CSharpParsedFile == null)
					return;

				CreateDocType ();

				// Don't update C# code in hiddenInfo when:
				// 1) We are in a RazorState, and the completion window is visible,
				// it'll freeze (or disappear if we call OnCompletionContextChanged).
				// 2) We're in the middle of writing a Razor expression - if we're in an incorrect state,
				// the generated code migh be behind what we've been already written.

				var state = Tracker.Engine.CurrentState;
				if (state is RazorState && CompletionWindowManager.IsVisible || 
				    (!updateNeeded && (state is RazorSpeculativeState || state is RazorExpressionState)))
					UpdateHiddenDocument (false);
				else {
					UpdateHiddenDocument ();
					updateNeeded = false;
				}
			} catch (Exception e) {
				LoggingService.LogError ("Error while updating razor completion.", e); 
			}
		}
		/// <summary>
		/// Used by unit tests.
		/// </summary>
		internal RazorCSharpEditorExtension (MonoDevelop.Ide.Gui.Document doc, RazorCSharpParsedDocument parsedDoc, bool cSharpContext)
		{
			razorDocument = parsedDoc;
			Initialize (doc.Editor, doc);
			if (cSharpContext) {
				InitializeCodeCompletion ();
				SwitchToHidden ();
			}
		}
		public RazorTestingEditorExtension (Document doc, RazorCSharpParsedDocument parsedDoc, bool cSharpContext)
		{
			razorDocument = parsedDoc;
			Initialize (doc);
			if (cSharpContext) {
				InitializeCodeCompletion ();
				SwitchToHidden ();
			}
		}