Exemplo n.º 1
0
		public MockTextEditor()
			: base(new TextEditor())
		{
			PropertyService.InitializeServiceForUnitTests();
			pc = new DefaultProjectContent();
			pc.Language = LanguageProperties.VBNet;
			pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib);
			
			Dictionary<string, string> referencedAssemblies = new Dictionary<string, string>() {
				{ "System", null },
				{ "System.Core", null },
				{ "Microsoft.VisualBasic", null }
			};
			foreach (var assembly in referencedAssemblies) {
				IProjectContent referenceProjectContent = AssemblyParserService.DefaultProjectContentRegistry.GetProjectContentForReference(assembly.Key, assembly.Value ?? assembly.Key);
				if (referenceProjectContent == null)
					throw new Exception("Error loading " + assembly.Key);
				pc.ReferencedContents.Add(referenceProjectContent);
				if (referenceProjectContent is ReflectionProjectContent) {
					(referenceProjectContent as ReflectionProjectContent).InitializeReferences();
				}
			}
			
			this.TextEditor.TextArea.TextView.Services.AddService(typeof(ISyntaxHighlighter), new AvalonEditSyntaxHighlighterAdapter(this.TextEditor));
			this.TextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("VBNet");
			
			new VBNetLanguageBinding().Attach(this);
		}
Exemplo n.º 2
0
        public ProjectsManager()
        {
            _pcRegistry = new Dom.ProjectContentRegistry();
            _pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "FOCodeCompletion"));

            _csProjectContent = new Dom.DefaultProjectContent();
        }
Exemplo n.º 3
0
		public static ParseInformation CreateParseInfo(string code)
		{
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			ICompilationUnit compilationUnit = parser.Parse(projectContent, @"C:\test.py", code);
			return new ParseInformation(compilationUnit);
		}
		public void SetUpFixture()
		{
			string python = "class Test:\r\n" +
							"\tdef foo(self):\r\n" +
							"\t\tpass";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);			
			if (compilationUnit.Classes.Count > 0) {
				c = compilationUnit.Classes[0];
				if (c.Methods.Count > 0) {
					method = c.Methods[0];
				}
				
				TextArea textArea = new TextArea();
				document = new TextDocument();
				textArea.Document = document;
				textArea.Document.Text = python;
				
				ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea);
				
				ParseInformation parseInfo = new ParseInformation(compilationUnit);
				foldingStrategy.UpdateFoldings(parseInfo);
				List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings);
				
				if (folds.Count > 0) {
					classFold = folds[0];
				}
				if (folds.Count > 1) {
					methodFold = folds[1];
				}
			}
		}
		public void SetUpFixture()
		{
			string ruby = "class Test\r\n" +
							"\tdef initialize\r\n" +
							"\t\tputs 'test'\r\n" +
							"\tend\r\n" +
							"end";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			RubyParser parser = new RubyParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby);			
			if (compilationUnit.Classes.Count > 0) {
				c = compilationUnit.Classes[0];
				if (c.Methods.Count > 0) {
					method = c.Methods[0];
				}
				
				TextArea textArea = new TextArea();
				document = new TextDocument();
				textArea.Document = document;
				textArea.Document.Text = ruby;
				
				// Get folds.
				ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea);
				
				ParseInformation parseInfo = new ParseInformation(compilationUnit);
				foldingStrategy.UpdateFoldings(parseInfo);
				List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings);
			
				if (folds.Count > 1) {
					classFold = folds[0];
					methodFold = folds[1];
				}
			}
		}
