///////////////////////////////////////////////////////////////////////////////////////////////////// // OBJECT ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes an instance of the <c>MainControl</c> class. /// </summary> public MainControl() { InitializeComponent(); // Set the header and footer on the fragment editor's document fragmentEditor.Document.SetHeaderAndFooterText(headerEditor.Document.CurrentSnapshot.Text, footerEditor.Document.CurrentSnapshot.Text); // // NOTE: Make sure that you've read through the add-on language's 'Getting Started' topic // since it tells you how to set up an ambient parse request dispatcher and an ambient // code repository within your application OnStartup code, and add related cleanup in your // application OnExit code. These steps are essential to having the add-on perform well. // // Initialize the project assembly (enables support for automated IntelliPrompt features) projectAssembly = new CSharpProjectAssembly("SampleBrowser"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader; assemblyLoader.RunWorkerAsync(); // Load the .NET Languages Add-on C# language and register the project assembly on it var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(projectAssembly); fragmentEditor.Document.Language = language; // Create a parser-less C# language for the header/footer editors var parserlessLanguage = new CSharpSyntaxLanguage(); parserlessLanguage.UnregisterParser(); headerEditor.Document.Language = parserlessLanguage; footerEditor.Document.Language = parserlessLanguage; }
///////////////////////////////////////////////////////////////////////////////////////////////////// // OBJECT ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes an instance of the <c>MainControl</c> class. /// </summary> public MainControl() { InitializeComponent(); // // NOTE: Make sure that you've read through the add-on language's 'Getting Started' topic // since it tells you how to set up an ambient parse request dispatcher and an ambient // code repository within your application OnStartup code, and add related cleanup in your // application OnExit code. These steps are essential to having the add-on perform well. // // Initialize the project assembly (enables support for automated IntelliPrompt features) projectAssembly = new CSharpProjectAssembly("SampleBrowser"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader; assemblyLoader.RunWorkerAsync(); // Load the .NET Languages Add-on C# language and register the project assembly on it var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(projectAssembly); codeEditor.Document.Language = language; // Override the completion provider with a custom one language.RegisterService <CSharpCompletionProvider>(new CustomCSharpCompletionProvider()); }
/// <summary> /// Initializes a new instance of the <c>ParentSyntaxLanguage</c> class. /// </summary> /// <param name="projectAssembly">The project assembly to use.</param> public ParentSyntaxLanguage(IProjectAssembly projectAssembly) : base("Parent to C# example") { // Create a classification type provider and register its classification types ParentClassificationTypeProvider classificationTypeProvider = new ParentClassificationTypeProvider(); classificationTypeProvider.RegisterAll(); // Create a C# child language var childLanguage = new CSharpSyntaxLanguage(); childLanguage.RegisterProjectAssembly(projectAssembly); this.RegisterProjectAssembly(projectAssembly); // Register core parent language services this.RegisterLexer(new ParentLexer(childLanguage)); this.RegisterService(new ParentTokenTaggerProvider(classificationTypeProvider)); this.RegisterParser(new ParentParser(childLanguage)); // Register proxy IntelliPrompt services this.RegisterService(new TranslatedCSharpCompletionProvider()); this.RegisterService(new TranslatedCSharpParameterInfoProvider()); this.RegisterService(new TranslatedCSharpQuickInfoProvider()); // Register a tagger provider for showing parse errors this.RegisterService(new CodeDocumentTaggerProvider <ParseErrorTagger>(typeof(ParseErrorTagger))); // Register a squiggle tag quick info provider this.RegisterService(new SquiggleTagQuickInfoProvider()); }
public SyntaxLanguage GetSyntaxLanguage(string file) { string documentType = this.GetDocumentType(file); if (documentType == "text.C#") { if (CodeProjectService.csharpSyntaxLanguage == null) { CodeProjectService.csharpSyntaxLanguage = new CSharpSyntaxLanguage(); } return((SyntaxLanguage)CodeProjectService.csharpSyntaxLanguage); } if (documentType == "text.VB") { if (CodeProjectService.vbSyntaxLanguage == null) { CodeProjectService.vbSyntaxLanguage = new VBSyntaxLanguage(); } return((SyntaxLanguage)CodeProjectService.vbSyntaxLanguage); } if (documentType == "text.JS") { if (CodeProjectService.jsSyntaxLanguage == null) { using (Stream stream = (Stream) new MemoryStream(Microsoft.Expression.Code.FileTable.GetByteArray("Resources\\Actipro.JS.xml"))) CodeProjectService.jsSyntaxLanguage = DynamicSyntaxLanguage.LoadFromXml(stream, 0); } return((SyntaxLanguage)CodeProjectService.jsSyntaxLanguage); } if (documentType == "text.C++") { if (CodeProjectService.cppSyntaxLanguage == null) { using (Stream stream = (Stream) new MemoryStream(Microsoft.Expression.Code.FileTable.GetByteArray("Resources\\Actipro.CPP.xml"))) { try { CodeProjectService.cppSyntaxLanguage = DynamicSyntaxLanguage.LoadFromXml(stream, 0); } catch (Exception ex) { throw; } } } return((SyntaxLanguage)CodeProjectService.cppSyntaxLanguage); } if (documentType == "text") { return(SyntaxLanguage.PlainText); } return((SyntaxLanguage)null); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // OBJECT ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes an instance of the <c>MainControl</c> class. /// </summary> public MainControl() { InitializeComponent(); // Register display item classification types (so breakpoint indicator styles are registered) new DisplayItemClassificationTypeProvider().RegisterAll(); // Set the header/footer text to make the editor work as a method body editor.Document.SetHeaderAndFooterText("using System; using System.Diagnostics; using System.IO; private class Program { private void Execute() {\r\n", "\r\n}}"); // // NOTE: Make sure that you've read through the add-on language's 'Getting Started' topic // since it tells you how to set up an ambient parse request dispatcher and an ambient // code repository within your application OnStartup code, and add related cleanup in your // application OnExit code. These steps are essential to having the add-on perform well. // // Initialize the project assembly (enables support for automated IntelliPrompt features) projectAssembly = new CSharpProjectAssembly("SampleBrowser"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader; assemblyLoader.RunWorkerAsync(); // Load the .NET Languages Add-on C# language and register the project assembly on it var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(projectAssembly); // Register an indicator quick info provider language.RegisterService(new IndicatorQuickInfoProvider()); // Register an event sink that allows for handling of clicks in the indicator margin language.RegisterService(new DebuggingPointerInputEventSink()); // Assign the language editor.Document.Language = language; this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (DispatcherOperationCallback) delegate(object arg) { // Since we are initializing some default breakpoints, make sure the document parse completes in the worker thread first AmbientParseRequestDispatcherProvider.Dispatcher.WaitForParse(ParseRequest.GetParseHashKey(editor.Document)); // Add some indicators (this is dispatched since this sample relies on the document's AST being available and parsing occurs asynchronously) DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[19].StartOffset), true); DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[23].StartOffset), false); DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[28].StartOffset), true); return(null); }, null); }
public Syntax(Object ob) { cf = (Classfile)ob; InitializeComponent(); projectAssembly = new CSharpProjectAssembly("SampleBrowser"); //projectAssembly.AssemblyReferences.ItemAdded += OnAssemblyReferencesChanged; //projectAssembly.AssemblyReferences.ItemRemoved += OnAssemblyReferencesChanged; var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader; assemblyLoader.RunWorkerAsync(); // Load the .NET Languages Add-on C# language and register the project assembly on it var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(projectAssembly); codeEditor.Document.Language = language; }
private void UpdateEditorLanguage(CodeTypes codeType, bool reloadAssemblies) { UpdateAssemblyReferences(); var changeToCsharp = codeType != CodeTypes.PixateCssFile; var currentEditorLanguageIsCsharp = CodeEditor.Document.Language is CSharpSyntaxLanguage; if (currentEditorLanguageIsCsharp == changeToCsharp) { if (reloadAssemblies) { LoadEditorReferences(); } return; } ISyntaxLanguage language; if (codeType == CodeTypes.PixateCssFile) { var serializer = new SyntaxLanguageDefinitionSerializer(); using (var cssLanguageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ProtoPad_Client.Css.langdef")) { language = serializer.LoadFromStream(cssLanguageStream); } } else { // Initialize the project assembly (enables support for automated IntelliPrompt features) _projectAssembly = new CSharpProjectAssembly("ProtoPad Client"); LoadEditorReferences(); // Load the .NET Languages Add-on C# language and register the project assembly on it language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(_projectAssembly); } CodeEditor.Document.Language = language; CodeEditor.Document.Language.RegisterService(new IndicatorQuickInfoProvider()); }
public Intellisense() { ServerAssembly = new CSharpProjectAssembly("Project"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader; assemblyLoader.RunWorkerAsync(); ServerLanguage = new CSharpSyntaxLanguage(); ServerLanguage.RegisterProjectAssembly(ServerAssembly); ClientAssembly = new CSharpProjectAssembly("Client"); var clientAssemblyLoader = new BackgroundWorker(); clientAssemblyLoader.DoWork += ClientAssemblyReferenceLoader; clientAssemblyLoader.RunWorkerAsync(); ClientLanguage = new CSharpSyntaxLanguage(); ClientLanguage.RegisterProjectAssembly(ClientAssembly); ServerLanguage.RegisterService(new CodeDocumentTaggerProvider <CodeEditor.Tagger>(typeof(CodeEditor.Tagger))); ClientLanguage.RegisterService(new CodeDocumentTaggerProvider <CodeEditor.Tagger>(typeof(CodeEditor.Tagger))); }
/// <summary> /// Initializes a new instance of the <see cref="CodePanel"/>. /// </summary> public CodePanel() { InitializeComponent(); _projectAssembly = new CSharpProjectAssembly("StudioStrategy"); _projectAssembly.AssemblyReferences.AddMsCorLib(); var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(_projectAssembly); CodeEditor.Document.Language = language; _errorsSource = new ObservableCollection<CompileResultItem>(); ErrorsGrid.ItemsSource = _errorsSource; var references = new SynchronizedList<CodeReference>(); references.Added += r => _references.SafeAdd(r, r1 => { IProjectAssemblyReference asmRef = null; try { asmRef = _projectAssembly.AssemblyReferences.AddFrom(r1.Location); } catch (Exception ex) { ex.LogError(); } return asmRef; }); references.Removed += r => { var item = _projectAssembly .AssemblyReferences .FirstOrDefault(p => { var assm = p.Assembly as IBinaryAssembly; if (assm == null) return false; return assm.Location == r.Location; }); if (item != null) _projectAssembly.AssemblyReferences.Remove(item); }; references.Cleared += () => { _projectAssembly.AssemblyReferences.Clear(); _projectAssembly.AssemblyReferences.AddMsCorLib(); }; References = references; }
/// <summary> /// Returns a language for the specified extension. /// </summary> /// <param name="extension">The file extension.</param> /// <returns>The <see cref="ISyntaxLanguage"/> to use.</returns> private ISyntaxLanguage GetOrCreateLanguage(string extension) { switch (extension) { case ".cs": if (cSharpSyntaxLanguage == null) { cSharpSyntaxLanguage = new CSharpSyntaxLanguage(); var cSharpProjectAssembly = new CSharpProjectAssembly("Sample"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += (sender, e) => { // Add some common assemblies for reflection (any custom assemblies could be added using various Add overloads instead) cSharpProjectAssembly.AssemblyReferences.AddMsCorLib(); #if !NETCORE cSharpProjectAssembly.AssemblyReferences.Add("System"); cSharpProjectAssembly.AssemblyReferences.Add("System.Core"); cSharpProjectAssembly.AssemblyReferences.Add("System.Xml"); #endif }; assemblyLoader.RunWorkerAsync(); cSharpSyntaxLanguage.RegisterProjectAssembly(cSharpProjectAssembly); } return(cSharpSyntaxLanguage); case ".js": if (javaScriptSyntaxLanguage == null) { javaScriptSyntaxLanguage = new JavaScriptSyntaxLanguage(); } return(javaScriptSyntaxLanguage); case ".py": if (pythonSyntaxLanguage == null) { pythonSyntaxLanguage = new PythonSyntaxLanguage(); } return(pythonSyntaxLanguage); case ".vb": if (vbSyntaxLanguage == null) { vbSyntaxLanguage = new VBSyntaxLanguage(); var vbProjectAssembly = new VBProjectAssembly("Sample"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += (sender, e) => { // Add some common assemblies for reflection (any custom assemblies could be added using various Add overloads instead) vbProjectAssembly.AssemblyReferences.AddMsCorLib(); #if !NETCORE vbProjectAssembly.AssemblyReferences.Add("System"); vbProjectAssembly.AssemblyReferences.Add("System.Core"); vbProjectAssembly.AssemblyReferences.Add("System.Xml"); #endif }; assemblyLoader.RunWorkerAsync(); vbSyntaxLanguage.RegisterProjectAssembly(vbProjectAssembly); } return(vbSyntaxLanguage); case ".xml": if (xmlSyntaxLanguage == null) { xmlSyntaxLanguage = new XmlSyntaxLanguage(); } return(xmlSyntaxLanguage); default: return(SyntaxLanguage.PlainText); } }
/// <summary> /// Initializes a new instance of the <see cref="CodePanel"/>. /// </summary> public CodePanel() { InitializeComponent(); _projectAssembly = new CSharpProjectAssembly("StudioStrategy"); _projectAssembly.AssemblyReferences.AddMsCorLib(); var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(_projectAssembly); CodeEditor.Document.Language = language; _errorsSource = new ObservableCollection <CompileResultItem>(); ErrorsGrid.ItemsSource = _errorsSource; var references = new SynchronizedList <CodeReference>(); references.Added += r => _references.SafeAdd(r, r1 => { IProjectAssemblyReference asmRef = null; try { asmRef = _projectAssembly.AssemblyReferences.AddFrom(r1.Location); } catch (Exception ex) { ex.LogError(); } return(asmRef); }); references.Removed += r => { var item = _projectAssembly .AssemblyReferences .FirstOrDefault(p => { var assm = p.Assembly as IBinaryAssembly; if (assm == null) { return(false); } return(assm.Location == r.Location); }); if (item != null) { _projectAssembly.AssemblyReferences.Remove(item); } }; references.Cleared += () => { _projectAssembly.AssemblyReferences.Clear(); _projectAssembly.AssemblyReferences.AddMsCorLib(); }; References = references; }
public MainWindow() { InitializeComponent(); _currentDevice = new DeviceItem { DeviceAddress = "http://192.168.1.104:8080/", DeviceName = "Yarvik", DeviceType = DeviceTypes.Android }; // NOTE: Make sure that you've read through the add-on language's 'Getting Started' topic // since it tells you how to set up an ambient parse request dispatcher and an ambient // code repository within your application OnStartup code, and add related cleanup in your // application OnExit code. These steps are essential to having the add-on perform well. // Initialize the project assembly (enables support for automated IntelliPrompt features) _projectAssembly = new CSharpProjectAssembly("SampleBrowser"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader; assemblyLoader.RunWorkerAsync(); // Load the .NET Languages Add-on C# language and register the project assembly on it var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(_projectAssembly); CodeEditor.Document.Language = language; CodeEditor.Document.Language.RegisterService(new IndicatorQuickInfoProvider()); CodeEditor.PreviewKeyDown += (sender, args) => { if (args.Key != Key.Enter || (Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.Control) return; SendCodeButton_Click(null,null); args.Handled = true; }; _udpDiscoveryClient = new UdpDiscoveryClient( // ready => Dispatcher.Invoke((Action) (() => SendCodeButton.IsEnabled = ready)), ready => { }, (name, address) => Dispatcher.Invoke(() => { if (address.Contains("?")) address = address.Replace("?", AndroidPort); var deviceItem = new DeviceItem { DeviceAddress = address, DeviceName = name, DeviceType = name.StartsWith("ProtoPad Service on ANDROID Device ") ? DeviceTypes.Android : DeviceTypes.iOS }; if (!DevicesComboBox.Items.Cast<object>().Any(i => (i as DeviceItem).DeviceAddress == deviceItem.DeviceAddress)) { DevicesComboBox.Items.Add(deviceItem); } DevicesComboBox.IsEnabled = true; //ResultTextBox.Text += String.Format("Found '{0}' on {1}", name, address); })); ResultTextBox.Navigated += (sender, args) => { var htmlDocument = ResultTextBox.Document as HTMLDocument; _htmlHolder = htmlDocument.getElementById("wrapallthethings") as HTMLDivElementClass; _htmlWindow = htmlDocument.parentWindow; _udpDiscoveryClient.SendServerPing(); var ticksPassed = 0; var dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += (s, a) => { if (ticksPassed > 2) { dispatcherTimer.Stop(); if (DevicesComboBox.Items.Count == 1) { DevicesComboBox.SelectedIndex = 0; } } _udpDiscoveryClient.SendServerPing(); ticksPassed++; }; dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200); dispatcherTimer.Start(); }; ResultTextBox.NavigateToString(Properties.Resources.ResultHtmlWrap); }
public QueryWindowForm(ReferenceList referenceList) { InitializeComponent(); this.Text = Resources.SelectAllExcept; this.cbxProviders.Properties.Items.Add("MSAccessProvider"); this.cbxProviders.Properties.Items.Add("MySqlClientProvider"); this.cbxProviders.Properties.Items.Add("Npgsql2Provider"); this.cbxProviders.Properties.Items.Add("OracleClientProvider"); this.cbxProviders.Properties.Items.Add("SqlClientProvider"); this.cbxProviders.Properties.Items.Add("SQLiteProvider"); this.cbxProviders.Properties.Items.Add("SqlServerCe4Provider"); this.cbxProviders.Properties.Items.Add("SqlServerCeProvider"); this.cbxProviders.Properties.Items.Add("SybaseSqlAnywhereProvider"); this.cbxProviders.Properties.Items.Add("VistaDB4Provider"); this.cbxProviders.Properties.Items.Add("VistaDBProvider"); this.cbxProviders.SelectedIndex = 4; this.referenceList = referenceList; esAssemblies.Add("EntitySpaces.Core.dll"); esAssemblies.Add("EntitySpaces.Interfaces.dll"); esAssemblies.Add("EntitySpaces.DynamicQuery.dll"); esAssemblies.Add("EntitySpaces.Loader.dll"); esAssemblies.Add("EntitySpaces.MSAccessProvider.dll"); esAssemblies.Add("EntitySpaces.MySqlClientProvider.dll"); esAssemblies.Add("EntitySpaces.Npgsql2Provider.dll"); esAssemblies.Add("EntitySpaces.OracleClientProvider.dll"); esAssemblies.Add("EntitySpaces.SqlClientProvider.dll"); esAssemblies.Add("EntitySpaces.SQLiteProvider.dll"); esAssemblies.Add("EntitySpaces.SqlServerCe4Provider.dll"); esAssemblies.Add("EntitySpaces.SqlServerCeProvider.dll"); esAssemblies.Add("EntitySpaces.SybaseSqlAnywhereProvider.dll"); esAssemblies.Add("EntitySpaces.VistaDB4Provider.dll"); esAssemblies.Add("EntitySpaces.VistaDBProvider.dll"); esAssemblies.Add("EntitySpaces.DebuggerVisualizer.dll"); //esAssemblies.Add("EntitySpaces.Profiler.dll"); //esAssemblies.Add("XDMessaging.dll"); AssignHeaderEditorText(); footerEditor.Document.Text = @" } };"; CSharpSyntaxLanguage cSharpLanguage = new CSharpSyntaxLanguage(); syntaxEditor.Document.Filename = "Query.cs"; syntaxEditor.Document.Language = cSharpLanguage; syntaxEditor.Document.LanguageData = referenceList.ProjectResolver; syntaxEditor.Document.HeaderText = headerEditor.Document.Text; syntaxEditor.Document.FooterText = footerEditor.Document.Text; syntaxEditor.LineNumberMarginVisible = true; syntaxEditor.LineNumberMarginWidth = 20; //define color of user customized token lzbasetype.gFmtOpt.HighlightingElements[(int)TLzHighlightingElement.sfkUserCustomized].SetForegroundInRGB("#FF00FF"); foreach (var obj in lzbasetype.gFmtOpt.HighlightingElements) { if (obj.Foreground.ToString().ToLower() == "12632256") { obj.SetForegroundInRGB("#000000"); } } lzbasetype.gFmtOpt.AlignAliasInSelectList = false; }
/// <summary> /// Parses the given code asynchronously and creates a C# CodeRoot from it. /// </summary> /// <param name="filename">The name of the file being parsed. Informational use only.</param> /// <param name="code">The code to parse</param> /// <returns>A WaitHandle that will be signalled when the code is parsed and /// the CodeRoot is ready for use.</returns> public WaitHandle ParseCodeAsync(string filename, string code) { Reset(); parseWaitHandle.Reset(); parseFinished = false; parserGuid = Guid.NewGuid(); ISemanticParserServiceProcessor language = new CSharpSyntaxLanguage(); // This is needed because the Actipro parser calculates the text offsets of parsed elements // by using /r/n for line breaks (on my windows machine) even if the original text had a /r or /n. // This manifests itself as a bunch of wierd Expressions, all type names, some variable names, and // various other elements will have completely the wrong text. The number of characters in the final // output is correct though. document = new Document(); document.Text = Helper.StandardizeLineBreaks(code, Helper.LineBreaks.Windows); if (SemanticParserService.IsRunning == false) SemanticParserService.Start(); // GFH: There seems to be a problem when the service is busy doing IntelliSense int ii = SemanticParserService.PendingRequestCount; if (SemanticParserService.IsBusy || SemanticParserService.IsRunning) { try { SemanticParserService.Stop(); } catch { // Do nothing. Complains about one thread stopping another thread. } SemanticParserService.Start(); } // Make a request to the parser service (runs in a separate thread). SemanticParserServiceRequest request = new SemanticParserServiceRequest( SemanticParserServiceRequest.MediumPriority, document, new ActiproSoftware.SyntaxEditor.TextRange(0, document.Length), SemanticParseFlags.None, language, this ); SemanticParserService.Parse(request); return parseWaitHandle; }