@@ -73,23 +73,49 @@ const activate = context => {
73
73
const fileBody = openedDoc . getText ( )
74
74
const isClass = / \. c l s $ / i. test ( fileName )
75
75
const content = fileBody . split ( / \r ? \n / g )
76
+ const matchingFileName = ( fileName . match ( / [ ^ \\ \/ ] + $ / ) || [ ] ) [ 0 ] || ''
77
+ const matchingName = matchingFileName . replace ( / \. [ ^ . ] + $ / , '' )
76
78
77
79
if ( isClass ) {
80
+
78
81
// Caché class files can be placed hierarchically (e.g. /src/Package/Class.cls),
79
82
// so we pick the class name from the class definition itself
80
- cacheDocName = ( fileBody . replace ( / \/ \/ [ ^ \r \n ] * \r ? \n / g, '' ) . match ( / C l a s s ( [ ^ \s ] + ) / i ) || [ ] ) [ 1 ] || ""
83
+ cacheDocName = ( fileBody . replace ( / \/ \/ [ ^ \r \n ] * \r ? \n / g, '' ) . match ( / C l a s s ( [ ^ \s ] + ) / i ) || [ ] ) [ 1 ] || ''
81
84
const nameParts = cacheDocName . split ( / \. / g ) . filter ( s => ! ! s )
82
85
if ( nameParts . length < 2 )
83
86
return log ( `Unable to detect class name in source code of ${ fileName } .\n`
84
87
+ `Is it a valid Caché ObjectScript class?` )
85
- const matchingFileName = ( fileName . match ( / [ ^ \\ \/ ] + $ / ) || [ ] ) [ 0 ]
86
- if ( ( cacheDocName . toLowerCase ( ) + '.cls' ) . indexOf ( matchingFileName . toLowerCase ( ) ) === - 1 )
87
- return log ( `You tried to compile class named "${ cacheDocName } " in file "${ matchingFileName } ".\n`
88
- + `Did you forget to rename the file/class to correspond to each other?` )
88
+ if ( ( cacheDocName . toLowerCase ( ) + '.cls' ) . indexOf ( matchingFileName . toLowerCase ( ) ) === - 1 )
89
+ return log (
90
+ `You tried to compile class named "${ cacheDocName } " in file "${ matchingFileName } ".\n`
91
+ + `Did you forget to rename the file/class to correspond to each other?`
92
+ )
89
93
cacheDocName += '.cls'
94
+
90
95
} else {
91
- // routine: cacheDocName = actual filename
92
- cacheDocName = ( fileName . match ( / [ \\ \/ ] ( [ ^ \\ \/ ] + ) $ / ) || [ ] ) [ 1 ] || ""
96
+
97
+ // routine: routine name must be declared in a routine
98
+ const cleanup = fileBody . replace ( / \/ \/ [ ^ \r \n ] * \r ? \n / g, '' )
99
+ cacheDocName = ( cleanup . match ( / r o u t i n e ( [ ^ \s ] + ) / i ) || [ ] ) [ 1 ] || ''
100
+ if ( ! cacheDocName )
101
+ return log (
102
+ `Unable to detect routine name in source code of ${ matchingFileName } .\n`
103
+ + `Is it a valid Caché ObjectScript routine? Did you forget to define a routine`
104
+ + ` name in the file on the first line? Routine code example: \n\n`
105
+ + `ROUTINE ${ matchingName } [Type=MAC]`
106
+ + `\n write "routine code here"\n quit`
107
+ )
108
+ const rtnType = ( cleanup . match ( / r o u t i n e \s + [ ^ \s ] + \s + \[ .* t y p e = ( [ a - z ] { 3 , } ) / i ) || [ ] ) [ 1 ] || 'MAC'
109
+ if ( ( ( cacheDocName + '.' + rtnType ) . toLowerCase ( ) ) . indexOf ( matchingFileName . toLowerCase ( ) ) === - 1 )
110
+ return log (
111
+ `You tried to compile routine named "${ cacheDocName } " (.${ rtnType } ) in file "${
112
+ matchingFileName } ".\nDid you forget to rename the file/routine to correspond to each other? `
113
+ + `Routine code example: \n\n`
114
+ + `ROUTINE ${ matchingName } [Type=${ rtnType } ]`
115
+ + `\n write "routine code here"\n quit`
116
+ )
117
+ cacheDocName += '.' + rtnType
118
+
93
119
}
94
120
95
121
const anyErrors = ( err , res , keyword ) => {
0 commit comments