2
// IRazorCompletionBuilder.cs
5
// Piotr Dowgiallo <sparekd@gmail.com>
7
// Copyright (c) 2012 Piotr Dowgiallo
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
28
using System.Collections.Generic;
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;
37
namespace MonoDevelop.AspNet.Mvc.Completion
39
// Based on MonoDevelop.AspNet.Gui.ILanguageCompletionBuilder
41
public interface IRazorCompletionBuilder
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);
54
public class UnderlyingDocument : Document
56
internal ParsedDocument HiddenParsedDocument;
57
internal ICompilation HiddenCompilation;
59
public override ParsedDocument ParsedDocument {
60
get { return HiddenParsedDocument; }
63
public override ICompilation Compilation {
64
get { return HiddenCompilation; }
67
public UnderlyingDocument (IWorkbenchWindow window)
73
public class UnderlyingDocumentInfo
75
public int CaretPosition { get; set; }
76
public int OriginalCaretPosition { get; set; }
77
public UnderlyingDocument UnderlyingDocument { get; set; }
80
public static class RazorCompletionBuilderService
82
static List<IRazorCompletionBuilder> builder = new List<IRazorCompletionBuilder> ();
84
public static IEnumerable<IRazorCompletionBuilder> Builder {
85
get { return builder; }
88
static RazorCompletionBuilderService ()
90
Mono.Addins.AddinManager.AddExtensionNodeHandler ("/MonoDevelop/Razor/CompletionBuilders", delegate (object sender, Mono.Addins.ExtensionNodeEventArgs args)
92
switch (args.Change) {
93
case Mono.Addins.ExtensionChange.Add:
94
builder.Add ((IRazorCompletionBuilder)args.ExtensionObject);
96
case Mono.Addins.ExtensionChange.Remove:
97
builder.Remove ((IRazorCompletionBuilder)args.ExtensionObject);
103
public static IRazorCompletionBuilder GetBuilder (string language)
105
foreach (IRazorCompletionBuilder b in Builder) {
106
if (b.SupportsLanguage (language))