Exemplo n.º 6
0
		public MockTextEditor()
			: base(new TextEditor())
		{
			PropertyService.InitializeServiceForUnitTests();
			pc = new DefaultProjectContent();
			pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib);
			
			Dictionary<string, string> referencedAssemblies = new Dictionary<string, string>() {
				{ "System", typeof(Uri).Assembly.Location },
				{ "System.Xml", typeof(System.Xml.XmlDocument).Assembly.Location },
				{ "System.Xaml", typeof(System.Xaml.XamlReader).Assembly.Location },
				{ "WindowsBase", typeof(System.Windows.Media.Matrix).Assembly.Location },
				{ "System.Core", typeof(System.Linq.Enumerable).Assembly.Location },
				{ "PresentationCore", typeof(System.Windows.Media.Brush).Assembly.Location },
				{ "PresentationFramework", typeof(System.Windows.EventSetter).Assembly.Location }
			};
			foreach (var assembly in referencedAssemblies) {
				IProjectContent referenceProjectContent = AssemblyParserService.DefaultProjectContentRegistry.GetProjectContentForReference(assembly.Key, assembly.Value ?? assembly.Key);
				if (referenceProjectContent == null)
					throw new Exception("Error loading " + assembly.Key);
				pc.ReferencedContents.Add(referenceProjectContent);
				if (referenceProjectContent is ReflectionProjectContent) {
					(referenceProjectContent as ReflectionProjectContent).InitializeReferences();
				}
			}
			
//			this.TextEditor.TextArea.TextView.Services.AddService(typeof(ISyntaxHighlighter), new AvalonEditSyntaxHighlighterAdapter(this.TextEditor));
			this.TextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML");
			
			new XamlLanguageBinding().Attach(this);
		}
		public void SetUpFixture()
		{
			string python = "class";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);			
		}
		public void SetUpFixture()
		{
			string Ruby = "require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			RubyParser parser = new RubyParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby);	
		}
		public void Init()
		{
			string python = "from math import *";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);
			import = compilationUnit.UsingScope.Usings[0] as PythonFromImport;
		}
Exemplo n.º 10
0
		public MockTextEditor()
			: base(new TextEditor())
		{
			PropertyService.InitializeServiceForUnitTests();
			pc = new DefaultProjectContent();
			pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib);
			
//			this.TextEditor.TextArea.TextView.Services.AddService(typeof(ISyntaxHighlighter), new AvalonEditSyntaxHighlighterAdapter(this.TextEditor));
			this.TextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
		}
		public void SetUpFixture()
		{
			string ruby = "class Class1\r\n" +
				"    @\r\n" +
				"end";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			RubyParser parser = new RubyParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby);			
		}
		public void Init()
		{
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent);
			existingParseInfo = new ParseInformation(unit);
			
			parserService = new MockParserService();
			parserService.SetExistingParseInformation(@"d:\projects\test.xml", existingParseInfo);
		}
		public void ParseDoesNotThrowNullReferenceException()
		{
			string ruby = "require #";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			RubyParser parser = new RubyParser();
			ICompilationUnit unit = null;
		
			Assert.DoesNotThrow(delegate { unit = parser.Parse(projectContent, @"C:\test.rb", ruby); });
			Assert.IsNotNull(unit);
		}
Exemplo n.º 14
0
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            if (IsVisualBasic)
            {
                textEditorControl1.Text = @"
Class A
 Sub B
  Dim xx As String
  
 End Sub
End Class
";
                textEditorControl1.SetHighlighting("VBNET");
            }
            else
            {
                textEditorControl1.Text = @"using System;
class A
{
 void B()
 {
  string x;
  
 }
}
";
                textEditorControl1.SetHighlighting("C#");
            }
            textEditorControl1.ShowEOLMarkers   = false;
            textEditorControl1.ShowInvalidLines = false;
            HostCallbackImplementation.Register(this);
            CodeCompletionKeyHandler.Attach(this, textEditorControl1);
            ToolTipProvider.Attach(this, textEditorControl1);

            pcRegistry = new Dom.ProjectContentRegistry();             // Default .NET 2.0 registry

            // Persistence lets SharpDevelop.Dom create a cache file on disk so that
            // future starts are faster.
            // It also caches XML documentation files in an on-disk hash table, thus
            // reducing memory usage.
            pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(),
                                                        "CSharpCodeCompletion"));

            myProjectContent          = new Dom.DefaultProjectContent();
            myProjectContent.Language = CurrentLanguageProperties;
            // create dummy parseInformation to prevent NullReferenceException when using CC before parsing
            // for the first time
            parseInformation = new Dom.ParseInformation(new Dom.DefaultCompilationUnit(myProjectContent));
        }
		public void SetUpFixture()
		{
			string python = "class Test:\r\n" +
							"\tpass";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			compilationUnit = parser.Parse(projectContent, @"C:\Projects\Test\test.py", python);
			if (compilationUnit.Classes.Count > 0) {
				c = compilationUnit.Classes[0];
			}
		}
