Skip to content

Commit 82bb925

Browse files
Additional warnings about routine compilation add
1 parent 197e927 commit 82bb925

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

cos.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,49 @@ const activate = context => {
7373
const fileBody = openedDoc.getText()
7474
const isClass = /\.cls$/i.test( fileName )
7575
const content = fileBody.split( /\r?\n/g )
76+
const matchingFileName = ( fileName.match(/[^\\\/]+$/) || [] )[ 0 ] || ''
77+
const matchingName = matchingFileName.replace( /\.[^.]+$/, '' )
7678

7779
if ( isClass ) {
80+
7881
// Caché class files can be placed hierarchically (e.g. /src/Package/Class.cls),
7982
// so we pick the class name from the class definition itself
80-
cacheDocName = (fileBody.replace( /\/\/[^\r\n]*\r?\n/g, '' ).match( /Class ([^\s]+)/i ) || [])[ 1 ] || ""
83+
cacheDocName = (fileBody.replace( /\/\/[^\r\n]*\r?\n/g, '' ).match( /Class ([^\s]+)/i ) || [])[ 1 ] || ''
8184
const nameParts = cacheDocName.split( /\./g ).filter(s => !!s)
8285
if ( nameParts.length < 2 )
8386
return log( `Unable to detect class name in source code of ${ fileName }.\n`
8487
+ `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+
)
8993
cacheDocName += '.cls'
94+
9095
} 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( /routine ([^\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( /routine\s+[^\s]+\s+\[.*type=([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+
93119
}
94120

95121
const anyErrors = (err, res, keyword) => {

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-cos",
33
"displayName": "Caché ObjectScript",
44
"description": "Caché ObjectScript language support for Visual Studio Code",
5-
"version": "0.1.0",
5+
"version": "0.1.1",
66
"icon": "images/logo.png",
77
"categories": [
88
"Languages",
@@ -14,7 +14,10 @@
1414
},
1515
"publisher": "doublefint",
1616
"contributors": [
17-
{ "name": "Nikita Savchenko", "email": "[email protected]" }
17+
{
18+
"name": "Nikita Savchenko",
19+
"email": "[email protected]"
20+
}
1821
],
1922
"engines": {
2023
"vscode": "^1.5.0"
@@ -72,10 +75,10 @@
7275
],
7376
"keybindings": [
7477
{
75-
"command": "cos.compile",
76-
"key": "Ctrl+F7",
77-
"mac": "Cmd+F7"
78-
}
78+
"command": "cos.compile",
79+
"key": "Ctrl+F7",
80+
"mac": "Cmd+F7"
81+
}
7982
],
8083
"configuration": {
8184
"title": "cos",

0 commit comments

Comments
 (0)