public RoslynSemanticHighlighter(IDocument document, DocumentId documentId, RoslynHost roslynHost) { if (document == null) { throw new ArgumentNullException(nameof(document)); } _document = document; _documentId = documentId; _roslynHost = roslynHost; _semaphore = new SemaphoreSlim(0); _queue = new ConcurrentQueue <HighlightedLine>(); if (document is TextDocument) { // Use the cache only for the live AvalonEdit document // Highlighting in read-only documents (e.g. search results) does // not need the cache as it does not need to highlight the same line multiple times _cachedLines = new List <CachedLine>(); } _syncContext = SynchronizationContext.Current; _cts = new CancellationTokenSource(); var cancellationToken = _cts.Token; Task.Run(() => Worker(cancellationToken), cancellationToken); }
public DocumentViewModel(RoslynHost host) { this.host = host; this.SxFy = new List <SxFyLogEntry>(); this.Result = HintProvider.GetUsageHint(); this.StatusLine = HintProvider.NoLogFilesLoadedYetText(); }
public async Task CloseDocument(OpenDocumentViewModel document) { if (document == null) { return; } var result = await document.Save(promptSave : true).ConfigureAwait(true); if (result == SaveResult.Cancel) { return; } // ReSharper disable once PossibleNullReferenceException var autoSavePath = document.Document?.GetAutoSavePath(); if (autoSavePath != null && File.Exists(autoSavePath)) { File.Delete(autoSavePath); } RoslynHost.CloseDocument(document.DocumentId); OpenDocuments.Remove(document); document.Close(); }
private async void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs args) { _viewModel = (OpenDocumentViewModel)args.NewValue; _viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled; _roslynHost = _viewModel.MainViewModel.RoslynHost; _viewModel.MainViewModel.EditorFontSizeChanged += OnEditorFontSizeChanged; Editor.FontSize = _viewModel.MainViewModel.EditorFontSize; var avalonEditTextContainer = new AvalonEditTextContainer(Editor); await _viewModel.Initialize( avalonEditTextContainer, a => _syncContext.Post(o => ProcessDiagnostics(a), null), text => avalonEditTextContainer.UpdateText(text), this).ConfigureAwait(true); var documentText = await _viewModel.LoadText().ConfigureAwait(true); Editor.AppendText(documentText); Editor.Document.UndoStack.ClearAll(); Editor.Document.TextChanged += (o, e) => _viewModel.SetDirty(Editor.Document.TextLength); Editor.TextArea.TextView.LineTransformers.Insert(0, new RoslynHighlightingColorizer(_viewModel.DocumentId, _roslynHost)); _contextActionsRenderer = new ContextActionsRenderer(Editor, _textMarkerService); _contextActionsRenderer.Providers.Add(new RoslynContextActionProvider(_viewModel.DocumentId, _roslynHost)); Editor.CompletionProvider = new RoslynCodeEditorCompletionProvider(_viewModel.DocumentId, _roslynHost); }
protected override void OnLoad(EventArgs e) { roslynCodeEditor.CreatingDocument += RoslynCodeEditor_CreatingDocument; roslynCodeEditor.DocumentChanged += RoslynCodeEditor_DocumentChanged; RoslynHostReferences roslynHostReferences = RoslynHostReferences.Empty.With( assemblyReferences: new[] { Assembly.GetExecutingAssembly() }); var context = GlobalContext; if (context is null) { context = new Empty(); } roslynHost = new CustomHost( context.GetType(), additionalAssemblies: new[] { Assembly.Load("RoslynPad.Roslyn.Windows"), Assembly.Load("RoslynPad.Editor.Windows") }, references: roslynHostReferences); elementHost1.Child = roslynCodeEditor; //roslynCodeEditor.Document = new ICSharpCode.AvalonEdit.Document.TextDocument(); docId = roslynCodeEditor.Initialize(roslynHost, new ClassificationHighlightColors(), System.IO.Directory.GetCurrentDirectory(), string.Empty); base.OnLoad(e); }
public RoslynContextActionProvider(ICommandProvider commandProvider, DocumentId documentId, RoslynHost roslynHost) { _commandProvider = commandProvider; _documentId = documentId; _roslynHost = roslynHost; _codeFixService = _roslynHost.GetService <ICodeFixService>(); }
public CodeEditorCompletionProvider(RoslynHost roslynHost, Workspace workspace, DocumentId documentId) { _documentId = documentId; _workspace = workspace; _roslynHost = roslynHost; _snippetService = (AltaxoSnippetInfoService)_roslynHost.GetService <ICSharpEditSnippetInfoService>(); }
public MainViewModel(IServiceLocator serviceLocator, ITelemetryProvider telemetryProvider, ICommandProvider commands, NuGetViewModel nugetViewModel) { _serviceLocator = serviceLocator; _telemetryProvider = telemetryProvider; _telemetryProvider.Initialize(_currentVersion.ToString()); _telemetryProvider.LastErrorChanged += () => OnPropertyChanged(nameof(LastError)); NuGet = nugetViewModel; NuGetConfiguration = new NuGetConfiguration(NuGet.GlobalPackageFolder, NuGetPathVariableName); RoslynHost = new RoslynHost(NuGetConfiguration, new[] { // TODO: xplat Assembly.Load("RoslynPad.Roslyn.Windows"), Assembly.Load("RoslynPad.Editor.Windows") }); NewDocumentCommand = commands.Create(CreateNewDocument); CloseCurrentDocumentCommand = commands.CreateAsync(CloseCurrentDocument); ClearErrorCommand = commands.Create(() => _telemetryProvider.ClearLastError()); ReportProblemCommand = commands.Create(ReportProblem); EditUserDocumentPathCommand = commands.Create(EditUserDocumentPath); _editorFontSize = Properties.Settings.Default.EditorFontSize; DocumentRoot = CreateDocumentRoot(); OpenDocuments = new ObservableCollection <OpenDocumentViewModel>(); OpenDocuments.CollectionChanged += (sender, args) => OnPropertyChanged(nameof(HasNoOpenDocuments)); }
public MainViewModel() { var hockeyClient = (HockeyClient)HockeyClient.Current; if (SendTelemetry) { hockeyClient.Configure(HockeyAppId) .RegisterCustomDispatcherUnhandledExceptionLogic(OnUnhandledDispatcherException) .UnregisterDefaultUnobservedTaskExceptionHandler(); var platformHelper = (HockeyPlatformHelperWPF)hockeyClient.PlatformHelper; platformHelper.AppVersion = _currentVersion.ToString(); hockeyClient.TrackEvent(TelemetryEventNames.Start); } else { Application.Current.DispatcherUnhandledException += (sender, args) => OnUnhandledDispatcherException(args); var platformHelper = new HockeyPlatformHelperWPF { AppVersion = _currentVersion.ToString() }; hockeyClient.PlatformHelper = platformHelper; hockeyClient.AppIdentifier = HockeyAppId; } NuGet = new NuGetViewModel(); NuGetConfiguration = new NuGetConfiguration(NuGet.GlobalPackageFolder, NuGetPathVariableName); RoslynHost = new RoslynHost(NuGetConfiguration, new[] { Assembly.Load("RoslynPad.RoslynEditor") }); NewDocumentCommand = new DelegateCommand((Action)CreateNewDocument); CloseCurrentDocumentCommand = new DelegateCommand(CloseCurrentDocument); ClearErrorCommand = new DelegateCommand(() => LastError = null); ReportProblemCommand = new DelegateCommand((Action)ReportProblem); _editorFontSize = Properties.Settings.Default.EditorFontSize; DocumentRoot = CreateDocumentRoot(); Documents = DocumentRoot.Children; OpenDocuments = new ObservableCollection <OpenDocumentViewModel>(LoadAutoSaves(DocumentRoot.Path)); OpenDocuments.CollectionChanged += (sender, args) => OnPropertyChanged(nameof(HasNoOpenDocuments)); if (HasNoOpenDocuments) { CreateNewDocument(); } else { CurrentOpenDocument = OpenDocuments[0]; } if (HasCachedUpdate()) { HasUpdate = true; } else { Task.Run(CheckForUpdates); } }
internal RoslynWorkspace(HostServices host, INuGetProvider nuGetProvider, RoslynHost roslynHost) : base(host, WorkspaceKind.Host) { _nuGetProvider = nuGetProvider; _referencesDirectives = new ConcurrentDictionary<string, DirectiveInfo>(); RoslynHost = roslynHost; }
private void OnLoaded(object sender, RoutedEventArgs e) { Loaded -= OnLoaded; _host = new RoslynHost(additionalAssemblies: new[] { Assembly.Load("RoslynPad.Roslyn.Windows"), Assembly.Load("RoslynPad.Editor.Windows") }); AddNewDocument(); }
public MainViewModel() { _telemetryClient = new TelemetryClient { InstrumentationKey = ApplicationInsightsInstrumentationKey }; _telemetryClient.Context.Component.Version = _currentVersion.ToString(); #if DEBUG _telemetryClient.Context.Properties["DEBUG"] = "1"; #endif if (SendTelemetry) { _telemetryClient.TrackEvent(TelemetryEventNames.Start); } Application.Current.DispatcherUnhandledException += (o, e) => OnUnhandledDispatcherException(e); AppDomain.CurrentDomain.UnhandledException += (o, e) => OnUnhandledException((Exception)e.ExceptionObject, flushSync: true); TaskScheduler.UnobservedTaskException += (o, e) => OnUnhandledException(e.Exception); NuGet = new NuGetViewModel(); NuGetConfiguration = new NuGetConfiguration(NuGet.GlobalPackageFolder, NuGetPathVariableName); RoslynHost = new RoslynHost(NuGetConfiguration, new[] { Assembly.Load("RoslynPad.RoslynEditor") }); ChildProcessManager = new ChildProcessManager(); NewDocumentCommand = new DelegateCommand((Action)CreateNewDocument); CloseCurrentDocumentCommand = new DelegateCommand(CloseCurrentDocument); ClearErrorCommand = new DelegateCommand(() => LastError = null); ReportProblemCommand = new DelegateCommand((Action)ReportProblem); _editorFontSize = Properties.Settings.Default.EditorFontSize; DocumentRoot = CreateDocumentRoot(); Documents = DocumentRoot.Children; OpenDocuments = new ObservableCollection <OpenDocumentViewModel>(LoadAutoSaves(DocumentRoot.Path)); OpenDocuments.CollectionChanged += (sender, args) => OnPropertyChanged(nameof(HasNoOpenDocuments)); if (HasNoOpenDocuments) { CreateNewDocument(); } else { CurrentOpenDocument = OpenDocuments[0]; } if (HasCachedUpdate()) { HasUpdate = true; } else { Task.Run(CheckForUpdates); } }
private void InitializeInternal() { RoslynHost = new RoslynHost(NuGetConfiguration, CompositionAssemblies, RoslynHostReferences.Default.With(typeNamespaceImports: new[] { typeof(Runtime.ObjectExtensions) })); OpenAutoSavedDocuments(); if (HasCachedUpdate()) { HasUpdate = true; } else { Task.Run(CheckForUpdates); } }
public async Task CloseDocument(OpenDocumentViewModel document) { var result = await document.Save(promptSave : true).ConfigureAwait(true); if (result == SaveResult.Cancel) { return; } if (document.Document?.IsAutoSave == true) { File.Delete(document.Document.Path); } RoslynHost.CloseDocument(document.DocumentId); OpenDocuments.Remove(document); document.Close(); }
public RoslynSemanticHighlighter(IDocument document, RoslynHost roslynHost) { if (document == null) { throw new ArgumentNullException(nameof(document)); } _document = document; _roslynHost = roslynHost; if (document is TextDocument) { // Use the cache only for the live AvalonEdit document // Highlighting in read-only documents (e.g. search results) does // not need the cache as it does not need to highlight the same line multiple times _cachedLines = new List <CachedLine>(); } }
private void OnLoaded(object sender, RoutedEventArgs e) { Loaded -= OnLoaded; _host = new RoslynHost(additionalAssemblies: new[] { Assembly.Load("RoslynPad.Roslyn.Windows"), Assembly.Load("RoslynPad.Editor.Windows") }, RoslynHostReferences.NamespaceDefault.With(new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), MetadataReference.CreateFromFile(typeof(System.Text.RegularExpressions.Regex).Assembly.Location), MetadataReference.CreateFromFile(typeof(System.Linq.Enumerable).Assembly.Location), })); AddNewDocument(); }
public MainWindow() { InitializeComponent(); Loaded += OnLoaded; _paragraphStyle = Resources["ParagraphWithNoMarginStyle"] as Style; _documents = new ObservableCollection <DocumentViewModel> { new DocumentViewModel(_host, null) }; _host = new RoslynHost(additionalAssemblies: new[] { Assembly.Load("RoslynPad.Roslyn.Windows"), Assembly.Load("RoslynPad.Editor.Windows") }); }
private void InitializeInternal() { RoslynHost = new RoslynHost(NuGetConfiguration, new[] { // TODO: xplat Assembly.Load("RoslynPad.Roslyn.Windows"), Assembly.Load("RoslynPad.Editor.Windows") }); OpenAutoSavedDocuments(); if (HasCachedUpdate()) { HasUpdate = true; } else { Task.Run(CheckForUpdates); } }
public MainWindow() { InitializeComponent(); host = new RoslynHost(additionalAssemblies: new[] { Assembly.Load("RoslynPad.Roslyn.Windows"), Assembly.Load("RoslynPad.Editor.Windows") }, references: RoslynHostReferences.Default.With(typeNamespaceImports: new[] { typeof(InputDevice) }) ); // 引数にスクリプトがある場合はそれを実行、なければアプリを起動する if (App.CommandLineArgs != null) { Title = App.CommandLineArgs[0]; workingFileName = App.CommandLineArgs[0]; using (StreamReader sr = new System.IO.StreamReader(App.CommandLineArgs[0], System.Text.Encoding.GetEncoding("shift_jis"))) { roslynCodeEditor.Text = sr.ReadToEnd(); } ExecFile(App.CommandLineArgs[0]); Close(); } else { // CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, delegate { SaveCommand(); })); ExecCommand = new DelegateCommand(OnExec, CanExec); SaveAsCommand = new DelegateCommand(OnSaveAs, CanSaveAs); SaveCommand = new DelegateCommand(OnSave, CanSave); NewCommand = new DelegateCommand(OnNew, CanNew); OpenCommand = new DelegateCommand(OnOpen, CanOpen); DataContext = this; //// 初期作業フォルダ //Directory.CreateDirectory(Path.GetDirectoryName(defaultFileName)); //Directory.SetCurrentDirectory(Path.GetDirectoryName(defaultFileName)); } }
public RoslynSemanticHighlighter(IDocument document, DocumentId documentId, RoslynHost roslynHost) { if (document == null) throw new ArgumentNullException(nameof(document)); _document = document; _documentId = documentId; _roslynHost = roslynHost; _semaphore = new SemaphoreSlim(0); _queue = new ConcurrentQueue<HighlightedLine>(); if (document is TextDocument) { // Use the cache only for the live AvalonEdit document // Highlighting in read-only documents (e.g. search results) does // not need the cache as it does not need to highlight the same line multiple times _cachedLines = new List<CachedLine>(); } _syncContext = SynchronizationContext.Current; _cts = new CancellationTokenSource(); var cancellationToken = _cts.Token; Task.Run(() => Worker(cancellationToken), cancellationToken); }
private async void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs args) { _viewModel = (OpenDocumentViewModel)args.NewValue; _viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled; _roslynHost = _viewModel.MainViewModel.RoslynHost; var avalonEditTextContainer = new AvalonEditTextContainer(Editor); await _viewModel.Initialize( avalonEditTextContainer, a => _syncContext.Post(o => ProcessDiagnostics(a), null), text => avalonEditTextContainer.UpdateText(text) ).ConfigureAwait(true); Editor.Document.UndoStack.ClearAll(); Editor.TextArea.TextView.LineTransformers.Insert(0, new RoslynHighlightingColorizer(_viewModel.DocumentId, _roslynHost)); _contextActionsRenderer = new ContextActionsRenderer(Editor, _textMarkerService); _contextActionsRenderer.Providers.Add(new RoslynContextActionProvider(_viewModel.DocumentId, _roslynHost)); Editor.CompletionProvider = new RoslynCodeEditorCompletionProvider(_viewModel.DocumentId, _roslynHost); }
public MainViewModel() { Application.Current.DispatcherUnhandledException += (o, e) => OnUnhandledDispatcherException(e); AppDomain.CurrentDomain.UnhandledException += (o, e) => OnUnhandledException((Exception)e.ExceptionObject, flushSync: true); TaskScheduler.UnobservedTaskException += (o, e) => OnUnhandledException(e.Exception); NuGet = new NuGetViewModel(); NuGetProvider = new NuGetProviderImpl(NuGet.GlobalPackageFolder, NuGetPathVariableName); RoslynHost = new RoslynHost(NuGetProvider); ChildProcessManager = new ChildProcessManager(); NewDocumentCommand = new DelegateCommand((Action)CreateNewDocument); ClearErrorCommand = new DelegateCommand(() => LastError = null); DocumentRoot = CreateDocumentRoot(); Documents = DocumentRoot.Children; OpenDocuments = new ObservableCollection<OpenDocumentViewModel>(LoadAutoSaves(DocumentRoot.Path)); OpenDocuments.CollectionChanged += (sender, args) => OnPropertyChanged(nameof(HasNoOpenDocuments)); if (HasNoOpenDocuments) { CreateNewDocument(); } else { CurrentOpenDocument = OpenDocuments[0]; } if (HasCachedUpdate()) { HasUpdate = true; } else { Task.Run(CheckForUpdates); } }
public RoslynCodeEditorCompletionProvider(RoslynHost roslynHost) { _roslynHost = roslynHost; }
public DocumentViewModel(RoslynHost host, DocumentViewModel previous) { _host = host; Previous = previous; }
public static void InitEditor() { lock (initLocked) { if (isInited) { return; } isInited = true; InitScriptOptions(); RoslynHostReferences roslynHostReferences; if (scriptOptions == null) { roslynHostReferences = RoslynHostReferences.NamespaceDefault.With( assemblyReferences: new[] { Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly(), typeof(MainController).Assembly, typeof(object).Assembly }); } else { roslynHostReferences = RoslynHostReferences.NamespaceDefault.With( references: scriptOptions.MetadataReferences.Where(a => !(a is UnresolvedMetadataReference)), imports: scriptOptions.Imports, assemblyReferences: new[] { Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly(), typeof(MainController).Assembly, typeof(object).Assembly }); } roslynHost = new CustomHost( globalType, additionalAssemblies: new[] { Assembly.Load("RoslynPad.Roslyn.Windows"), Assembly.Load("RoslynPad.Editor.Windows") }, references: roslynHostReferences); if (instance == null) { CreateEditorInstance(); } instance.Invoke((Action)(() => { roslynCodeEditor = new RoslynCodeEditor { FontFamily = new System.Windows.Media.FontFamily("Consolas") }; docId = roslynCodeEditor.Initialize(roslynHost, new ClassificationHighlightColors(), Directory.GetCurrentDirectory(), string.Empty); if (!Directory.Exists("Code")) { Directory.CreateDirectory("Code"); } if (File.Exists("Code\\_last")) { roslynCodeEditor.Text = File.ReadAllText("Code\\_last"); } instance.elementHost1.Child = roslynCodeEditor; foreach (var item in Directory.EnumerateFiles("Code")) { instance.comboBox1.Items.Add(item.Substring(5)); } instance.comboBox1.SelectedIndexChanged += (_, __) => { if (File.Exists($"Code\\{instance.comboBox1.Text}")) { Code = File.ReadAllText($"Code\\{instance.comboBox1.Text}"); } }; //AppDomain.CurrentDomain.AssemblyResolve += (a, b) => //{ // var asms = AppDomain.CurrentDomain.GetAssemblies(); // var fasms = asms.Where(a => a.FullName == b.Name).ToArray(); // if (fasms.Length > 0) return fasms[0]; // else // { // string asmName; // if (b.Name.IndexOf(',') > 0) // asmName = b.Name.Substring(0, b.Name.IndexOf(',')); // else asmName = b.Name; // var dinfo = Directory.CreateDirectory("Plugins"); // foreach (var item in dinfo.EnumerateFiles("*.dll", SearchOption.AllDirectories)) // { // if (item.Name == asmName) // { // return assemblyLoadContext.LoadFromAssemblyPath(item.FullName); // } // } // } // return null; //}; })); } }
/// <summary> /// Initializes a new instance of the <see cref="CodeTextEditorFactory"/> class. /// </summary> /// <param name="host">The roslyn host. If this argument is null, a new instance of <see cref="RoslynHost"/> is created and stored in this instance.</param> public CodeTextEditorFactory(RoslynHost host) { RoslynHost = host ?? new RoslynHost(null); }
public RoslynHighlightingColorizer(DocumentId documentId, RoslynHost roslynHost) { _documentId = documentId; _roslynHost = roslynHost; }
public RoslynHighlightingColorizer(RoslynHost roslynHost) { _roslynHost = roslynHost; }
public RoslynContextActionProvider(DocumentId documentId, RoslynHost roslynHost) { _documentId = documentId; _roslynHost = roslynHost; _codeFixService = _roslynHost.GetService<ICodeFixService>(); }
public RoslynCodeEditorCompletionProvider(DocumentId documentId, RoslynHost roslynHost) { _documentId = documentId; _roslynHost = roslynHost; _snippetService = (SnippetInfoService)_roslynHost.GetService <ISnippetInfoService>(); }
public RoslynCodeEditorCompletionProvider(DocumentId documentId, RoslynHost roslynHost) { _documentId = documentId; _roslynHost = roslynHost; }
public MainViewModel() { NuGet = new NuGetViewModel(); RoslynHost = new RoslynHost(new NuGetProvider(NuGet.GlobalPackageFolder, NuGetPathVariableName)); }
public RoslynContextActionProvider(RoslynHost roslynHost) { _roslynHost = roslynHost; }