Exemplo n.º 16
0
		ICompilationUnit Prepare(LanguageProperties language)
		{
			DefaultProjectContent pc = new DefaultProjectContent();
			pc.ReferencedContents.Add(projectContentRegistry.Mscorlib);
			pc.Language = language;
			DefaultCompilationUnit cu = new DefaultCompilationUnit(pc);
			if (language == LanguageProperties.VBNet)
				cu.UsingScope.Usings.Add(CreateUsing(pc, "syStEm"));
			else
				cu.UsingScope.Usings.Add(CreateUsing(pc, "System"));
			return cu;
		}
		public void SetUpFixture()
		{
			string Ruby = "class Test\r\n" +
							"end";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			RubyParser parser = new RubyParser();
			compilationUnit = parser.Parse(projectContent, @"C:\Projects\Test\test.rb", Ruby);
			if (compilationUnit.Classes.Count > 0) {
				c = compilationUnit.Classes[0];
			}
		}
		public void SetUpFixture()
		{
			string python = "import System\r\n" +
							"\r\n" +
							"class Class1:\r\n" +
							"	def __init__(self):\r\n" +
							"		Console.\r\n" +
							"		pass\r\n";

			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);			
		}
		public void Init()
		{
			DefaultProjectContent projectContent = new DefaultProjectContent();
			unit = new DefaultCompilationUnit(projectContent);
			DefaultClass c = new DefaultClass(unit, "Foo");
			
			DefaultMethod buttonClickMethod = new DefaultMethod(c, "ButtonClick");
			AddSenderAndEventArgsParameters(buttonClickMethod);
			c.Methods.Add(buttonClickMethod);
			
			projectContent.AddClassToNamespaceList(c);
			
			parseInfo = new ParseInformation(unit);
		}
