1
1
import * as vscode from "vscode" ;
2
2
import { config } from "../extension" ;
3
3
import { currentFile } from "../utils" ;
4
+ import { AtelierAPI } from "../api" ;
4
5
5
6
export class ObjectScriptCodeLensProvider implements vscode . CodeLensProvider {
6
7
public provideCodeLenses (
7
8
document : vscode . TextDocument ,
8
9
token : vscode . CancellationToken
9
10
) : vscode . ProviderResult < vscode . CodeLens [ ] > {
10
11
if ( document . languageId == "objectscript-class" ) {
11
- return this . classMethods ( document ) ;
12
+ return this . classMembers ( document ) ;
12
13
}
13
14
if ( [ "objectscript" , "objectscript-int" ] . includes ( document . languageId ) ) {
14
15
return this . routineLabels ( document ) ;
15
16
}
16
17
return [ ] ;
17
18
}
18
19
19
- private classMethods ( document : vscode . TextDocument ) : vscode . CodeLens [ ] {
20
+ private classMembers ( document : vscode . TextDocument ) : vscode . CodeLens [ ] {
20
21
const file = currentFile ( document ) ;
21
22
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 ) ;
25
24
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 ) ;
30
32
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 [ ] = [ ] ;
32
34
let inComment = false ;
33
35
for ( let i = 0 ; i < document . lineCount ; i ++ ) {
34
36
const line = document . lineAt ( i ) ;
@@ -45,8 +47,51 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
45
47
continue ;
46
48
}
47
49
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 ) ) {
50
95
const [ , kind , name , paramsRaw ] = methodMatch ;
51
96
let params = paramsRaw ;
52
97
params = params . replace ( / " [ ^ " ] * " / g, '""' ) ;
0 commit comments