public static CompletionDataList CreateProvider (string text, string extension, bool isCtrlSpace)
		{
			string parsedText;
			string editorText;
			int cursorPosition = text.IndexOf ('$');
			int endPos = text.IndexOf ('$', cursorPosition + 1);
			if (endPos == -1)
				parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
			else {
				parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1);
				editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1);
				cursorPosition = endPos - 1; 
			}
			var tww = new MonoDevelop.CSharpBinding.Tests.TestWorkbenchWindow ();
			var sev = new MonoDevelop.CSharpBinding.Tests.TestViewContent ();
			var project = new AspNetAppProject ("C#");
			project.FileName = UnitTests.TestBase.GetTempFile (".csproj");
			
			string file = UnitTests.TestBase.GetTempFile (extension);
			project.AddFile (file);
			
			ProjectDomService.Load (project);
			ProjectDom dom = ProjectDomService.GetProjectDom (project);
			dom.ForceUpdate (true);
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			
			sev.Project = project;
			sev.ContentName = file;
			sev.Text = editorText;
			sev.CursorPosition = cursorPosition;
			tww.ViewContent = sev;
			var doc = new MonoDevelop.Ide.Gui.Document (tww);
			doc.ParsedDocument = new MonoDevelop.AspNet.Parser.AspNetParser ().Parse (null, sev.ContentName, parsedText);
			foreach (var e in doc.ParsedDocument.Errors)
				Console.WriteLine (e);
			
			var textEditorCompletion = new MonoDevelop.AspNet.Gui.AspNetEditorExtension ();
			Initialize (textEditorCompletion, doc);
			
			int triggerWordLength = 1;
			CodeCompletionContext ctx = new CodeCompletionContext ();
			ctx.TriggerOffset = sev.CursorPosition;
			int line, column;
			sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column);
			ctx.TriggerLine = line;
			ctx.TriggerLineOffset = column - 1;
			
			if (isCtrlSpace)
				return textEditorCompletion.CodeCompletionCommand (ctx) as CompletionDataList;
			else
				return textEditorCompletion.HandleCodeCompletion (ctx, editorText[cursorPosition - 1] , ref triggerWordLength) as CompletionDataList;
		}
Ejemplo n.º 2
0
        public static CompletionDataList CreateProvider(string text, string extension, bool isCtrlSpace)
        {
            string parsedText;
            string editorText;
            int    cursorPosition = text.IndexOf('$');
            int    endPos         = text.IndexOf('$', cursorPosition + 1);

            if (endPos == -1)
            {
                parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
            }
            else
            {
                parsedText     = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1);
                editorText     = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1);
                cursorPosition = endPos - 1;
            }
            var tww     = new MonoDevelop.CSharpBinding.Tests.TestWorkbenchWindow();
            var sev     = new MonoDevelop.CSharpBinding.Tests.TestViewContent();
            var project = new AspNetAppProject("C#");

            project.FileName = UnitTests.TestBase.GetTempFile(".csproj");

            string file = UnitTests.TestBase.GetTempFile(extension);

            project.AddFile(file);

            ProjectDomService.Load(project);
            ProjectDom dom = ProjectDomService.GetProjectDom(project);

            dom.ForceUpdate(true);
            ProjectDomService.Parse(project, file, delegate { return(parsedText); });
            ProjectDomService.Parse(project, file, delegate { return(parsedText); });

            sev.Project        = project;
            sev.ContentName    = file;
            sev.Text           = editorText;
            sev.CursorPosition = cursorPosition;
            tww.ViewContent    = sev;
            var doc = new MonoDevelop.Ide.Gui.Document(tww);

            doc.ParsedDocument = new MonoDevelop.AspNet.Parser.AspNetParser().Parse(null, sev.ContentName, parsedText);
            foreach (var e in doc.ParsedDocument.Errors)
            {
                Console.WriteLine(e);
            }

            var textEditorCompletion = new MonoDevelop.AspNet.Gui.AspNetEditorExtension();

            Initialize(textEditorCompletion, doc);

            int triggerWordLength     = 1;
            CodeCompletionContext ctx = new CodeCompletionContext();

            ctx.TriggerOffset = sev.CursorPosition;
            int line, column;

            sev.GetLineColumnFromPosition(sev.CursorPosition, out line, out column);
            ctx.TriggerLine       = line;
            ctx.TriggerLineOffset = column - 1;

            if (isCtrlSpace)
            {
                return(textEditorCompletion.CodeCompletionCommand(ctx) as CompletionDataList);
            }
            else
            {
                return(textEditorCompletion.HandleCodeCompletion(ctx, editorText[cursorPosition - 1], ref triggerWordLength) as CompletionDataList);
            }
        }