Exemplo n.º 20
0
		public void FixtureSetup()
		{
			ProjectContentRegistry r = new ProjectContentRegistry();
			msc = r.Mscorlib;
			swf = r.GetProjectContentForReference("System.Windows.Forms", typeof(System.Windows.Forms.Form).Module.FullyQualifiedName);
			
			DefaultProjectContent dpc = new DefaultProjectContent();
			dpc.ReferencedContents.Add(msc);
			DefaultCompilationUnit cu = new DefaultCompilationUnit(dpc);
			dummyClass = new DefaultClass(cu, "DummyClass");
			cu.Classes.Add(dummyClass);
			methodForGenericCalls = new DefaultMethod(dummyClass, "DummyMethod");
			dummyClass.Methods.Add(methodForGenericCalls);
		}
		void TestProgram(SupportedLanguage sourceLanguage, string sourceCode, string expectedOutput)
		{
			DefaultProjectContent pc = new DefaultProjectContent();
			pc.ReferencedContents.Add(projectContentRegistry.Mscorlib);
			pc.ReferencedContents.Add(projectContentRegistry.GetProjectContentForReference("System.Windows.Forms", "System.Windows.Forms"));
			if (sourceLanguage == SupportedLanguage.VBNet) {
				pc.ReferencedContents.Add(projectContentRegistry.GetProjectContentForReference("Microsoft.VisualBasic", "Microsoft.VisualBasic"));
				pc.DefaultImports = new DefaultUsing(pc);
				pc.DefaultImports.Usings.Add("System");
				pc.DefaultImports.Usings.Add("Microsoft.VisualBasic");
			}
			pc.Language = sourceLanguage == SupportedLanguage.CSharp ? LanguageProperties.CSharp : LanguageProperties.VBNet;
			HostCallback.GetCurrentProjectContent = delegate {
				return pc;
			};
			
			ICSharpCode.NRefactory.IParser parser = ParserFactory.CreateParser(sourceLanguage, new StringReader(sourceCode));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			
			NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(pc);
			visitor.VisitCompilationUnit(parser.CompilationUnit, null);
			visitor.Cu.FileName = sourceLanguage == SupportedLanguage.CSharp ? "a.cs" : "a.vb";
			foreach (IClass c in visitor.Cu.Classes) {
				pc.AddClassToNamespaceList(c);
			}
			
			ParseInformation parseInfo = new ParseInformation();
			parseInfo.SetCompilationUnit(visitor.Cu);
			
			if (sourceLanguage == SupportedLanguage.CSharp) {
				CSharpToVBNetConvertVisitor convertVisitor = new CSharpToVBNetConvertVisitor(pc, parseInfo);
				convertVisitor.RootNamespaceToRemove = "RootNamespace";
				parser.CompilationUnit.AcceptVisitor(convertVisitor, null);
			} else {
				VBNetToCSharpConvertVisitor convertVisitor = new VBNetToCSharpConvertVisitor(pc, parseInfo);
				parser.CompilationUnit.AcceptVisitor(convertVisitor, null);
			}
			
			IOutputAstVisitor outputVisitor = sourceLanguage == SupportedLanguage.CSharp ? (IOutputAstVisitor)new VBNetOutputVisitor() : new CSharpOutputVisitor();
			outputVisitor.Options.IndentationChar = ' ';
			outputVisitor.Options.IndentSize = 2;
			using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(),
			                                    outputVisitor)) {
				outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			}
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(expectedOutput.Replace("\r", ""), outputVisitor.Text.Trim().Replace("\r", ""));
		}
		protected virtual void DoTearDown()
		{
			if (this.defaultPC != null) {
				this.defaultPC.Dispose();
				this.defaultPC = null;
			}
			if (this.project != null) {
				this.project.Dispose();
				this.project = null;
			}
			if (this.solution != null) {
				this.solution.Dispose();
				this.solution = null;
			}
		}
        protected virtual DefaultProjectContent CreateNewProjectContent(IProject project)
        {
            DefaultProjectContent pc = new DefaultProjectContent();

            pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib);
            pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.GetProjectContentForReference("System", typeof(Uri).Module.FullyQualifiedName));

            if (project != null) {
                if (project.LanguageProperties != null) {
                    pc.Language = project.LanguageProperties;
                }
            }

            return pc;
        }
		protected virtual void DoSetUp()
		{
			TestHelper.InitializeParsers();
			
			this.solution = new Solution(new MockProjectChangeWatcher());
			this.project = this.CreateTestProject();
			ProjectService.CurrentProject = this.project;
			
			DefaultProjectContent pc = this.CreateNewProjectContent(this.project);
			HostCallback.GetCurrentProjectContent = delegate {
				return pc;
			};
			ResourceResolverService.SetProjectContentUnitTestOnly(this.project, pc);
			this.defaultPC = pc;
		}
Exemplo n.º 25
0
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
            string appPath = Path.GetDirectoryName(Application.ExecutablePath);

            this.sqlConnection1.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + quot + Data_Path + quot + ";Integrated Security=True;User Instance=False;Timeout=60";

            ICSharpCode.TextEditor.Document.FileSyntaxModeProvider provider = new ICSharpCode.TextEditor.Document.FileSyntaxModeProvider(appPath);
            ICSharpCode.TextEditor.Document.HighlightingManager.Manager.AddSyntaxModeFileProvider(provider);
            sqlEditor.Document.HighlightingStrategy = ICSharpCode.TextEditor.Document.HighlightingManager.Manager.FindHighlighter("SQL");


            sqlEditor.Text = @"SELECT word.lemma, synset.pos, synset.definition 
