File tree Expand file tree Collapse file tree
extensions/ql-vscode/src/model-editor/languages/ruby Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { parseAccessPathTokens } from "../../shared/access-paths" ;
2+
3+ const methodTokenRegex = / ^ M e t h o d \[ ( .+ ) ] $ / ;
4+
15export function parseRubyMethodFromPath ( path : string ) : string {
2- const match = path . match ( / M e t h o d \[ ( [ ^ \] ] + ) ] .* / ) ;
6+ const tokens = parseAccessPathTokens ( path ) ;
7+
8+ if ( tokens . length === 0 ) {
9+ return "" ;
10+ }
11+
12+ const match = tokens [ 0 ] . text . match ( methodTokenRegex ) ;
313 if ( match ) {
414 return match [ 1 ] ;
515 } else {
@@ -11,9 +21,22 @@ export function parseRubyAccessPath(path: string): {
1121 methodName : string ;
1222 path : string ;
1323} {
14- const match = path . match ( / M e t h o d \[ ( [ ^ \] ] + ) ] \. ( .* ) / ) ;
24+ const tokens = parseAccessPathTokens ( path ) ;
25+
26+ if ( tokens . length === 0 ) {
27+ return { methodName : "" , path : "" } ;
28+ }
29+
30+ const match = tokens [ 0 ] . text . match ( methodTokenRegex ) ;
31+
1532 if ( match ) {
16- return { methodName : match [ 1 ] , path : match [ 2 ] } ;
33+ return {
34+ methodName : match [ 1 ] ,
35+ path : tokens
36+ . slice ( 1 )
37+ . map ( ( token ) => token . text )
38+ . join ( "." ) ,
39+ } ;
1740 } else {
1841 return { methodName : "" , path : "" } ;
1942 }
You can’t perform that action at this time.
0 commit comments