public void SetCursor(int index, int line, int column, List <UnsavedFile> unsavedFiles)
        {
            if (!intellisenseControl.IsVisible)
            {
                _requestingData = true;
                intellisenseQueryRunner.InvokeAsync(() =>
                {
                    CodeCompletionResults result = null;
                    intellisenseJobRunner.InvokeAsync(() =>
                    {
                        var task = languageService.CodeCompleteAtAsync(file, index, line, column, unsavedFiles);
                        task.Wait();

                        result = task.Result;
                    }).Wait();

                    Dispatcher.UIThread.InvokeAsync(() =>
                    {
                        SetCompletionData(result);

                        _requestingData = false;

                        UpdateFilter(editor.CaretOffset, false);

                        intellisenseControl.IsVisible = !_hidden;
                    });
                });
            }
        }
Beispiel #2
0
        public async Task <bool> PauseAsync()
        {
            var result = true;

            if (currentState == DebuggerState.Paused)
            {
                result = false;
                return(result);
            }

            EventHandler <StopRecord> onStoppedHandler = (sender, e) =>
            {
                if (e != null)
                {
                    switch (e.Reason)
                    {
                    case StopReason.SignalReceived:
                        break;

                    default:
                        // indicate that the debugger has been interrupted for a reason other than signalling, i.e. stepping range ended.
                        result = false;
                        break;
                    }
                }

                if (waitForStop.CurrentCount == 0)
                {
                    waitForStop.Release();
                }
            };

            InternalStopped += onStoppedHandler;

            if (asyncModeEnabled)
            {
                await new ExecInterruptCommand().Execute(this);

                await waitForStop.WaitAsync();
            }
            else
            {
                await transmitRunner.InvokeAsync(() =>
                {
                    do
                    {
                        Platform.SendSignal(process.Id, Platform.Signum.SIGINT);
                    } while (!waitForStop.Wait(100));
                });
            }

            InternalStopped -= onStoppedHandler;

            return(result);
        }
Beispiel #3
0
        private async Task <bool> DoCodeAnalysisAsync()
        {
            var sourceFile   = SourceFile;
            var unsavedFiles = UnsavedFiles.ToList();

            await _codeAnalysisRunner.InvokeAsync(async() =>
            {
                if (LanguageService != null)
                {
                    // TODO allow interruption.
                    var result = await LanguageService.RunCodeAnalysisAsync(sourceFile, unsavedFiles, () => false);

                    Dispatcher.UIThread.InvokeAsync(() =>
                    {
                        Diagnostics = result.Diagnostics;

                        TextArea.TextView.Redraw();

                        _shell.InvalidateErrors();
                    });
                }
            });

            return(true);
        }
Beispiel #4
0
        private async Task <bool> DoCodeAnalysisAsync()
        {
            var editor       = DocumentAccessor;
            var unsavedFiles = UnsavedFiles.ToList();

            await _codeAnalysisRunner.InvokeAsync(async() =>
            {
                if (LanguageService != null)
                {
                    var result = await LanguageService.RunCodeAnalysisAsync(editor, unsavedFiles, () => false);

                    _textColorizer?.SetTransformations(editor, result.SyntaxHighlightingData);

                    await Dispatcher.UIThread.InvokeAsync(() =>
                    {
                        _scopeLineBackgroundRenderer?.ApplyIndex(result.IndexItems);
                    });

                    Dispatcher.UIThread.Post(() =>
                    {
                        TextArea.TextView.Redraw();
                    });
                }
            });

            return(true);
        }
        private async Task <bool> DoCodeAnalysisAsync()
        {
            var sourceFile   = SourceFile;
            var unsavedFiles = UnsavedFiles.ToList();

            await _codeAnalysisRunner.InvokeAsync(async() =>
            {
                if (LanguageService != null)
                {
                    // TODO allow interruption.
                    var result = await LanguageService.RunCodeAnalysisAsync(sourceFile, unsavedFiles, () => false);

                    _textColorizer?.SetTransformations(result.SyntaxHighlightingData);

                    _diagnosticMarkersRenderer?.SetDiagnostics(result.Diagnostics);

                    _scopeLineBackgroundRenderer?.ApplyIndex(result.IndexItems);

                    Dispatcher.UIThread.InvokeAsync(() =>
                    {
                        Diagnostics = result.Diagnostics;

                        TextArea.TextView.Redraw();

                        _shell.InvalidateErrors();
                    });
                }
            });

            return(true);
        }
        private void Editor_LostFocus(object sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            intellisenseJobRunner.InvokeAsync(() =>
            {
                CloseIntellisense();
            });

            completionAssistant.Close();
        }
        private async Task PushToSignatureHelp(string currentWord, int offset)
        {
            SignatureHelp signatureHelp = null;

            await intellisenseJobRunner.InvokeAsync(() =>
            {
                var task = languageService.SignatureHelp(editor, CodeEditor.UnsavedFiles.ToList(), offset, currentWord);
                task.Wait();

                signatureHelp = task.Result;
            });

            if (signatureHelp != null)
            {
                _onSetSignatureHelpPosition(signatureHelp.Offset);
                completionAssistant.PushMethod(signatureHelp);
            }
        }
