diff options
Diffstat (limited to 'main/src/addins/TextTemplating')
8 files changed, 83 insertions, 67 deletions
diff --git a/main/src/addins/TextTemplating/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs b/main/src/addins/TextTemplating/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs index 3ca28d88c2..3396e1342f 100644 --- a/main/src/addins/TextTemplating/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs +++ b/main/src/addins/TextTemplating/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs @@ -237,9 +237,9 @@ namespace Mono.TextTemplating return path; var dir = Path.GetDirectoryName (inputFile); var test = Path.Combine (dir, path); - if (File.Exists (test)) + if (File.Exists (test) || Directory.Exists (test)) return test; - return null; + return path; } #endregion @@ -262,7 +262,7 @@ namespace Mono.TextTemplating content = ""; location = ResolvePath (requestFileName); - if (location == null) { + if (location == null || !File.Exists (location)) { foreach (string path in includePaths) { string f = Path.Combine (path, requestFileName); if (File.Exists (f)) { diff --git a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Gui/T4EditorExtension.cs b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Gui/T4EditorExtension.cs index 260518ee9d..1479522a06 100644 --- a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Gui/T4EditorExtension.cs +++ b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Gui/T4EditorExtension.cs @@ -32,6 +32,10 @@ using MonoDevelop.DesignerSupport; using MonoDevelop.TextTemplating.Parser; using MonoDevelop.Ide; using ICSharpCode.NRefactory.TypeSystem; +using MonoDevelop.Ide.Editor.Extension; +using MonoDevelop.Ide.Editor; +using System.Threading.Tasks; +using System.Threading; namespace MonoDevelop.TextTemplating.Gui { @@ -44,16 +48,16 @@ namespace MonoDevelop.TextTemplating.Gui { } - public override void Initialize () + protected override void Initialize () { base.Initialize (); - Document.DocumentParsed += HandleDocumentDocumentParsed; + DocumentContext.DocumentParsed += HandleDocumentDocumentParsed; HandleDocumentDocumentParsed (this, EventArgs.Empty); } void HandleDocumentDocumentParsed (object sender, EventArgs e) { - parsedDoc = (T4ParsedDocument)Document.ParsedDocument; + parsedDoc = (T4ParsedDocument)DocumentContext.ParsedDocument; if (parsedDoc != null) RefreshOutline (); } @@ -71,30 +75,21 @@ namespace MonoDevelop.TextTemplating.Gui protected T4ParsedDocument ParsedDoc { get { return parsedDoc; } } - - protected ITextBuffer Buffer { - get { - if (Document == null) - throw new InvalidOperationException ("Editor extension not yet initialized"); - return Document.GetContent<ITextBuffer> (); - } - } - - protected IEditableTextBuffer EditableBuffer { + + protected TextEditor EditableBuffer { get { - if (Document == null) + if (DocumentContext == null) throw new InvalidOperationException ("Editor extension not yet initialized"); - return Document.GetContent<IEditableTextBuffer> (); + return DocumentContext.GetContent<TextEditor> (); } } protected string GetBufferText (DomRegion region) { - MonoDevelop.Ide.Gui.Content.ITextBuffer buf = Buffer; - int start = buf.GetPositionFromLineColumn (region.BeginLine, region.BeginColumn); - int end = buf.GetPositionFromLineColumn (region.EndLine, region.EndColumn); + int start = Editor.LocationToOffset (region.BeginLine, region.BeginColumn); + int end = Editor.LocationToOffset (region.EndLine, region.EndColumn); if (end > start && start >= 0) - return buf.GetText (start, end); + return Editor.GetTextBetween (start, end); else return null; } @@ -108,23 +103,20 @@ namespace MonoDevelop.TextTemplating.Gui int pos = completionContext.TriggerOffset; if (pos <= 0) return null; - int triggerWordLength = 0; - return HandleCodeCompletion ((CodeCompletionContext) completionContext, true, ref triggerWordLength); + return HandleCodeCompletion ((CodeCompletionContext) completionContext, true); } - public override ICompletionDataList HandleCodeCompletion ( - CodeCompletionContext completionContext, char completionChar, ref int triggerWordLength) + public override Task<ICompletionDataList> HandleCodeCompletionAsync (CodeCompletionContext completionContext, char completionChar, CancellationToken token = default(CancellationToken)) { int pos = completionContext.TriggerOffset; if (pos > 0 && Editor.GetCharAt (pos - 1) == completionChar) { - return HandleCodeCompletion ((CodeCompletionContext) completionContext, - false, ref triggerWordLength); + return Task.FromResult (HandleCodeCompletion ((CodeCompletionContext) completionContext, false)); } return null; } protected virtual ICompletionDataList HandleCodeCompletion ( - CodeCompletionContext completionContext, bool forced, ref int triggerWordLength) + CodeCompletionContext completionContext, bool forced) { //IEditableTextBuffer buf = this.EditableBuffer; return null; @@ -272,9 +264,9 @@ namespace MonoDevelop.TextTemplating.Gui void SelectSegment (Mono.TextTemplating.ISegment seg) { - int s = Editor.Document.LocationToOffset (seg.TagStartLocation.Line, seg.TagStartLocation.Column); + int s = Editor.LocationToOffset (seg.TagStartLocation.Line, seg.TagStartLocation.Column); if (s > -1) { - Editor.Caret.Offset = s; + Editor.CaretOffset = s; Editor.CenterTo (s); } } diff --git a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/MonoDevelop.TextTemplating.csproj b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/MonoDevelop.TextTemplating.csproj index 91b0d65c0a..6829810e05 100644 --- a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/MonoDevelop.TextTemplating.csproj +++ b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/MonoDevelop.TextTemplating.csproj @@ -76,6 +76,22 @@ <SpecificVersion>False</SpecificVersion> </Reference> <Reference Include="System.Core" /> + <Reference Include="System.Collections.Immutable"> + <HintPath>..\..\..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="System.Reflection.Metadata"> + <HintPath>..\..\..\..\packages\System.Reflection.Metadata.1.0.18-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="Microsoft.CodeAnalysis.Desktop"> + <HintPath>..\..\..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="Microsoft.CodeAnalysis"> + <HintPath>..\..\..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.dll</HintPath> + <Private>False</Private> + </Reference> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> @@ -104,16 +120,6 @@ <Name>MonoDevelop.Ide</Name> <Private>False</Private> </ProjectReference> - <ProjectReference Include="..\..\MonoDevelop.SourceEditor2\MonoDevelop.SourceEditor.csproj"> - <Project>{F8F92AA4-A376-4679-A9D4-60E7B7FBF477}</Project> - <Name>MonoDevelop.SourceEditor</Name> - <Private>False</Private> - </ProjectReference> - <ProjectReference Include="..\..\..\core\Mono.Texteditor\Mono.TextEditor.csproj"> - <Project>{A2329308-3751-4DBD-9A75-5F7B8B024625}</Project> - <Name>Mono.TextEditor</Name> - <Private>False</Private> - </ProjectReference> <ProjectReference Include="..\..\..\..\external\nrefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> <Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> <Name>ICSharpCode.NRefactory</Name> @@ -135,5 +141,6 @@ <None Include="Templates\T4PreprocessedTemplateCSharp.xft.xml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="packages.config" /> </ItemGroup> </Project> diff --git a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Parser/T4ParsedDocument.cs b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Parser/T4ParsedDocument.cs index 6c3e152a43..1d6036c153 100644 --- a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Parser/T4ParsedDocument.cs +++ b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Parser/T4ParsedDocument.cs @@ -29,35 +29,28 @@ using System.Collections.Generic; using Mono.TextTemplating; using MonoDevelop.Ide.TypeSystem; using ICSharpCode.NRefactory.TypeSystem; +using MonoDevelop.Ide.Editor; +using System.Linq; namespace MonoDevelop.TextTemplating.Parser { - public class T4ParsedDocument : ParsedDocument + public class T4ParsedDocument : DefaultParsedDocument { - string fileName; - IList<Error> errors; + IList<MonoDevelop.Ide.TypeSystem.Error> errors; - public override string FileName { - get { - return fileName; - } - } - - public T4ParsedDocument (string fileName, List<ISegment> segments, IList<Error> errors) + public T4ParsedDocument (string fileName, List<ISegment> segments, IList<MonoDevelop.Ide.TypeSystem.Error> errors) : base(fileName) { - this.fileName = fileName; this.errors = errors; TemplateSegments = segments; } - public override IList<Error> Errors { - get { - return errors; - } + public override System.Threading.Tasks.Task<IReadOnlyList<MonoDevelop.Ide.TypeSystem.Error>> GetErrorsAsync (System.Threading.CancellationToken cancellationToken) + { + return System.Threading.Tasks.Task.FromResult((IReadOnlyList<MonoDevelop.Ide.TypeSystem.Error>)errors); } - + public List<ISegment> TemplateSegments { get; private set; } public IEnumerable<Directive> TemplateDirectives { @@ -79,10 +72,15 @@ namespace MonoDevelop.TextTemplating.Parser } } } + + public override System.Threading.Tasks.Task<IReadOnlyList<FoldingRegion>> GetFoldingsAsync (System.Threading.CancellationToken cancellationToken) + { + return System.Threading.Tasks.Task.FromResult((IReadOnlyList<FoldingRegion>)Foldings.ToList ()); + } - public override IEnumerable<FoldingRegion> Foldings { + public IEnumerable<FoldingRegion> Foldings { get { - foreach (var region in Comments.ToFolds ()) + foreach (var region in GetCommentsAsync().Result.ToFolds ()) yield return region; foreach (ISegment seg in TemplateSegments) { if (seg.EndLocation.Line - seg.TagStartLocation.Line < 1) @@ -105,7 +103,7 @@ namespace MonoDevelop.TextTemplating.Parser name = "<#@" + dir.Name + "...#>"; } - DomRegion region = new DomRegion (seg.TagStartLocation.Line, seg.TagStartLocation.Column, + var region = new DocumentRegion (seg.TagStartLocation.Line, seg.TagStartLocation.Column, seg.EndLocation.Line, seg.EndLocation.Column); yield return new FoldingRegion (name, region, false); diff --git a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Parser/T4Parser.cs b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Parser/T4Parser.cs index a18ebdbc6a..d348e6340e 100644 --- a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Parser/T4Parser.cs +++ b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/Parser/T4Parser.cs @@ -28,32 +28,35 @@ using System; using System.IO; using Mono.TextTemplating; using MonoDevelop.Ide.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.Projects; using System.Collections.Generic; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Core.Text; namespace MonoDevelop.TextTemplating.Parser { public class T4Parser : TypeSystemParser { - public override ParsedDocument Parse (bool storeAst, string fileName, TextReader content, Project project = null) + public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { + var fileName = parseOptions.FileName; ParsedTemplate template = new ParsedTemplate (fileName); + var readOnlyDoc = TextEditorFactory.CreateNewReadonlyDocument (parseOptions.Content, fileName); + try { - var tk = new Tokeniser (fileName, content.ReadToEnd ()); + var tk = new Tokeniser (fileName, readOnlyDoc.Text); template.ParseWithoutIncludes (tk); } catch (ParserException ex) { template.LogError (ex.Message, ex.Location); } - var errors = new List<Error> (); foreach (System.CodeDom.Compiler.CompilerError err in template.Errors) { - errors.Add (new Error (err.IsWarning ? ErrorType.Warning : ErrorType.Error, err.ErrorText, err.Line, err.Column)); + errors.Add (new Error (err.IsWarning ? ErrorType.Warning : ErrorType.Error, err.ErrorText, new DocumentLocation (err.Line, err.Column))); } var doc = new T4ParsedDocument (fileName, template.RawSegments, errors); doc.Flags |= ParsedDocumentFlags.NonSerializable; - return doc; + return System.Threading.Tasks.Task.FromResult((ParsedDocument)doc); } } } diff --git a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/TextTemplatingFilePreprocessor.cs b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/TextTemplatingFilePreprocessor.cs index 5f1ab37897..4387d8d872 100644 --- a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/TextTemplatingFilePreprocessor.cs +++ b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/TextTemplatingFilePreprocessor.cs @@ -107,4 +107,3 @@ namespace MonoDevelop.TextTemplating } } } - diff --git a/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/packages.config b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/packages.config new file mode 100644 index 0000000000..d3fca62c00 --- /dev/null +++ b/main/src/addins/TextTemplating/MonoDevelop.TextTemplating/packages.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.CodeAnalysis.Common" version="1.0.0-rc1" targetFramework="net45" />
+ <package id="System.Collections.Immutable" version="1.1.33-beta" targetFramework="net45" />
+ <package id="System.Reflection.Metadata" version="1.0.18-beta" targetFramework="net45" />
+</packages>
\ No newline at end of file diff --git a/main/src/addins/TextTemplating/TextTransform/TextTransform.cs b/main/src/addins/TextTemplating/TextTransform/TextTransform.cs index d1b061d07c..e4f239e320 100644 --- a/main/src/addins/TextTemplating/TextTransform/TextTransform.cs +++ b/main/src/addins/TextTemplating/TextTransform/TextTransform.cs @@ -37,6 +37,17 @@ namespace Mono.TextTemplating const string name ="TextTransform.exe"; public static int Main (string[] args) + {
+ try {
+ return MainInternal(args);
+ }
+ catch (Exception e) {
+ Console.Error.WriteLine(e);
+ return -1;
+ }
+ } + + private static int MainInternal (string[] args) { if (args.Length == 0) { ShowHelp (true); |