コード例 #1
0
        public ScriptingEngine()
        {
            tokenSource = new CancellationTokenSource();
            taskFactory = new TaskFactory(tokenSource.Token);

            context   = new CompilerContext(new Mono.CSharp.CompilerSettings(), new ConsoleReportPrinter());
            evaluator = new Evaluator(context);
            evaluator.InteractiveBaseClass    = typeof(ScriptingInteractiveBase);
            evaluator.DescribeTypeExpressions = true;

            ScriptingInteractiveBase.Evaluator = evaluator;
            var errorStream = new GuiStream(TextType.Error, OnConsoleOutput);
            var guiOutput   = new StreamWriter(errorStream);

            guiOutput.AutoFlush = true;
            Console.SetError(guiOutput);
            ScriptingInteractiveBase.Output = guiOutput;

            var stdoutStream = new GuiStream(TextType.Output, OnConsoleOutput);

            guiOutput           = new StreamWriter(stdoutStream);
            guiOutput.AutoFlush = true;
            Console.SetOut(guiOutput);
            ScriptingInteractiveBase.Error = guiOutput;

            codeCompletion = new CSharpCompletion(this);

            Evaluate("using System; using System.Linq; using System.Collections; using System.Collections.Generic;");

            //init the code completion so that the first character typed is not delayed
            //var readOnlyDocument = new ReadOnlyDocument(new StringTextSource(""), "init.csx");
            //codeCompletion.GetCompletions(readOnlyDocument, 0);
        }
コード例 #2
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            completion                = new CSharpCompletion();
            editor.Completion         = completion;
            editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");

            OpenFile(@"..\SampleFiles\Sample1.cs");
        }
コード例 #3
0
        protected override void OnInitialized(EventArgs eventArgs)
        {
            base.OnInitialized(eventArgs);

            _language = "C#";

            completion = WindowFactory.Get(typeof(CSharpCompletion), new object[] { new ScriptProvider() }) as CSharpCompletion;

            TabControl.Items.Add(OpenFile());
        }
コード例 #4
0
 private void PrepareTextEditor()
 {
     codeCompletion = new ICSharpCode.CodeCompletion.CSharpCompletion();
     codeCompletion.AddAssembly("UOMachine.exe");
     scriptTextBox.Completion = codeCompletion;
     scriptTextBox.FontFamily = new FontFamily("Consolas");
     scriptTextBox.FontSize   = 12;
     scriptTextBox.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(scriptTextBox.TextArea));
     FileNew_Click(null, null);
     scriptTextBox.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
     scriptTextBox.Options            = myCurrentOptions.TextEditorOptions;
     foldingManager = FoldingManager.Install(scriptTextBox.TextArea);
     new BraceFoldingStrategy().UpdateFoldings(foldingManager, scriptTextBox.Document);
 }
コード例 #5
0
 public MainViewModel()
 {
     _completion = new CSharpCompletion(new ScriptProvider());
     _runCmd     = new SimpleCommand(() => Run());
     _doc        = new TextDocument(defaultCode)
     {
         FileName = "code.cs"
     };
     defaultRefAssemblies.Select(x => new RefDto {
         Name = x
     }).AddToCollection(_refAssemblies);
     _output.Changed              += () => OnOutputChanged();
     _consoleWriter.CharWritten   += x => _output.Append(x);
     _consoleWriter.StringWritten += x => _output.Append(x);
     SetConsoleOutput(_consoleWriter);
 }
コード例 #6
0
        private void UpdateDocument(string code)
        {
            if (doc == null)
            {
                doc        = workspace.AddDocument(project.Id, "ManagerScript.cs", SourceText.From(code));
                completion = CompletionService.GetService(doc);
            }

            Document document = doc.WithText(SourceText.From(code));

            if (!workspace.TryApplyChanges(document.Project.Solution))
            {
                throw new Exception("Unable to apply changes to solution");
            }
            doc = workspace.CurrentSolution.GetDocument(doc.Id);
        }