Beispiel #8
0
        /// <summary>
        ///     Write lock must be held before calling this.
        /// </summary>
        private async Task TriggerCodeAnalysis()
        {
            await codeAnalysisRunner.InvokeAsync(async() =>
            {
                if (LanguageService != null)
                {
                    // TODO allow interruption.
                    var result = await LanguageService.RunCodeAnalysisAsync(ProjectFile, UnsavedFiles.ToList(), () => false);

                    Dispatcher.UIThread.InvokeAsync(() => { CodeAnalysisResults = result; });
                }
            });
        }
Beispiel #9
0
        private async Task <T> SendPacketTaskAsync <T>(IdpPacket packet, int timeout) where T : Transaction
        {
            T          result = null;
            List <int> x      = new List <int>();

            var command           = commandManager.GetCommand <T>();
            var packetReceivedTcs = new TaskCompletionSource <T>();

            EventHandler <T> commandReceivedHandler = (sender, e) =>
            {
                if (!packetReceivedTcs.Task.IsCompleted)
                {
                    packetReceivedTcs.SetResult(e);
                }
            };

            command.CommandReceived += commandReceivedHandler;

            configurationCommsThread.InvokeAsync(() =>
            {
                packet.Insert(0, (byte)packet.Count);
                packet.Insert(0, 0x01);
                configurationDevice.WriteFeatureData(packet.ToArray());
            });

            if (await Task.WhenAny(packetReceivedTcs.Task, Task.Delay(timeout)) == packetReceivedTcs.Task)
            {
                result = packetReceivedTcs.Task.Result;
            }
            else
            {
                result = null;
            }

            command.CommandReceived -= commandReceivedHandler;

            return(result);
        }
Beispiel #10
0
    public async Task Enqueue_AsyncInstanceMethod_ShouldSucceed()
    {
        var testServiceProvider = new TestServiceProvider();
        var testStore           = new MemoryJobStore();
        var jobManager          = new JobManager(testStore);
        var jobRunner           = new JobRunner(testServiceProvider);

        await jobManager.EnqueueAsync <TestJobs>((t) => t.InstanceJobAsync1(1));

        JobDescriptor?job = await testStore.NextAsync(CancellationToken.None);

        Assert.Equal("InstanceJobAsync1", job !.Call.Method);
        await jobRunner.InvokeAsync(job.Call, CancellationToken.None);
    }
