diff options
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemParser.cs')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemParser.cs | 99 |
1 files changed, 85 insertions, 14 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemParser.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemParser.cs index 7470e8c358..62ca819303 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemParser.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemParser.cs @@ -27,9 +27,53 @@ using System; using System.IO; using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.Projects; +using MonoDevelop.Core.Text; +using Microsoft.CodeAnalysis; +using System.Threading.Tasks; +using System.Threading; +using MonoDevelop.Ide.Editor.Projection; +using MonoDevelop.Ide.Editor; +using System.Collections.Generic; namespace MonoDevelop.Ide.TypeSystem { + public sealed class ParseOptions + { + public string FileName { get; set; } + + public ITextSource Content { get; set; } + + public MonoDevelop.Projects.Project Project { get; set; } + + public Document RoslynDocument { get; set; } + } + + [Flags] + public enum DisabledProjectionFeatures { + None = 0, + Completion = 1 << 0, + SemanticHighlighting = 1 << 1, + Tooltips = 1 << 2, + + All = Completion | SemanticHighlighting | Tooltips + } + + public class ParsedDocumentProjection + { + public ParsedDocument ParsedDocument { get; private set; } + + public IReadOnlyList<Projection> Projections { get; private set;} + + public DisabledProjectionFeatures DisabledProjectionFeatures { get; private set;} + + public ParsedDocumentProjection (ParsedDocument parsedDocument, IReadOnlyList<Projection> projections, DisabledProjectionFeatures disabledProjectionFeatures = DisabledProjectionFeatures.None) + { + this.ParsedDocument = parsedDocument; + this.Projections = projections; + this.DisabledProjectionFeatures = disabledProjectionFeatures; + } + } + /// <summary> /// A type system parser provides a ParsedDocument (which just adds some more information to a IUnresolvedFile) for /// a given file. This is required for adding information to the type system service to make the file contents available @@ -52,24 +96,51 @@ namespace MonoDevelop.Ide.TypeSystem /// <param name='project'> /// The project the file belongs to. /// </param> - public abstract ParsedDocument Parse (bool storeAst, string fileName, TextReader content, Project project = null); + public abstract Task<ParsedDocument> Parse (ParseOptions options, CancellationToken cancellationToken = default(CancellationToken)); /// <summary> - /// Parse the specified file. The file content should be read by the type system parser. + /// If true projections are possible. A projection transforms a source to a target language and maps certain parts of the file to parts in the projected file. + /// That's used for embedded languages for example. /// </summary> - /// <param name='storeAst'> - /// If set to <c>true</c> the ast should be stored in the parsed document. - /// </param> - /// <param name='fileName'> - /// The name of the file. - /// </param> - /// <param name='project'> - /// The project the file belongs to. - /// </param> - public virtual ParsedDocument Parse (bool storeAst, string fileName, Project project = null) + /// <returns><c>true</c> if this instance can generate projection the specified mimeType buildAction supportedLanguages; + /// otherwise, <c>false</c>.</returns> + /// <param name="mimeType">MIME type.</param> + /// <param name="buildAction">Build action.</param> + /// <param name="supportedLanguages">Supported languages.</param> + public virtual bool CanGenerateProjection (string mimeType, string buildAction, string[] supportedLanguages) + { + return false; + } + + /// <summary> + /// Generates the plain projection. This is used for type system services. + /// </summary> + /// <returns>The projection.</returns> + /// <param name="options">Options.</param> + /// <param name="cancellationToken">Cancellation token.</param> + public virtual Task<IReadOnlyList<Projection>> GenerateProjections (ParseOptions options, CancellationToken cancellationToken = default(CancellationToken)) + { + throw new NotSupportedException (); + } + + /// <summary> + /// Generates the parsed document projection. That contains the parsed document and the projection. This is used inside the IDE for the editor. + /// That's usually more efficient than calling Parse/GenerateProjection separately. + /// </summary> + /// <returns>The parsed document projection.</returns> + /// <param name="options">Options.</param> + /// <param name="cancellationToken">Cancellation token.</param> + public virtual Task<ParsedDocumentProjection> GenerateParsedDocumentProjection (ParseOptions options, CancellationToken cancellationToken = default(CancellationToken)) + { + throw new NotSupportedException (); + } + + /// <summary> + /// Gets an up to date partial projection used by code completion. + /// </summary> + public virtual Task<IReadOnlyList<Projection>> GetPartialProjectionsAsync (DocumentContext ctx, TextEditor editor, ParsedDocument currentParsedDocument, CancellationToken cancellationToken = default(CancellationToken)) { - using (var stream = Mono.TextEditor.Utils.TextFileUtility.OpenStream (fileName)) - return Parse (storeAst, fileName, stream, project); + throw new NotSupportedException (); } } } |