~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/CSharpBinding/AspNet/AspLanguageBuilder.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
using System;
28
28
using System.Linq;
29
 
using MonoDevelop.AspNet.Parser.Dom;
30
29
using MonoDevelop.AspNet.Gui;
31
30
using System.Text;
32
31
using System.Collections.Generic;
33
32
using MonoDevelop.Ide.CodeCompletion;
34
33
using MonoDevelop.Ide.Gui;
35
34
using Mono.TextEditor;
36
 
using ICSharpCode.OldNRefactory;
37
35
using MonoDevelop.Ide.TypeSystem;
38
36
using ICSharpCode.NRefactory.TypeSystem;
39
37
using MonoDevelop.CSharp.Parser;
40
38
using System.IO;
41
39
using ICSharpCode.NRefactory.Completion;
 
40
using MonoDevelop.AspNet.StateEngine;
 
41
using MonoDevelop.Xml.StateEngine;
42
42
 
43
43
 
44
44
 
45
45
namespace MonoDevelop.CSharp.Completion
46
46
{
47
 
        public class AspLanguageBuilder : Visitor, ILanguageCompletionBuilder
 
47
        public class AspLanguageBuilder : ILanguageCompletionBuilder
48
48
        {
49
49
                public bool SupportsLanguage (string language)
50
50
                {
54
54
                public static ParsedDocument Parse (string fileName, string text)
55
55
                {
56
56
                        using (var content = new StringReader (text)) {
57
 
                                return new TypeSystemParser ().Parse (true, fileName, content);
 
57
                                return new MonoDevelop.CSharp.Parser.TypeSystemParser ().Parse (true, fileName, content);
58
58
                        }
59
59
                }
60
60
                
88
88
                                sb.AppendLine ("void Generated ()");
89
89
                                sb.AppendLine ("{");
90
90
                                //Console.WriteLine ("start:" + location.BeginLine  +"/" +location.BeginColumn);
91
 
                                foreach (var expression in info.Expressions) {
92
 
                                        if (expression.Location.BeginLine > data.Caret.Line || expression.Location.BeginLine == data.Caret.Line && expression.Location.BeginColumn > data.Caret.Column - 5) 
 
91
                                foreach (var node in info.XExpressions) {
 
92
                                        bool isBlock = node is AspNetRenderBlock;
 
93
 
 
94
                                        if (node.Region.Begin.Line > data.Caret.Line || node.Region.Begin.Line == data.Caret.Line && node.Region.Begin.Column > data.Caret.Column - 5) 
93
95
                                                continue;
94
96
                                        //Console.WriteLine ("take xprt:" + expressions.Key.BeginLine  +"/" +expressions.Key.BeginColumn);
95
 
                                        if (expression.IsExpression)
 
97
 
 
98
                                        var start = data.Document.LocationToOffset (node.Region.Begin.Line, node.Region.Begin.Column) + 2;
 
99
                                        var end = data.Document.LocationToOffset (node.Region.End.Line, node.Region.End.Column) - 2;
 
100
 
 
101
                                        if (!isBlock) {
96
102
                                                sb.Append ("WriteLine (");
97
 
                                        string expr = expression.Expression.Trim ('=');
98
 
                                        result.AddTextPosition (data.Document.LocationToOffset (expression.Location.BeginLine, expression.Location.BeginColumn), sb.Length, expr.Length);
 
103
                                                start += 1;
 
104
                                        }
 
105
 
 
106
                                        string expr = data.GetTextBetween (start, end);
 
107
                                        result.AddTextPosition (start, end, expr.Length);
99
108
                                        sb.Append (expr);
100
 
                                        if (expression.IsExpression)
 
109
 
 
110
                                        if (!isBlock)
101
111
                                                sb.Append (");");
102
112
                                }
103
113
                        }
132
142
                        }
133
143
                }
134
144
                
135
 
                public IParameterDataProvider HandleParameterCompletion (MonoDevelop.Ide.Gui.Document realDocument, CodeCompletionContext completionContext, DocumentInfo info, LocalDocumentInfo localInfo, char completionChar)
 
145
                public ParameterDataProvider HandleParameterCompletion (MonoDevelop.Ide.Gui.Document realDocument, CodeCompletionContext completionContext, DocumentInfo info, LocalDocumentInfo localInfo, char completionChar)
136
146
                {
137
147
                        CodeCompletionContext ccc;
138
148
                        using (var completion = CreateCompletion (realDocument, info, localInfo, out ccc)) {
290
300
                        var document = new StringBuilder ();
291
301
                        
292
302
                        WriteUsings (info.Imports, document);
293
 
                        
294
 
                        foreach (var node in info.ScriptBlocks) {
295
 
                                int start = data.Document.LocationToOffset (node.Location.EndLine,  node.Location.EndColumn);
296
 
                                int end = data.Document.LocationToOffset (node.EndLocation.BeginLine, node.EndLocation.BeginColumn);
 
303
 
 
304
                        foreach (var node in info.XScriptBlocks) {
 
305
                                var start = data.Document.LocationToOffset (node.Region.Begin.Line, node.Region.Begin.Column) + 2;
 
306
                                var end = data.Document.LocationToOffset (node.Region.End.Line, node.Region.End.Column) - 2;
297
307
                                if (offsetInfos != null)
298
308
                                        offsetInfos.Add (new LocalDocumentInfo.OffsetInfo (start, document.Length, end - start));
299
309
                                
305
315
                                document.AppendLine ("void Generated ()");
306
316
                                document.AppendLine ("{");
307
317
                                //Console.WriteLine ("start:" + location.BeginLine  +"/" +location.BeginColumn);
308
 
                                foreach (var expression in info.Expressions) {
309
 
                                        if (expression.IsExpression)
 
318
 
 
319
                                foreach (var node in info.XExpressions) {
 
320
                                        bool isBlock = node is AspNetRenderBlock;
 
321
 
 
322
                                        var start = data.Document.LocationToOffset (node.Region.Begin.Line, node.Region.Begin.Column) + 2;
 
323
                                        var end = data.Document.LocationToOffset (node.Region.End.Line, node.Region.End.Column) - 2;
 
324
                                        
 
325
                                        if (!isBlock) {
310
326
                                                document.Append ("WriteLine (");
 
327
                                                start += 1;
 
328
                                        }
311
329
                                        
312
 
                                        string expr = expression.Expression.Trim ('=');
 
330
                                        string expr = data.GetTextBetween (start, end);
313
331
                                        if (offsetInfos != null) {
314
 
                                                int col = expression.Location.BeginColumn + "<%".Length + 2;
315
 
                                                if (expr.Length < expression.Expression.Length)
316
 
                                                        col++;
317
 
                                                offsetInfos.Add (new LocalDocumentInfo.OffsetInfo (data.Document.LocationToOffset (expression.Location.BeginLine, col), document.Length, expr.Length));
 
332
                                                offsetInfos.Add (new LocalDocumentInfo.OffsetInfo (start, document.Length, expr.Length));
318
333
                                        }
319
334
                                        document.Append (expr);
320
 
                                        if (expression.IsExpression)
 
335
                                        if (!isBlock)
321
336
                                                document.Append (");");
322
337
                                }
323
338
                                document.AppendLine ("}");