Beispiel #11
0
        private async Task <bool> DoCodeAnalysisAsync()
        {
            var editor       = DocumentAccessor;
            var unsavedFiles = UnsavedFiles.ToList();

            await _codeAnalysisRunner.InvokeAsync(async() =>
            {
                if (LanguageService != null)
                {
                    var result = await LanguageService.RunCodeAnalysisAsync(editor, unsavedFiles, () => false);

                    _textColorizer?.SetTransformations(result.SyntaxHighlightingData);

                    TextSegmentCollection <Diagnostic> diagnostics = null;

                    await Dispatcher.UIThread.InvokeAsync(() =>
                    {
                        _scopeLineBackgroundRenderer?.ApplyIndex(result.IndexItems);
                        diagnostics = new TextSegmentCollection <Diagnostic>(Document);
                    });

                    foreach (var diagnostic in result.Diagnostics)
                    {
                        diagnostics.Add(diagnostic);
                    }

                    _diagnosticMarkersRenderer?.SetDiagnostics(diagnostics);

                    Dispatcher.UIThread.InvokeAsync(() =>
                    {
                        Diagnostics = diagnostics;

                        _shell.InvalidateErrors();

                        TextArea.TextView.Redraw();
                    });
                }
            });

            return(true);
        }
        public async Task <CodeCompletionResults> CodeCompleteAtAsync(ISourceFile file, int index, int line, int column,
                                                                      List <UnsavedFile> unsavedFiles, char lastChar, string filter)
        {
            var clangUnsavedFiles = new List <ClangUnsavedFile>();

            foreach (var unsavedFile in unsavedFiles)
            {
                clangUnsavedFiles.Add(new ClangUnsavedFile(unsavedFile.FileName, unsavedFile.Contents));
            }

            var result = new CodeCompletionResults();

            await clangAccessJobRunner.InvokeAsync(() =>
            {
                var translationUnit = GetAndParseTranslationUnit(file, clangUnsavedFiles);

                if (translationUnit != null)
                {
                    var completionResults = translationUnit.CodeCompleteAt(file.Location, line, column, clangUnsavedFiles.ToArray(),
                                                                           CodeCompleteFlags.IncludeBriefComments | CodeCompleteFlags.IncludeMacros | CodeCompleteFlags.IncludeCodePatterns);
                    completionResults.Sort();

                    result.Contexts = (CompletionContext)completionResults.Contexts;

                    if (result.Contexts == CompletionContext.Unexposed && lastChar == ':')
                    {
                        result.Contexts = CompletionContext.AnyType; // special case Class::<- here static class member access.
                    }

                    foreach (var codeCompletion in completionResults.Results)
                    {
                        var typedText = string.Empty;

                        var hint = string.Empty;

                        if (codeCompletion.CompletionString.Availability == AvailabilityKind.Available || codeCompletion.CompletionString.Availability == AvailabilityKind.Deprecated)
                        {
                            foreach (var chunk in codeCompletion.CompletionString.Chunks)
                            {
                                if (chunk.Kind == CompletionChunkKind.TypedText)
                                {
                                    typedText = chunk.Text;
                                }

                                hint += chunk.Text;

                                switch (chunk.Kind)
                                {
                                case CompletionChunkKind.LeftParen:
                                case CompletionChunkKind.LeftAngle:
                                case CompletionChunkKind.LeftBrace:
                                case CompletionChunkKind.LeftBracket:
                                case CompletionChunkKind.RightAngle:
                                case CompletionChunkKind.RightBrace:
                                case CompletionChunkKind.RightBracket:
                                case CompletionChunkKind.RightParen:
                                case CompletionChunkKind.Placeholder:
                                case CompletionChunkKind.Comma:
                                    break;

                                default:
                                    hint += " ";
                                    break;
                                }
                            }

                            if (filter == string.Empty || typedText.StartsWith(filter))
                            {
                                var completion = new CodeCompletionData
                                {
                                    Suggestion   = typedText,
                                    Priority     = codeCompletion.CompletionString.Priority,
                                    Kind         = FromClangKind(codeCompletion.CursorKind),
                                    Hint         = hint,
                                    BriefComment = codeCompletion.CompletionString.BriefComment
                                };

                                result.Completions.Add(completion);

                                if (completion.Kind == CodeCompletionKind.OverloadCandidate)
                                {
                                    Console.WriteLine("TODO Implement overload candidate.");
                                }
                            }
                        }
                    }

                    completionResults.Dispose();
                }
            });

            return(result);
        }
