private static string GetCompletionTextToEvaluate(ICompletionsCommand cmd) { var idx = cmd.Column - 1; var text = idx <= cmd.Text.Length ? cmd.Text.Substring(0, idx) : cmd.Text; return(text.TrimEnd('.')); }
/// <inheritdoc/> public void Completions(ICompletionsCommand cmd) { if (!cmd.FrameId.HasValue) { SendErrorEvaluationInGlobalScopeNotSupported(cmd); return; } var frameRef = m_scopeHandles.Get(cmd.FrameId.Value, null); var ans = m_expressionEvaluator.EvaluateExpression(frameRef, GetCompletionTextToEvaluate(cmd)); List <ICompletionItem> items; if (!ans.Succeeded) { items = new List <ICompletionItem>(0); } else { var resultAsObjLiteral = ans.Result.Object as ObjectLiteral; var memberProps = resultAsObjLiteral != null?Renderer.ObjectLiteralInfo(ans.Result.Context, resultAsObjLiteral).Properties : Property.Empty; var ambientProps = m_renderer.GetAmbientProperties(ans.Result.Context, ans.Result.Object); items = memberProps.Concat(ambientProps).Select(p => (ICompletionItem) new CompletionItem(p.Name, p.Name, p.Kind)).ToList(); } cmd.SendResult(new CompletionsResult(items)); }
/// <inheritdoc/> public void Completions(ICompletionsCommand cmd) { if (!cmd.FrameId.HasValue) { SendErrorEvaluationInGlobalScopeNotSupported(cmd); return; } var frameRef = m_scopeHandles.Get(cmd.FrameId.Value, null); var textToEval = ExtractCompletionRequestPrefixText(cmd); var lastIdx = new[] { '.', '[', '(' }.Max(c => textToEval.LastIndexOf(c)); var text = lastIdx > -1 ? textToEval.Substring(0, length: lastIdx) : textToEval; var ans = ExpressionEvaluator.EvaluateExpression( State.GetThreadState(frameRef.ThreadId), frameRef.FrameIndex, text, evaluateForCompletions: true); List <ICompletionItem> items; if (!ans.Succeeded) { items = new List <ICompletionItem>(0); } else { items = Renderer .GetObjectInfo(ans.Result.Context, ans.Result.Object) .Properties .Select(p => (ICompletionItem) new CompletionItem(p.Name, p.Name, p.Kind)) .ToList(); } cmd.SendResult(new CompletionsResult(items)); }
private static string ExtractCompletionRequestPrefixText(ICompletionsCommand cmd) { var idx = cmd.Column - 1; return(idx <= cmd.Text.Length ? cmd.Text.Substring(0, idx) : cmd.Text); }