public async void RegisterLanguageService(IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant) { UnRegisterLanguageService(); LanguageService = shell.LanguageServices.FirstOrDefault(o => o.CanHandle(ProjectFile)); if (LanguageService != null) { ShellViewModel.Instance.StatusBar.Language = LanguageService.Title; LanguageService.RegisterSourceFile(intellisenseControl, completionAssistant, Editor, ProjectFile, TextDocument); } else { LanguageService = null; ShellViewModel.Instance.StatusBar.Language = "Text"; } IsDirty = false; StartBackgroundWorkers(); TextDocument.TextChanged += TextDocument_TextChanged; OnBeforeTextChanged(null); await TriggerCodeAnalysis(); }
public IntellisenseManager(IEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file, Action <int> onSetSignatureHelpPosition) { intellisenseJobRunner = new JobRunner(); intellisenseQueryRunner = new JobRunner(1); _cancelRunners = new CancellationTokenSource(); _onSetSignatureHelpPosition = onSetSignatureHelpPosition; Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(_cancelRunners.Token); }); Task.Factory.StartNew(() => { intellisenseQueryRunner.RunLoop(_cancelRunners.Token); }); this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.languageService = languageService; this.file = file; this.editor = editor; this.editor.LostFocus += Editor_LostFocus; _hidden = true; _shell = IoC.Get <IShell>(); _console = IoC.Get <IConsole>(); var snippetManager = IoC.Get <SnippetManager>(); _snippets = snippetManager.GetSnippets(languageService, file.Project?.Solution, file.Project); }
public CSharpIntellisenseManager(ILanguageService languageService, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ISourceFile file, TextEditor.TextEditor editor) { this.languageService = languageService; this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.file = file; this.editor = editor; }
public IntellisenseManager(TextEditor.TextEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file) { intellisenseJobRunner = new JobRunner(); Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(new CancellationToken()); }); this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.languageService = languageService; this.file = file; this.editor = editor; this.editor.LostFocus += Editor_LostFocus; }
public void RegisterSourceFile(IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, TextEditor editor, ISourceFile file, TextDocument textDocument) { CSharpDataAssociation association = null; if (dataAssociations.TryGetValue(file, out association)) { throw new Exception("Source file already registered with language service."); } association = new CSharpDataAssociation(textDocument); association.Solution = file.Project.Solution as OmniSharpSolution; // CanHandle has checked this. dataAssociations.Add(file, association); association.KeyUpHandler = (sender, e) => { if (editor.TextDocument == textDocument) { switch (e.Key) { case Key.Return: { if (editor.CaretIndex >= 0 && editor.CaretIndex < editor.TextDocument.TextLength) { if (editor.TextDocument.GetCharAt(editor.CaretIndex) == '}') { editor.TextDocument.Insert(editor.CaretIndex, Environment.NewLine); editor.CaretIndex--; var currentLine = editor.TextDocument.GetLineByOffset(editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine, editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine.NextLine.NextLine, editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine.NextLine, editor.CaretIndex); } var newCaret = IndentationStrategy.IndentLine(editor.TextDocument, editor.TextDocument.GetLineByOffset(editor.CaretIndex), editor.CaretIndex); editor.CaretIndex = newCaret; } } break; } } }; editor.AddHandler(InputElement.KeyUpEvent, association.KeyUpHandler, RoutingStrategies.Tunnel); }
public void RegisterSourceFile(IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, TextEditor.TextEditor editor, ISourceFile file, TextDocument textDocument) { _tsContext = _tsContext ?? ((TypeScriptProject)file.Project).TypeScriptContext; _tsContext.OpenFile(file.FilePath, File.ReadAllText(file.FilePath)); TypeScriptDataAssociation association = null; if (dataAssociations.TryGetValue(file, out association)) { throw new InvalidOperationException("Source file already registered with language service."); } association = new TypeScriptDataAssociation(textDocument); dataAssociations.Add(file, association); }
public void OpenFile(ISourceFile file, IIntellisenseControl intellisense, ICompletionAssistant completionAssistant) { if (ProjectFile != file) { if (System.IO.File.Exists(file.Location)) { using (var fs = System.IO.File.OpenText(file.Location)) { TextDocument = new TextDocument(fs.ReadToEnd()); TextDocument.FileName = file.Location; } ProjectFile = file; RegisterLanguageService(intellisense, completionAssistant); DocumentLoaded?.Invoke(this, new EventArgs()); } } }
public IntellisenseManager(AvaloniaEdit.TextEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file) { intellisenseJobRunner = new JobRunner(); intellisenseQueryRunner = new JobRunner(1); Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(new CancellationToken()); }); Task.Factory.StartNew(() => { intellisenseQueryRunner.RunLoop(new CancellationToken()); }); this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.languageService = languageService; this.file = file; this.editor = editor; this.editor.LostFocus += Editor_LostFocus; _hidden = true; _shell = IoC.Get <IShell>(); _console = IoC.Get <IConsole>(); var snippetManager = IoC.Get <SnippetManager>(); _snippets = snippetManager.GetSnippets(languageService, file.Project?.Solution, file.Project); }
public void RegisterSourceFile(IIntellisenseControl intellisense, ICompletionAssistant completionAssistant, TextEditor.TextEditor editor, ISourceFile file, TextDocument doc) { CPlusPlusDataAssociation association = null; if (dataAssociations.TryGetValue(file, out association)) { throw new Exception("Source file already registered with language service."); } association = new CPlusPlusDataAssociation(doc); dataAssociations.Add(file, association); association.IntellisenseManager = new CPlusPlusIntellisenseManager(this, intellisense, completionAssistant, file, editor); association.TunneledKeyUpHandler = async(sender, e) => { await intellisenseJobRunner.InvokeAsync(() => { association.IntellisenseManager.OnKeyUp(e).Wait(); }); }; association.TunneledKeyDownHandler = async(sender, e) => { association.IntellisenseManager.OnKeyDown(e); await intellisenseJobRunner.InvokeAsync(() => { association.IntellisenseManager.CompleteOnKeyDown(e).Wait(); }); }; association.KeyUpHandler = (sender, e) => { if (editor.TextDocument == doc) { switch (e.Key) { case Key.Return: { if (editor.CaretIndex >= 0 && editor.CaretIndex < editor.TextDocument.TextLength) { if (editor.TextDocument.GetCharAt(editor.CaretIndex) == '}') { editor.TextDocument.Insert(editor.CaretIndex, Environment.NewLine); editor.CaretIndex--; var currentLine = editor.TextDocument.GetLineByOffset(editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine, editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine.NextLine.NextLine, editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine.NextLine, editor.CaretIndex); } var newCaret = IndentationStrategy.IndentLine(editor.TextDocument, editor.TextDocument.GetLineByOffset(editor.CaretIndex), editor.CaretIndex); editor.CaretIndex = newCaret; } } break; } } }; association.TextInputHandler = (sender, e) => { if (editor.TextDocument == doc) { OpenBracket(editor, editor.TextDocument, e.Text); CloseBracket(editor, editor.TextDocument, e.Text); switch (e.Text) { case "}": case ";": editor.CaretIndex = Format(editor.TextDocument, 0, (uint)editor.TextDocument.TextLength, editor.CaretIndex); break; case "{": var lineCount = editor.TextDocument.LineCount; var offset = Format(editor.TextDocument, 0, (uint)editor.TextDocument.TextLength, editor.CaretIndex); // suggests clang format didnt do anything, so we can assume not moving to new line. if (lineCount != editor.TextDocument.LineCount) { if (offset <= editor.TextDocument.TextLength) { var newLine = editor.TextDocument.GetLineByOffset(offset); editor.CaretIndex = newLine.PreviousLine.EndOffset; } } else { editor.CaretIndex = offset; } break; } } }; editor.AddHandler(InputElement.KeyDownEvent, association.TunneledKeyDownHandler, RoutingStrategies.Tunnel); editor.AddHandler(InputElement.KeyUpEvent, association.TunneledKeyUpHandler, RoutingStrategies.Tunnel); editor.AddHandler(InputElement.KeyUpEvent, association.KeyUpHandler, RoutingStrategies.Tunnel); editor.TextInput += association.TextInputHandler; }
public void RegisterSourceFile(IIntellisenseControl intellisense, ICompletionAssistant completionAssistant, TextEditor.TextEditor editor, ISourceFile file, TextDocument doc) { CPlusPlusDataAssociation association = null; if (dataAssociations.TryGetValue(file, out association)) { throw new Exception("Source file already registered with language service."); } association = new CPlusPlusDataAssociation(doc); dataAssociations.Add(file, association); association.KeyUpHandler = (sender, e) => { if (editor.TextDocument == doc) { switch (e.Key) { case Key.Return: { if (editor.CaretIndex >= 0 && editor.CaretIndex < editor.TextDocument.TextLength) { if (editor.TextDocument.GetCharAt(editor.CaretIndex) == '}') { editor.TextDocument.Insert(editor.CaretIndex, Environment.NewLine); editor.CaretIndex--; var currentLine = editor.TextDocument.GetLineByOffset(editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine, editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine.NextLine.NextLine, editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine.NextLine, editor.CaretIndex); } var newCaret = IndentationStrategy.IndentLine(editor.TextDocument, editor.TextDocument.GetLineByOffset(editor.CaretIndex), editor.CaretIndex); editor.CaretIndex = newCaret; } } break; } } }; association.TextInputHandler = (sender, e) => { if (editor.TextDocument == doc) { OpenBracket(editor, editor.TextDocument, e.Text); CloseBracket(editor, editor.TextDocument, e.Text); switch (e.Text) { case "}": case ";": editor.CaretIndex = Format(editor.TextDocument, 0, (uint)editor.TextDocument.TextLength, editor.CaretIndex); break; case "{": var lineCount = editor.TextDocument.LineCount; var offset = Format(editor.TextDocument, 0, (uint)editor.TextDocument.TextLength, editor.CaretIndex); // suggests clang format didnt do anything, so we can assume not moving to new line. if (lineCount != editor.TextDocument.LineCount) { if (offset <= editor.TextDocument.TextLength) { var newLine = editor.TextDocument.GetLineByOffset(offset); editor.CaretIndex = newLine.PreviousLine.EndOffset; } } else { editor.CaretIndex = offset; } break; } } }; editor.AddHandler(InputElement.KeyUpEvent, association.KeyUpHandler, RoutingStrategies.Tunnel); editor.TextInput += association.TextInputHandler; }
public void RegisterLanguageService(IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant) { UnRegisterLanguageService(); LanguageService = shell.LanguageServices.FirstOrDefault(o => o.CanHandle(ProjectFile)); if (LanguageService != null) { ShellViewModel.Instance.StatusBar.Language = LanguageService.Title; LanguageService.RegisterSourceFile(intellisenseControl, completionAssistant, Editor, ProjectFile, TextDocument); } else { LanguageService = null; ShellViewModel.Instance.StatusBar.Language = "Text"; } IsDirty = false; StartBackgroundWorkers(); TextDocument.TextChanged += TextDocument_TextChanged; OnBeforeTextChanged(null); DoCodeAnalysisAsync().GetAwaiter(); }