Beispiel #13
0
        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.IntellisenseManager = new CSharpIntellisenseManager(this, intellisenseControl, 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 == 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;
                    }
                }
            };

            association.TextInputHandler = (sender, e) =>
            {
            };

            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.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 async Task <List <CodeCompletionData> > CodeCompleteAtAsync(ISourceFile file, int line, int column,
                                                                           List <UnsavedFile> unsavedFiles, string filter)
        {
            var clangUnsavedFiles = new List <ClangUnsavedFile>();

            foreach (var unsavedFile in unsavedFiles)
            {
                clangUnsavedFiles.Add(new ClangUnsavedFile(unsavedFile.FileName, unsavedFile.Contents));
            }

            var result = new List <CodeCompletionData>();

            await clangAccessJobRunner.InvokeAsync(() =>
            {
                var translationUnit = GetAndParseTranslationUnit(file, clangUnsavedFiles);

                var completionResults = translationUnit.CodeCompleteAt(file.Location, line, column, clangUnsavedFiles.ToArray(),
                                                                       CodeCompleteFlags.IncludeBriefComments | CodeCompleteFlags.IncludeMacros | CodeCompleteFlags.IncludeCodePatterns);
                completionResults.Sort();

                foreach (var codeCompletion in completionResults.Results)
                {
                    var typedText = string.Empty;

                    var hint = string.Empty;

                    foreach (var chunk in codeCompletion.CompletionString.Chunks)
                    {
                        if (chunk.Kind == CompletionChunkKind.TypedText)
                        {
                            typedText = chunk.Text;
                        }

                        hint += chunk.Text;

                        switch (chunk.Kind)
                        {
                        case CompletionChunkKind.LeftParen:
                        case CompletionChunkKind.LeftAngle:
                        case CompletionChunkKind.LeftBrace:
                        case CompletionChunkKind.LeftBracket:
                        case CompletionChunkKind.RightAngle:
                        case CompletionChunkKind.RightBrace:
                        case CompletionChunkKind.RightBracket:
                        case CompletionChunkKind.RightParen:
                        case CompletionChunkKind.Placeholder:
                        case CompletionChunkKind.Comma:
                            break;

                        default:
                            hint += " ";
                            break;
                        }
                    }

                    if (filter == string.Empty || typedText.StartsWith(filter))
                    {
                        result.Add(new CodeCompletionData
                        {
                            Suggestion   = typedText,
                            Priority     = codeCompletion.CompletionString.Priority,
                            Kind         = FromClangKind(codeCompletion.CursorKind),
                            Hint         = hint,
                            BriefComment = codeCompletion.CompletionString.BriefComment
                        });
                    }
                }

                completionResults.Dispose();
            });

            return(result);
        }
        public void SetCursor(int index, int line, int column, List <UnsavedFile> unsavedFiles, bool canUpdateSignature = true)
        {
            if (_lastIndex != index)
            {
                _lastIndex = index;

                if (canUpdateSignature)
                {
                    UpdateActiveParameterAndVisibility();
                }

                if (!intellisenseControl.IsVisible)
                {
                    unfilteredCompletions.Clear();

                    if (_shell.DebugMode)
                    {
                        _console.WriteLine("Set Cursor");
                    }

                    _requestingData = true;

                    char previousChar = '\0';

                    if (index >= 1)
                    {
                        previousChar = editor.Document.GetCharAt(index - 1);
                    }

                    intellisenseQueryRunner.InvokeAsync(() =>
                    {
                        CodeCompletionResults result = null;
                        intellisenseJobRunner.InvokeAsync(() =>
                        {
                            if (_shell.DebugMode)
                            {
                                _console.WriteLine($"Query Language Service {index}, {line}, {column}");
                            }

                            var task = languageService.CodeCompleteAtAsync(editor, index, line, column, unsavedFiles, previousChar);
                            task.Wait();

                            result = task.Result;
                        }).Wait();

                        if (result != null)
                        {
                            Dispatcher.UIThread.InvokeAsync(() =>
                            {
                                if (_shell.DebugMode)
                                {
                                    _console.WriteLine($"Set Completion Data {_hidden}");
                                }

                                SetCompletionData(result);

                                _requestingData = false;

                                if (unfilteredCompletions.Count > 0)
                                {
                                    UpdateFilter(editor.CaretOffset, false);
                                    intellisenseControl.IsVisible = !_hidden;
                                }
                                else
                                {
                                    _hidden = true;
                                }
                            });
                        }
                    });
                }
                else
                {
                    UpdateFilter(editor.CaretOffset, false);
                }
            }
        }