Skip to content

Commit a8c71da

Browse files
authored
Merge pull request #6 from ZitRos/master
Add *.mac Compilation Support and Additional Routine Compilation Warnings
2 parents 197e927 + 36d55b6 commit a8c71da

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
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: 11 additions & 7 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.2",
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"
@@ -31,7 +34,8 @@
3134
"COS"
3235
],
3336
"extensions": [
34-
".cls"
37+
".cls",
38+
".mac"
3539
],
3640
"configuration": "./language-configuration.json"
3741
},
@@ -72,10 +76,10 @@
7276
],
7377
"keybindings": [
7478
{
75-
"command": "cos.compile",
76-
"key": "Ctrl+F7",
77-
"mac": "Cmd+F7"
78-
}
79+
"command": "cos.compile",
80+
"key": "Ctrl+F7",
81+
"mac": "Cmd+F7"
82+
}
7983
],
8084
"configuration": {
8185
"title": "cos",

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Configure connection
1313
To be able to use many plugin features, you need to configure the connection to Caché server first.
1414

1515
- Find a 'cos.conn' section in workspace settings (File - Preferences - Settings)
16-
- change settings according to your Caché instance and reload VSCode ( as temporary solution )
16+
- Change settings according to your Caché instance and reload VSCode ( as temporary solution )
17+
- You will see Caché-related output in "Output" while switched to "cos" channel (right drop-down menu on top of the output window)
1718

1819
Features
1920
--------

0 commit comments

Comments
 (0)