FROM word
LEFT JOIN sense ON word.wordid=sense.wordid
LEFT JOIN synset ON sense.synsetid=synset.synsetid
WHERE word.lemma='light'
ORDER BY synset.pos

";
//			sqlEditor.SetHighlighting("C#");
//			sqlEditor.SetHighlighting("SQL");
            sqlEditor.ShowEOLMarkers = false;
            CodeCompletionKeyHandler.Attach(this, sqlEditor);
            HostCallbackImplementation.Register(this);

            pcRegistry = new Dom.ProjectContentRegistry();             // Default .NET 2.0 registry

            // Persistence caches referenced project contents for faster loading.
            // It also activates loading XML documentation files and caching them
            // for faster loading and lower memory usage.
            pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(),
                                                        "CSharpCodeCompletion"));

            myProjectContent = new Dom.DefaultProjectContent();
            //myProjectContent.Language = Dom.LanguageProperties.CSharp;

            myProjectContent.Language = Dom.LanguageProperties.VBNet;
        }
		public void SetUpFixture()
		{
			string python = "class Test(Base):\r\n" +
							"\tdef foo(self, sender, e):\r\n" +
							"\t\tpass";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			ICompilationUnit compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);			
			if (compilationUnit.Classes.Count > 0) {
				IClass c = compilationUnit.Classes[0];
				method = c.Methods[0];
				if (method.Parameters.Count > 1) {
					senderParameter = method.Parameters[0];
					eventArgsParameter = method.Parameters[1];
				}
			}
		}
		public void SetUpFixture()
		{
			string Ruby = "class Test\r\n" +
							"\tdef foo(a = 1, b = 'test')\r\n" +
							"\tend\r\n" +
							"end";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			RubyParser parser = new RubyParser();
			ICompilationUnit compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby);			
			if (compilationUnit.Classes.Count > 0) {
				IClass c = compilationUnit.Classes[0];
				method = c.Methods[0];
				if (method.Parameters.Count > 1) {
					parameterA = method.Parameters[0];
					parameterB = method.Parameters[1];
				}
			}
		}
		public void SetUpFixture()
		{
			string python =
				"class MyClass:\r\n" +
				"    def firstMethod(self):\r\n" +
				"        class NestedClass:\r\n" +
				"            def firstNestedClassMethod(self):\r\n" +
				"                pass\r\n" +
				"\r\n" +
				"    def secondMethod(self):\r\n" +
				"        pass\r\n" +
				"\r\n";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);
			if (compilationUnit.Classes.Count > 0) {
				c = compilationUnit.Classes[0];
			}
		}
		public void SetUpFixture()
		{
			string python = 
				"import unittest\r\n" +
				"\r\n" +
				"class simpleTest(unittest.TestCase):\r\n" +
				"    def testSuccess(self):\r\n" +
				"        assert True\r\n" +
				"\r\n" +
				"    def testFailure(self):\r\n" +
				"        assert False\r\n" +
				"\r\n";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);
			if (compilationUnit.Classes.Count > 0) {
				c = compilationUnit.Classes[0];
			}
		}
		public void ConvertedRubyCode()
		{
			string expectedCode =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        button = Button.new()\r\n" +
				"        button.Click { self.ButtonClick() }\r\n" +
				"        button.MouseDown { self.OnMouseDown() }\r\n" +
				"    end\r\n" +
				"end";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent);
			ParseInformation parseInfo = new ParseInformation(unit);
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp, parseInfo);
			converter.IndentString = "    ";
			string code = converter.Convert(csharp);
			
			Assert.AreEqual(expectedCode, code, code);
		}
		public void SetUpFixture()
		{
			string python = 
				"import unittest\r\n" +
				"\r\n" +
				"class BaseTest(unittest.TestCase):\r\n" +
				"    def testSuccess(self):\r\n" +
				"        assert True\r\n" +
				"\r\n" +
				"class DerivedTest(BaseTest):\r\n" +
				"    pass\r\n" +
				"\r\n";
			
			projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			string fileName = @"C:\test.py";
			compilationUnit = parser.Parse(projectContent, fileName, python);
			projectContent.UpdateCompilationUnit(null, compilationUnit, fileName);
			if (compilationUnit.Classes.Count > 1) {
				c = compilationUnit.Classes[1];
			}
		}
		public void SetUpFixture()
		{
			string ruby =
				"def foo\r\n" +
				"end\r\n" +
				"\r\n" +
				"def bar(i)\r\n" +
				"end";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			RubyParser parser = new RubyParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby);			
			
			if (compilationUnit.Classes.Count > 0) {
				globalClass = compilationUnit.Classes[0];
				if (globalClass.Methods.Count > 1) {
					fooMethod = globalClass.Methods[0];
					barMethod = globalClass.Methods[1];
				}
			}
	
			// Get folds.
			TextArea textArea = new TextArea();
			document = new TextDocument();
			textArea.Document = document;
			textArea.Document.Text = ruby;
			
			ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea);
			
			ParseInformation parseInfo = new ParseInformation(compilationUnit);
			foldingStrategy.UpdateFoldings(parseInfo);
			List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings);
		
			if (folds.Count > 1) {
				fooMethodFold = folds[0];
				barMethodFold = folds[1];
			}
		}
