11import * as vscode from "vscode" ;
22import { config } from "../extension" ;
33import { currentFile } from "../utils" ;
4+ import { AtelierAPI } from "../api" ;
45
56export class ObjectScriptCodeLensProvider implements vscode . CodeLensProvider {
67 public provideCodeLenses (
78 document : vscode . TextDocument ,
89 token : vscode . CancellationToken
910 ) : vscode . ProviderResult < vscode . CodeLens [ ] > {
1011 if ( document . languageId == "objectscript-class" ) {
11- return this . classMethods ( document ) ;
12+ return this . classMembers ( document ) ;
1213 }
1314 if ( [ "objectscript" , "objectscript-int" ] . includes ( document . languageId ) ) {
1415 return this . routineLabels ( document ) ;
1516 }
1617 return [ ] ;
1718 }
1819
19- private classMethods ( document : vscode . TextDocument ) : vscode . CodeLens [ ] {
20+ private classMembers ( document : vscode . TextDocument ) : vscode . CodeLens [ ] {
2021 const file = currentFile ( document ) ;
2122 const result = new Array < vscode . CodeLens > ( ) ;
22-
23- const className = file . name . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
24-
23+ const className = file . name . slice ( 0 , - 4 ) ;
2524 const { debugThisMethod, copyToClipboard } = config ( "debug" ) ;
26- if ( ! debugThisMethod && ! copyToClipboard ) {
27- // Return early if both types are turned off
28- return result ;
29- }
25+ const methodPattern = / (?: ^ ( C l a s s M e t h o d | Q u e r y ) \s ) ( [ ^ ( ] + ) \( ( .* ) / i;
26+ const xdataPattern = / ^ X D a t a \s ( [ ^ [ { \s ] + ) / i;
27+ const superPattern = new RegExp (
28+ `^\\s*Class\\s+${ className . replace ( / \. / g, "\\." ) } \\s+Extends\\s+(?:(?:\\(([^)]+)\\))|(?:([^\\s]+)))` ,
29+ "i"
30+ ) ;
31+ const api = new AtelierAPI ( document . uri ) ;
3032
31- const pattern = / (?: ^ ( C l a s s M e t h o d | Q u e r y ) \s ) ( [ ^ ( ] + ) \( ( . * ) / i ;
33+ let superclasses : string [ ] = [ ] ;
3234 let inComment = false ;
3335 for ( let i = 0 ; i < document . lineCount ; i ++ ) {
3436 const line = document . lineAt ( i ) ;
@@ -45,8 +47,51 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
4547 continue ;
4648 }
4749
48- const methodMatch = text . match ( pattern ) ;
49- if ( methodMatch ) {
50+ const methodMatch = text . match ( methodPattern ) ;
51+ const xdataMatch = text . match ( xdataPattern ) ;
52+ const superMatch = text . match ( superPattern ) ;
53+ if ( superMatch ) {
54+ const [ , superclassesList , superclass ] = superMatch ;
55+ if ( superclass ) {
56+ superclasses = [ superclass ] ;
57+ } else {
58+ superclasses = superclassesList . replace ( / \s + / g, "" ) . split ( "," ) ;
59+ }
60+ } else if ( xdataMatch && api . active ) {
61+ let [ , xdataName ] = xdataMatch ;
62+ xdataName = xdataName . trim ( ) ;
63+ let cmd : vscode . Command = undefined ;
64+ if (
65+ ( xdataName == "BPL" && superclasses . includes ( "Ens.BusinessProcessBPL" ) ) ||
66+ ( xdataName == "DTL" && superclasses . includes ( "Ens.DataTransformDTL" ) )
67+ ) {
68+ cmd = {
69+ title : "Open Graphical Editor" ,
70+ command : "vscode-objectscript.openPathInBrowser" ,
71+ tooltip : "Open graphical editor in an external browser" ,
72+ arguments : [
73+ `/csp/${ api . config . ns . toLowerCase ( ) } /EnsPortal.${
74+ xdataName == "BPL" ? `BPLEditor.zen?BP=${ className } .BPL` : `DTLEditor.zen?DT=${ className } .DTL`
75+ } `,
76+ document . uri ,
77+ ] ,
78+ } ;
79+ } else if ( xdataName == "RuleDefinition" && superclasses . includes ( "Ens.Rule.Definition" ) ) {
80+ cmd = {
81+ title : "Reopen in Graphical Editor" ,
82+ command : "workbench.action.toggleEditorType" ,
83+ tooltip : "Replace text editor with graphical editor" ,
84+ } ;
85+ } else if ( xdataName == "KPI" && superclasses . includes ( "%DeepSee.KPI" ) ) {
86+ cmd = {
87+ title : "Test KPI" ,
88+ command : "vscode-objectscript.openPathInBrowser" ,
89+ tooltip : "Open testing page in an external browser" ,
90+ arguments : [ `/csp/${ api . config . ns . toLowerCase ( ) } /${ className } .cls` , document . uri ] ,
91+ } ;
92+ }
93+ if ( cmd ) result . push ( new vscode . CodeLens ( new vscode . Range ( i , 0 , i , 80 ) , cmd ) ) ;
94+ } else if ( methodMatch && ( debugThisMethod || copyToClipboard ) ) {
5095 const [ , kind , name , paramsRaw ] = methodMatch ;
5196 let params = paramsRaw ;
5297 params = params . replace ( / " [ ^ " ] * " / g, '""' ) ;
0 commit comments