internal static IParameterDataProvider CreateProvider(string text)
        {
            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;
            }

            TestWorkbenchWindow tww     = new TestWorkbenchWindow();
            TestViewContent     sev     = new TestViewContent();
            DotNetProject       project = new DotNetAssemblyProject("C#");

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

            string file = GetTempFile(".cs");

            project.AddFile(file);

            ProjectDomService.Load(project);
//			ProjectDom dom = ProjectDomService.GetProjectDom (project);
            ProjectDomService.Parse(project, file, null, delegate { return(parsedText); });
            ProjectDomService.Parse(project, file, null, delegate { return(parsedText); });

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

            doc.ParsedDocument = new NRefactoryParser().Parse(null, sev.ContentName, parsedText);
            CSharpTextEditorCompletion textEditorCompletion = new CSharpTextEditorCompletion(doc);

            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;

            IParameterDataProvider result = textEditorCompletion.HandleParameterCompletion(ctx, editorText[cursorPosition - 1]);

            ProjectDomService.Unload(project);
            return(result);
        }
Beispiel #2
0
        public override void Setup()
        {
            base.Setup();
            string solFile = Util.GetSampleProject("completion-db-test", "CompletionDbTest.sln");

            solution = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);
            ProjectDomService.Load(solution);

            Project prj;

            prj  = solution.FindProjectByName("Library2");
            lib2 = ProjectDomService.GetProjectDom(prj);
            lib2.ForceUpdate(true);
            prj  = solution.FindProjectByName("Library1");
            lib1 = ProjectDomService.GetProjectDom(prj);
            lib1.ForceUpdate(true);
            prj         = solution.FindProjectByName("CompletionDbTest");
            mainProject = ProjectDomService.GetProjectDom(prj);
            mainProject.ForceUpdate(true);
        }
        internal static RefactoringOptions CreateRefactoringOptions(string text)
        {
            int cursorPosition = -1;
            int endPos         = text.IndexOf('$');

            if (endPos >= 0)
            {
                cursorPosition = endPos;
                text           = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
            }

            int selectionStart = -1;
            int selectionEnd   = -1;
            int idx            = text.IndexOf("<-");

            if (idx >= 0)
            {
                selectionStart = idx;
                text           = text.Substring(0, idx) + text.Substring(idx + 2);
                selectionEnd   = idx = text.IndexOf("->");

                text = text.Substring(0, idx) + text.Substring(idx + 2);
                if (cursorPosition < 0)
                {
                    cursorPosition = selectionEnd - 1;
                }
            }

            TestWorkbenchWindow tww = new TestWorkbenchWindow();
            TestViewContent     sev = new TestViewContent();
            //		return new RefactoringOptions ();

            DotNetProject project  = new DotNetAssemblyProject("C#");
            Solution      solution = new Solution();

            solution.RootFolder.Items.Add(project);
            project.FileName = GetTempFile(".csproj");
            string file = GetTempFile(".cs");

            project.AddFile(file);
            string parsedText = text;
            string editorText = text;

            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.Editor.Document.MimeType = "text/x-csharp";
            doc.Editor.Document.FileName = file;
            doc.ParsedDocument           = new McsParser().Parse(null, sev.ContentName, parsedText);
            foreach (var e in doc.ParsedDocument.Errors)
            {
                Console.WriteLine(e);
            }
            if (cursorPosition >= 0)
            {
                doc.Editor.Caret.Offset = cursorPosition;
            }
            if (selectionStart >= 0)
            {
                doc.Editor.SetSelection(selectionStart, selectionEnd);
            }

            NRefactoryResolver resolver = new NRefactoryResolver(dom,
                                                                 doc.ParsedDocument.CompilationUnit,
                                                                 sev.Data,
                                                                 file);

            ExpressionResult expressionResult;

            if (selectionStart >= 0)
            {
                expressionResult = new ExpressionResult(editorText.Substring(selectionStart, selectionEnd - selectionStart).Trim());
                endPos           = selectionEnd;
            }
            else
            {
                expressionResult = new NewCSharpExpressionFinder(dom).FindFullExpression(doc.Editor, cursorPosition + 1);
            }
            ResolveResult resolveResult = endPos >= 0 ? resolver.Resolve(expressionResult, new DomLocation(doc.Editor.Caret.Line, doc.Editor.Caret.Column)) : null;

            RefactoringOptions result = new RefactoringOptions {
                Document      = doc,
                Dom           = dom,
                ResolveResult = resolveResult,
                SelectedItem  = null
            };

            if (resolveResult is MemberResolveResult)
            {
                result.SelectedItem = ((MemberResolveResult)resolveResult).ResolvedMember;
            }
            if (resolveResult is LocalVariableResolveResult)
            {
                result.SelectedItem = ((LocalVariableResolveResult)resolveResult).LocalVariable;
            }
            if (resolveResult is ParameterResolveResult)
            {
                result.SelectedItem = ((ParameterResolveResult)resolveResult).Parameter;
            }
            result.TestFileProvider = new FileProvider(result);
            return(result);
        }
Beispiel #4
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);
            }
        }