Exemplo n.º 33
0
		// usingMode: 0 = one using-statement for each namespace (correctly cased)
		//            1 = mixture of using statements and default imports (incorrectly cased)
		//            2 = all default imports (incorrectly cased)
		ICompilationUnit Prepare(LanguageProperties language, int usingMode)
		{
			DefaultProjectContent pc = new DefaultProjectContent();
			pc.ReferencedContents.Add(projectContentRegistry.Mscorlib);
			pc.Language = language;
			DefaultCompilationUnit cu = new DefaultCompilationUnit(pc);
			if (usingMode == 1) {
				cu.UsingScope.Usings.Add(CreateUsing(pc, "syStEm.coLLectIons"));
				pc.DefaultImports = new DefaultUsing(pc);
				pc.DefaultImports.Usings.Add("syStEm");
				pc.DefaultImports.Usings.Add("syStEm.coLLEctionS.GeNeRic");
			} else if (usingMode == 2) {
				pc.DefaultImports = new DefaultUsing(pc);
				pc.DefaultImports.Usings.Add("syStEm");
				pc.DefaultImports.Usings.Add("syStEm.coLLEctioNs");
				pc.DefaultImports.Usings.Add("syStEm.coLLEctionS.GeNeRic");
			} else { // usingMode == 0
				cu.UsingScope.Usings.Add(CreateUsing(pc, "System"));
				cu.UsingScope.Usings.Add(CreateUsing(pc, "System.Collections"));
				cu.UsingScope.Usings.Add(CreateUsing(pc, "System.Collections.Generic"));
			}
			return cu;
		}
Exemplo n.º 34
0
        public IntellisenseEditor()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            textEditorControl1.SetHighlighting(Language);
            textEditorControl1.ShowEOLMarkers = false;
            CodeCompletionKeyHandler.Attach(this, textEditorControl1);
            HostCallbackImplementation.Register(this);

            pcRegistry = new Dom.ProjectContentRegistry();             // Default .NET 2.0 registry

            // Persistence caches referenced project contents for faster loading.
            // It also activates loading XML documentation files and caching them
            // for faster loading and lower memory usage.
            pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(),
                                                        "CSharpCodeCompletion"));

            myProjectContent          = new Dom.DefaultProjectContent();
            myProjectContent.Language = Dom.LanguageProperties.CSharp;
        }
