Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RazorCSharpCompletionBuilder.cs « AspNet « CSharpBinding « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3f1159dd76d663391bec18531bff98073cc3981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//
// RazorCSharpCompletionBuilder.cs
//
// Author:
//		Piotr Dowgiallo <sparekd@gmail.com>
//
// Copyright (c) 2012 Piotr Dowgiallo
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/*
using System;
using MonoDevelop.CSharp.Completion;
using MonoDevelop.Ide.CodeCompletion;
using MonoDevelop.Ide.Gui;
using ICSharpCode.NRefactory6.CSharp.Completion;
using MonoDevelop.AspNet.Razor;
using MonoDevelop.Ide.Editor;

namespace MonoDevelop.CSharp.Completion
{
	// Based on AspLanguageBuilder

	class RazorCSharpCompletionBuilder : IRazorCompletionBuilder
	{
		public bool SupportsLanguage (string language)
		{
			return language == "C#";
		}

		CSharpCompletionTextEditorExtension CreateCompletion (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo,
			out CodeCompletionContext codeCompletionContext)
		{
			var documentLocation = docInfo.UnderlyingDocument.Editor.OffsetToLocation (docInfo.CaretPosition);

			codeCompletionContext = new CodeCompletionContext () {
				TriggerOffset = docInfo.CaretPosition,
				TriggerLine = documentLocation.Line,
				TriggerLineOffset = documentLocation.Column - 1
			};

			return new CSharpCompletionTextEditorExtension (docInfo.UnderlyingDocument) {
				CompletionWidget = CreateCompletionWidget (editor, context, docInfo)
			};
		}

		CSharpCompletionTextEditorExtension CreateCompletionAndUpdate (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo,
			out CodeCompletionContext codeCompletionContext)
		{
			var completion = CreateCompletion (editor, context, docInfo, out codeCompletionContext);
			completion.UpdateParsedDocument ();
			return completion;
		}

		public ICompletionWidget CreateCompletionWidget (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context,	UnderlyingDocumentInfo docInfo)
		{
			return new RazorCompletionWidget (editor, context, docInfo);
		}

		public ICompletionDataList HandlePopupCompletion (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo)
		{
			CodeCompletionContext ccc;
			var completion = CreateCompletionAndUpdate (editor, context, docInfo, out ccc);
			return completion.CodeCompletionCommand (ccc);
		}

		public ICompletionDataList HandleCompletion (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context,	CodeCompletionContext completionContext,
			UnderlyingDocumentInfo docInfo, char currentChar, ref int triggerWordLength)
		{
			CodeCompletionContext ccc;
			var completion = CreateCompletionAndUpdate (editor, context, docInfo, out ccc);
			return completion.HandleCodeCompletionAsync (completionContext, currentChar, ref triggerWordLength);
		}

		public ParameterDataProvider HandleParameterCompletion (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context,	CodeCompletionContext completionContext,
			UnderlyingDocumentInfo docInfo, char completionChar)
		{
			CodeCompletionContext ccc;
			var completion = CreateCompletionAndUpdate (editor, context, docInfo, out ccc);
			return completion.HandleParameterCompletionAsync (completionContext, completionChar);
		}

		public bool GetParameterCompletionCommandOffset (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context,	UnderlyingDocumentInfo docInfo, out int cpos)
		{
			CodeCompletionContext ccc;
			var completion = CreateCompletionAndUpdate (editor, context, docInfo, out ccc);
			return completion.GetParameterCompletionCommandOffset (out cpos);
		}

		public int GetCurrentParameterIndex (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo, int startOffset)
		{
			CodeCompletionContext ccc;
			var completion = CreateCompletionAndUpdate (editor, context, docInfo, out ccc);
			return completion.GetCurrentParameterIndex (startOffset);
		}
	}

	class RazorCompletionWidget : ICompletionWidget
	{
		DocumentContext realDocumentContext;

		MonoDevelop.Ide.Editor.TextEditor realEditor;

		UnderlyingDocumentInfo docInfo;

		public RazorCompletionWidget (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo)
		{
			this.realEditor = editor;
			this.realDocumentContext = context;
			this.docInfo = docInfo;
		}

		#region ICompletionWidget implementation

		public CodeCompletionContext CurrentCodeCompletionContext
		{
			get	{
				return CreateCodeCompletionContext (CaretOffset);
			}
		}

		public event EventHandler CompletionContextChanged;

		public string GetText (int startOffset, int endOffset)
		{
			endOffset = Math.Min (endOffset, TextLength);
			if (endOffset <= startOffset)
				return String.Empty;
			return docInfo.UnderlyingDocument.Editor.GetTextAt (startOffset, endOffset - startOffset);
		}

		public char GetChar (int offset)
		{
			if (offset < 0 || offset >= TextLength)
				return '\0';
			return docInfo.UnderlyingDocument.Editor.GetCharAt (offset);
		}

		public void Replace (int offset, int count, string text)
		{
			if (count > 0)
				docInfo.UnderlyingDocument.Editor.Text = docInfo.UnderlyingDocument.Editor.Text.Remove (offset, count);
			if (!string.IsNullOrEmpty (text))
				docInfo.UnderlyingDocument.Editor.Text = docInfo.UnderlyingDocument.Editor.Text.Insert (offset, text);
		}

		public CodeCompletionContext CreateCodeCompletionContext (int triggerOffset)
		{
			var savedCtx = realDocumentContext.GetContent<ICompletionWidget> ().CreateCodeCompletionContext (
				realEditor.CaretOffset + triggerOffset - docInfo.CaretPosition);
			var result = new CodeCompletionContext ();
			result.TriggerOffset = triggerOffset;
			var loc = docInfo.UnderlyingDocument.Editor.OffsetToLocation (triggerOffset);
			result.TriggerLine = loc.Line;
			result.TriggerLineOffset = loc.Column - 1;

			result.TriggerXCoord = savedCtx.TriggerXCoord;
			result.TriggerYCoord = savedCtx.TriggerYCoord;
			result.TriggerTextHeight = savedCtx.TriggerTextHeight;

			return result;
		}

		public string GetCompletionText (CodeCompletionContext ctx)
		{
			if (ctx == null)
				return null;
			int min = Math.Min (ctx.TriggerOffset, CaretOffset);
			int max = Math.Max (ctx.TriggerOffset, CaretOffset);
			return docInfo.UnderlyingDocument.Editor.GetTextBetween (min, max);
		}

		public void SetCompletionText (CodeCompletionContext ctx, string partial_word, string complete_word)
		{
			SetCompletionText (ctx, partial_word, complete_word, complete_word.Length);
		}

		public void SetCompletionText (CodeCompletionContext ctx, string partial_word, string complete_word, int wordOffset)
		{
			int offset = docInfo.OriginalCaretPosition + ctx.TriggerOffset - docInfo.CaretPosition;
			if (offset < 0 || offset > TextLength)
				return;

			var translatedCtx = new CodeCompletionContext ();
			translatedCtx.TriggerOffset = offset;
			var loc = docInfo.UnderlyingDocument.Editor.OffsetToLocation (offset);
			translatedCtx.TriggerLine = loc.Line;
			translatedCtx.TriggerLineOffset = loc.Column - 1;
			translatedCtx.TriggerWordLength = ctx.TriggerWordLength;
				realDocumentContext.GetContent<ICompletionWidget> ().SetCompletionText (
				translatedCtx, partial_word, complete_word, wordOffset);
		}

		public int CaretOffset
		{
			get	{
				return docInfo.UnderlyingDocument.Editor.CaretOffset;
			}
			set {
				docInfo.UnderlyingDocument.Editor.CaretOffset = value;
			}
		}

		public int TextLength
		{
			get	{
				return docInfo.UnderlyingDocument.Editor.Length;
			}
		}

		public int SelectedLength
		{
			get	{
				return 0;
			}
		}

		public Gtk.Style GtkStyle
		{
			get	{
				return Gtk.Widget.DefaultStyle;
			}
		}

		void ICompletionWidget.AddSkipChar (int cursorPosition, char c)
		{
			// ignore
		}
		#endregion
	}
}
*/