コード例 #7
0
        public void CreateEditor(Control parent)
        {
            ElementHost host = new ElementHost();

            host.Dock = DockStyle.Fill;

            completion = new CSharpCompletion(new ScriptProvider());

            editor                    = new CodeTextEditor();
            editor.FontFamily         = new FontFamily("Consolas");
            editor.FontSize           = 12;
            editor.Completion         = completion;
            editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
            editor.TextChanged       += OnTextChanged;

            // Very important!  The code completer throws exceptions if the document does not have a filename.
            editor.Document.FileName = "foo.cs";

            host.Child = editor;
            parent.Controls.Add(host);
        }
コード例 #8
0
        private void SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            toolTip.IsOpen = false;
            ListBox list = CompletionList.ListBox;

            if (list.Items.Count == 0)
            {
                this.Close();
            }
            for (int i = 0; i < list.Items.Count; i++)
            {
                CSharpCompletion item = list.Items[i] as CSharpCompletion;
                item.SelectionColor = Theme.CompletionBackground;
            }
            CSharpCompletion currentItem = list.SelectedValue as CSharpCompletion;

            if (currentItem != null)
            {
                CSharpCompletion data = currentItem;
                data.SelectionColor = SelectionBrush;
                CreateToolTip(data);
            }
        }
コード例 #9
0
        private void ShowCompletion(string enteredText, bool controlSpace)
        {
            if (!controlSpace)
            {
                Debug.WriteLine("Code Completion: TextEntered: " + enteredText);
            }
            else
            {
                Debug.WriteLine("Code Completion: Ctrl+Space");
            }

            //only process csharp files
            if (String.IsNullOrEmpty(textEditor.Document.FileName))
            {
                return;
            }
            var fileExtension = Path.GetExtension(textEditor.Document.FileName);

            fileExtension = fileExtension != null?fileExtension.ToLower() : null;

            //check file extension to be a c# file (.cs, .csx, etc.)
            if (fileExtension == null || (!fileExtension.StartsWith(".cs")))
            {
                return;
            }

            if (completionWindow == null)
            {
                CodeCompletionResult results = null;
                try
                {
                    results = CSharpCompletion.GetCompletions(textEditor.Document, textEditor.CaretOffset, controlSpace);
                }
                catch (Exception exception)
                {
                    Debug.WriteLine("Error in getting completion: " + exception);
                }
                if (results == null)
                {
                    return;
                }

                if (insightWindow == null && results.OverloadProvider != null)
                {
                    insightWindow          = new OverloadInsightWindow(textEditor.TextArea);
                    insightWindow.Provider = results.OverloadProvider;
                    insightWindow.Show();
                    insightWindow.Closed += (o, args) => insightWindow = null;
                    return;
                }

                if (completionWindow == null && results != null && results.CompletionData.Any())
                {
                    // Open code completion after the user has pressed dot:
                    completionWindow = new CompletionWindow(textEditor.TextArea);
                    completionWindow.CloseWhenCaretAtBeginning = controlSpace;
                    completionWindow.StartOffset -= results.TriggerWordLength;
                    //completionWindow.EndOffset -= results.TriggerWordLength;

                    IList <ICompletionData> data = completionWindow.CompletionList.CompletionData;
                    foreach (var completion in results.CompletionData.OrderBy(item => item.Text))
                    {
                        data.Add(completion);
                    }
                    if (results.TriggerWordLength > 0)
                    {
                        //completionWindow.CompletionList.IsFiltering = false;
                        completionWindow.CompletionList.SelectItem(results.TriggerWord);
                    }
                    completionWindow.Show();
                    completionWindow.Closed += (o, args) => completionWindow = null;
                }
            }//end if


            //update the insight window
            if (!string.IsNullOrEmpty(enteredText) && insightWindow != null)
            {
                //whenver text is entered update the provider
                var provider = insightWindow.Provider as CSharpOverloadProvider;
                if (provider != null)
                {
                    //since the text has not been added yet we need to tread it as if the char has already been inserted
                    provider.Update(textEditor.Document, textEditor.CaretOffset);
                    //if the windows is requested to be closed we do it here
                    if (provider.RequestClose)
                    {
                        insightWindow.Close();
                        insightWindow = null;
                    }
                }
            }
        }//end method