Exemplo n.º 35
0
        public ScriptForm(PBObjLib.Application app)
        {
            m_App = app;
            InitializeComponent();
            editor.ShowEOLMarkers   = false;
            editor.ShowSpaces       = false;
            editor.ShowTabs         = false;
            editor.ShowInvalidLines = false;
            editor.SetHighlighting("C#");
            workDir           = Path.GetTempPath() + "gPBToolKit\\";
            fullPathDummyFile = workDir + DummyFileName;

            if (!Directory.Exists(workDir))
            {
                Directory.CreateDirectory(workDir);
            }
            if (!Directory.Exists(workDir + "\\CSharpCodeCompletion\\"))
            {
                Directory.CreateDirectory(workDir + "\\CSharpCodeCompletion");
            }



            string indexFile = workDir + "CSharpCodeCompletion\\index.dat";

            if (!File.Exists(fullPathDummyFile))
            {
                string       sh           = @"using System;
using System.Collections.Generic;
using System.Text;
using PBObjLib;
using PBSymLib;
using VBIDE;
using System.Windows.Forms;

namespace gPBToolKit
{
    public class gkScript
    {   
        // ���������� �������� �������
        public static void StartScript(Display d)
        {
            foreach (Symbol s in d.Symbols)
            {
                if (s.Type == 7)
                {
                    Value v = (Value)s;
                    v.BackgroundColor = 32768;  
                    v.ShowUOM = true;
                }           
            }
            Action(d.Application);
        }
        
        public static void Action(PBObjLib.Application m_App)
        {
            try
            {
                VBProject project = null;
                CodeModule codeModule = null;
                for (int i = 1; i <= ((VBE)m_App.VBE).VBProjects.Count; i++)
                {
                    VBProject bufProject = ((VBE)m_App.VBE).VBProjects.Item(i);
                    if (bufProject.FileName.ToLower() == m_App.ActiveDisplay.Path.ToLower()) // ���� �� ��������� ����� ������
                    {
                        project = bufProject;
                        break;
                    }
                }

                if (project == null)
                {
                    MessageBox.Show(""VBProject not found"");
                    return;
                }

                codeModule = project.VBComponents.Item(""ThisDisplay"").CodeModule;
                try
                {
                    string procName = ""Display_Open"";
                    int procCountLine = -1, procStart = -1;
                    try{
						procStart = codeModule.get_ProcBodyLine(procName, vbext_ProcKind.vbext_pk_Proc);
                        procCountLine = codeModule.get_ProcCountLines(procName, vbext_ProcKind.vbext_pk_Proc);	
                    }
                    catch{}
                    
                    if (procStart > 0) 
                        codeModule.DeleteLines(procStart, procCountLine);
                    
                    string srvName = ""do51-dc1-du-pis.sgpz.gpp.gazprom.ru"";
                    string rootModule = ""����"";                   
                    string dispOpenText = string.Format(@""
Private Sub Display_Open()
    AVExtension1.Initialize """"{0}"""", """"{1}"""", ThisDisplay, Trend1
End Sub"", srvName, rootModule);
                    codeModule.AddFromString(dispOpenText);			
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message + "" ""+ ex.StackTrace);
                }
            }
            catch { }
        }
    }
}
";
                UTF8Encoding asciEncoding = new UTF8Encoding();
                FileStream   fs           = File.Create(fullPathDummyFile);
                fs.Write(asciEncoding.GetBytes(sh), 0, asciEncoding.GetByteCount(sh));
                fs.Close();
            }
            if (!File.Exists(indexFile))
            {
                File.Create(indexFile).Close();
            }


            editor.LoadFile(fullPathDummyFile);

            refList.Items.Add("System.dll");
            refList.Items.Add("System.Drawing.dll");
            refList.Items.Add("System.Windows.Forms.dll");
            refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\OSIsoft.PBObjLib.dll");
            refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\OSIsoft.PBSymLib.dll");
            refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\Interop.VBIDE.dll");

            CodeCompletionKeyHandler.Attach(this, editor);
            HostCallbackImplementation.Register(this);

            pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry

            // Persistence caches referenced project contents for faster loading.
            // It also activates loading XML documentation files and caching them
            // for faster loading and lower memory usage.
            pcRegistry.ActivatePersistence(Path.Combine(workDir, "CSharpCodeCompletion"));

            myProjectContent          = new Dom.DefaultProjectContent();
            myProjectContent.Language = Dom.LanguageProperties.CSharp;
        }