← Back to Pull requests

Fix 'a-f' (a-function) commands in JS when using using tree-sitter #1134

Merged
jonboiser merged 2 files (55 lines) on Jan 01, 2020 00:52 UTC
View on GitHub
jonboiser jonboiser commented on Dec 30, 2019 20:31 UTC
Author

This fixes the broken 'a-f' commands when editing JS/TS/JS+flow files when Tree-Sitter parsers are enabled. I think this is because of some changes to the tree-sitter parsers. Here is some output from the tree-sitter playground.

The main thing is that function_declaration is used for function foo() {} and function is used for anonymous functions. They have even added support for arrow functions, although the a-f selection range isn't perfect when the functions are formatted in weird ways. I added tests for very simple examples, and hopefully the more complicated ones can be addressed later.

Thanks and あけましておめでとう!

Input

function foo() {
	return '';
}

const foo = () => {
	return '';
}

const foo = function() {
	return '';
}

const methods = {
	foo() {
		return '';
	}
}

Output

program [0, 0] - [11, 0])
	
Named Function
  function_declaration [0, 0] - [2, 1])
    name: identifier [0, 9] - [0, 12])
    parameters: formal_parameters [0, 12] - [0, 14])
    body: statement_block [0, 15] - [2, 1])
      return_statement [1, 1] - [1, 11])
        string [1, 8] - [1, 10])

Arrow function
  lexical_declaration [4, 0] - [6, 1])
    variable_declarator [4, 6] - [6, 1])
      name: identifier [4, 6] - [4, 9])
      value: arrow_function [4, 12] - [6, 1])
        parameters: formal_parameters [4, 12] - [4, 14])
        body: statement_block [4, 18] - [6, 1])
          return_statement [5, 1] - [5, 11])
            string [5, 8] - [5, 10])

Anonymous function
  lexical_declaration [8, 0] - [10, 1])
    variable_declarator [8, 6] - [10, 1])
      name: identifier [8, 6] - [8, 9])
      value: function [8, 12] - [10, 1])
        parameters: formal_parameters [8, 20] - [8, 22])
        body: statement_block [8, 23] - [10, 1])
          return_statement [9, 1] - [9, 11])
            string [9, 8] - [9, 10])

Method
  lexical_declaration [12, 0] - [16, 1])
    variable_declarator [12, 6] - [16, 1])
      name: identifier [12, 6] - [12, 13])
      value: object [12, 16] - [16, 1])
        method_definition [13, 0] - [15, 1])
          name: property_identifier [13, 0] - [13, 3])
          parameters: formal_parameters [13, 3] - [13, 5])
          body: statement_block [13, 6] - [15, 1])
            return_statement [14, 0] - [14, 10])
              string [14, 7] - [14, 9])

Diff: 55 lines (+50 / -5) across 2 files Reviewer: t9md Review duration: 1700m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.29) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.29 · 55 lines diff across 2 files
0.29
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
42%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.241
Real PR Conversation Timeline
1 comments
"Review active on #1134"
general weight: 0.35
Reviewers
Assignees
jonboiser jonboiser
Labels
risk: low confidence: 43.0% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 28.5% (LOW) · Higher = larger blast radius
28.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 43.0% · Lower = rushed or shallow review
43.0%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.3% · Safe to merge
16.3%