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

« back to all changes in this revision

Viewing changes to src/addins/AspNet/MonoDevelop.AspNet.Mvc/Completion/IRazorCompletionBuilder.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:
 
1
//
 
2
// IRazorCompletionBuilder.cs
 
3
//
 
4
// Author:
 
5
//              Piotr Dowgiallo <sparekd@gmail.com>
 
6
//
 
7
// Copyright (c) 2012 Piotr Dowgiallo
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
//
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
//
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Collections.Generic;
 
29
using System.Linq;
 
30
using System.Text;
 
31
using MonoDevelop.Ide.CodeCompletion;
 
32
using ICSharpCode.NRefactory.Completion;
 
33
using MonoDevelop.Ide.TypeSystem;
 
34
using MonoDevelop.Ide.Gui;
 
35
using ICSharpCode.NRefactory.TypeSystem;
 
36
 
 
37
namespace MonoDevelop.AspNet.Mvc.Completion
 
38
{
 
39
        // Based on MonoDevelop.AspNet.Gui.ILanguageCompletionBuilder
 
40
 
 
41
        public interface IRazorCompletionBuilder
 
42
        {
 
43
                bool SupportsLanguage (string language);
 
44
                ICompletionWidget CreateCompletionWidget (Document document, UnderlyingDocumentInfo docInfo);
 
45
                ICompletionDataList HandlePopupCompletion (Document realDocument, UnderlyingDocumentInfo docInfo);
 
46
                ICompletionDataList HandleCompletion (Document realDocument, CodeCompletionContext completionContext,
 
47
                        UnderlyingDocumentInfo docInfo, char currentChar, ref int triggerWordLength);
 
48
                ParameterDataProvider HandleParameterCompletion (Document realDocument, CodeCompletionContext completionContext,
 
49
                        UnderlyingDocumentInfo docInfo, char completionChar);
 
50
                bool GetParameterCompletionCommandOffset (Document realDocument, UnderlyingDocumentInfo docInfo, out int cpos);
 
51
                int GetCurrentParameterIndex (Document realDocument, UnderlyingDocumentInfo docInfo, int startOffset);
 
52
        }
 
53
 
 
54
        public class UnderlyingDocument : Document
 
55
        {
 
56
                internal ParsedDocument HiddenParsedDocument;
 
57
                internal ICompilation HiddenCompilation;
 
58
 
 
59
                public override ParsedDocument ParsedDocument {
 
60
                        get     { return HiddenParsedDocument; }
 
61
                }
 
62
 
 
63
                public override ICompilation Compilation {
 
64
                        get { return HiddenCompilation; }
 
65
                }
 
66
 
 
67
                public UnderlyingDocument (IWorkbenchWindow window)
 
68
                        : base (window)
 
69
                {
 
70
                }
 
71
        }
 
72
 
 
73
        public class UnderlyingDocumentInfo
 
74
        {
 
75
                public int CaretPosition { get; set; }
 
76
                public int OriginalCaretPosition { get; set; }
 
77
                public UnderlyingDocument UnderlyingDocument { get; set; }
 
78
        }
 
79
 
 
80
        public static class RazorCompletionBuilderService
 
81
        {
 
82
                static List<IRazorCompletionBuilder> builder = new List<IRazorCompletionBuilder> ();
 
83
 
 
84
                public static IEnumerable<IRazorCompletionBuilder> Builder {
 
85
                        get     { return builder; }
 
86
                }
 
87
 
 
88
                static RazorCompletionBuilderService ()
 
89
                {
 
90
                        Mono.Addins.AddinManager.AddExtensionNodeHandler ("/MonoDevelop/Razor/CompletionBuilders", delegate (object sender, Mono.Addins.ExtensionNodeEventArgs args)
 
91
                        {
 
92
                                switch (args.Change) {
 
93
                                        case Mono.Addins.ExtensionChange.Add:
 
94
                                                builder.Add ((IRazorCompletionBuilder)args.ExtensionObject);
 
95
                                                break;
 
96
                                        case Mono.Addins.ExtensionChange.Remove:
 
97
                                                builder.Remove ((IRazorCompletionBuilder)args.ExtensionObject);
 
98
                                                break;
 
99
                                }
 
100
                        });
 
101
                }
 
102
 
 
103
                public static IRazorCompletionBuilder GetBuilder (string language)
 
104
                {
 
105
                        foreach (IRazorCompletionBuilder b in Builder) {
 
106
                                if (b.SupportsLanguage (language))
 
107
                                        return b;
 
108
                        }
 
109
                        return null;
 
110
                }
 
111
        }
 
112
}