Skip to content

Commit

Permalink
Add function and class name scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
brxck committed Jul 6, 2021
1 parent 9c3b2f1 commit 3a79d5d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type ScopeType =
| "argumentOrParameter"
| "arrowFunction"
| "class"
| "className"
| "comment"
| "dictionary"
| "functionCall"
Expand Down
1 change: 1 addition & 0 deletions src/languages/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const nodeMatchers: Record<ScopeType, NodeMatcher> = {
...getPojoMatchers(["object"], ["array"], isValue),
ifStatement: notSupported,
class: notSupported,
className: notSupported,
statement: notSupported,
arrowFunction: notSupported,
functionCall: notSupported,
Expand Down
10 changes: 9 additions & 1 deletion src/languages/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SyntaxNode } from "web-tree-sitter";
import { getPojoMatchers } from "./getPojoMatchers";
import {
cascadingMatcher,
composedMatcher,
matcher,
notSupported,
typeMatcher,
Expand Down Expand Up @@ -149,7 +150,14 @@ const nodeMatchers: Record<ScopeType, NodeMatcher> = {
matcher(getNameNode),
matcher((node) => (node.type === "assignment" ? getLeftNode(node) : null))
),
functionName: notSupported,
functionName: composedMatcher([
possiblyDecoratedDefinition("function_definition"),
getNameNode,
]),
className: composedMatcher([
possiblyDecoratedDefinition("class_definition"),
getNameNode,
]),
arrowFunction: typeMatcher("lambda"),
functionCall: typeMatcher("call"),
argumentOrParameter: matcher(
Expand Down
4 changes: 4 additions & 0 deletions src/languages/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ const nodeMatchers: Record<ScopeType, NodeMatcher> = {
composedMatcher([findClassPropertyArrowFunction, getNameNode]),
composedMatcher([findNamedArrowFunction, getNameNode])
),
className: composedMatcher([
possiblyExportedDeclaration("class_declaration", "class"),
getNameNode,
]),
type: cascadingMatcher(
// Typed parameters, properties, and functions
matcher(findTypeNode, selectWithLeadingDelimiter),
Expand Down

0 comments on commit 3a79d5d

Please sign in to comment.