Skip to content

Commit 21f40b2

Browse files
committed
add connection and export sources
1 parent 76fe92c commit 21f40b2

File tree

5 files changed

+215
-27
lines changed

5 files changed

+215
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Change Log
2-
All notable changes to the "intersystems-cos" extension will be documented in this file.
32

4-
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
3+
## [0.0.3]
4+
### Added
5+
- Config connection to server REST API: press Ctrl+Shift+P, type 'Pref', press Enter
6+
- Export sources (experimental): press Ctrl+Shift+P, type 'cos', press Enter
57

6-
## [Unreleased]
8+
## [0.0.1]
79
- Initial release

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# vscode-COS
1+
# vscode-cos
22
Initial [Cache](http://www.intersystems.com/our-products/cache/cache-overview/) ObjectScript ( COS ) language support for Visual Studio Code
33

44
## Features
55

66
![example](images/screenshot.png)
7+
- Connect to Caché instance via Atelier API ( edit 'cos' section in File - Preferences - Settings )
8+
- Export sources ( press Ctrl+Shift+P, type 'cos', press Enter )
79

810
## Notes
9-
Language support based on https://github.com/RustamIbragimov/atom-language-cos
11+
For Caché instance with maximum security level, add %Development role for /api/atelier/ web-application ( [More]( https://community.intersystems.com/post/using-atelier-rest-api) )
12+
13+
Language support based on https://github.com/RustamIbragimov/atom-language-cos

cos.js

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
2+
const vscode = require('vscode')
3+
const workspace = vscode.workspace
4+
const window = vscode.window
5+
const API = require('cos-api4node')
6+
const fs = require('fs')
7+
8+
const createBar = () => {
9+
10+
const left = vscode.StatusBarAlignment.Left
11+
const server = vscode.window.createStatusBarItem( left )
12+
// server.command = "cos.server"
13+
server.show()
14+
15+
return {
16+
set: conn => { server.text = `${conn.label}:${conn.ns}` }
17+
}
18+
}
19+
20+
const activate = context => {
21+
22+
const bar = createBar()
23+
24+
const output = window.createOutputChannel( 'cos' )
25+
26+
const log = msg => output.appendLine( msg )
27+
28+
const conn = workspace.getConfiguration( 'cos' ).get( 'conn' )
29+
30+
const api = API( conn )
31+
32+
api.headServer( ( err ) => {
33+
34+
if ( !!err ) return log( 'connect FAIL ' + JSON.stringify( err ) )
35+
log( 'connected ' + JSON.stringify( conn ) )
36+
bar.set( conn )
37+
38+
})
39+
40+
const cosExport = () => {
41+
42+
const exportDoc = ( doc, cb ) => {
43+
44+
const root = workspace.rootPath
45+
if ( typeof root === 'undefined' ){
46+
log('')
47+
log('Open folder before export - Ctrl+K, Ctrl+O')
48+
return cb()
49+
}
50+
51+
let exportDir = root + '/src/'
52+
if ( !fs.existsSync( exportDir ) ) fs.mkdirSync( exportDir )
53+
exportDir += doc.cat + '/'
54+
if ( !fs.existsSync( exportDir ) ) fs.mkdirSync( exportDir )
55+
56+
const filepath = exportDir + doc.name
57+
fs.writeFileSync( filepath, doc.content.join('\n') )
58+
59+
60+
log( doc.name + ' -> ' + filepath )
61+
cb( null, {} )
62+
63+
}
64+
65+
const load = ( doc, cb ) => {
66+
67+
const loaded = ( err, data ) => {
68+
69+
if ( !!err ) {
70+
71+
log('')
72+
log( 'ERROR!!!: ' + doc.name + JSON.stringify( err ) )
73+
log('')
74+
return cb( err )
75+
76+
}
77+
78+
const json = JSON.parse( data )
79+
const content = json.result
80+
exportDoc( content, cb )
81+
82+
}
83+
84+
api.getDoc( encodeURI(doc.name), loaded )
85+
86+
}
87+
88+
const exportDocs = ( docs, cb ) => {
89+
const doc = docs.shift()
90+
if (!doc ) return cb()
91+
92+
load( doc, ( err, data )=>{
93+
if ( err ) log( 'ERROR: ' + JSON.stringify(doc) + ' ' + JSON.stringify( err ) )
94+
exportDocs( docs, cb ) //continue
95+
})
96+
}
97+
98+
99+
const onGetDocs = ( err, data ) => {
100+
101+
if ( err ) return log( 'getDocs ERROR')
102+
103+
const json = JSON.parse( data )
104+
const list = json.result.content
105+
log( '' )
106+
log( 'list: ' + list.length )
107+
const docs = list.filter( doc => ( doc.cat !== 'CSP' ) && ( doc.name.substring( 0, 1 ) !== '%' ) && ( doc.name.substring( 0, 12 ) !== 'INFORMATION.' ) )
108+
log( 'without % and CSP and INFORMATION: ' + docs.length )
109+
log( '' )
110+
exportDocs( docs, ()=>{
111+
log( '' )
112+
log( 'Export completed.' )
113+
})
114+
115+
}
116+
117+
api.getDocNames( { generated: 0 }, onGetDocs )
118+
119+
}
120+
121+
// command 'cos.server' defined in statusBar
122+
const cmd = vscode.commands.registerCommand( 'cos.export', cosExport )
123+
context.subscriptions.push( cmd )
124+
125+
}
126+
127+
module.exports = { activate, deactivate: () => {} }

package.json

Lines changed: 76 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,78 @@
11
{
2-
"name": "vscode-cos",
3-
"displayName": "Caché ObjectScript",
4-
"description": "Caché ObjectScript language support for Visual Studio Code",
5-
"version": "0.0.2",
6-
"icon": "images/logo.png",
7-
"categories": [ "Languages" ],
8-
"repository": { "type": "git", "url": "https://github.com/doublefint/vscode-cos.git" },
9-
"publisher": "doublefint",
10-
"engines": { "vscode": "^1.5.0" },
11-
"contributes": {
12-
"languages": [{
13-
"id": "cachéobjectscript",
14-
"aliases": ["Caché ObjectScript", "COS"],
15-
"extensions": [".cls","*.rtn","*.mac","*.int","*.inc"],
16-
"configuration": "./language-configuration.json"
17-
}],
18-
"grammars": [{
19-
"language": "cachéobjectscript",
20-
"scopeName": "source.cos",
21-
"path": "./syntaxes/cos.tmLanguage.json"
22-
}]
2+
"name": "vscode-cos",
3+
"displayName": "Caché ObjectScript",
4+
"description": "Caché ObjectScript language support for Visual Studio Code",
5+
"version": "0.0.3",
6+
"icon": "images/logo.png",
7+
"categories": [
8+
"Languages",
9+
"Other"
10+
],
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/doublefint/vscode-cos.git"
14+
},
15+
"publisher": "doublefint",
16+
"engines": {
17+
"vscode": "^1.5.0"
18+
},
19+
"activationEvents": [
20+
"*"
21+
],
22+
"main": "./cos",
23+
"contributes": {
24+
"languages": [
25+
{
26+
"id": "cachéobjectscript",
27+
"aliases": [
28+
"Caché ObjectScript",
29+
"COS"
30+
],
31+
"extensions": [
32+
".cls"
33+
],
34+
"configuration": "./language-configuration.json"
35+
}
36+
],
37+
"grammars": [
38+
{
39+
"language": "cachéobjectscript",
40+
"scopeName": "source.cos",
41+
"path": "syntaxes/cos.tmLanguage.json"
42+
}
43+
],
44+
"commands": [
45+
{
46+
"category": "cos",
47+
"command": "cos.export",
48+
"title": "export sources"
49+
}
50+
],
51+
"configuration": {
52+
"title": "cos",
53+
"type": "object",
54+
"properties": {
55+
"cos.conn": {
56+
"description": "connection to cos server",
57+
"type": "object",
58+
"default": {
59+
"label": "LOCAL",
60+
"host": "127.0.0.1",
61+
"port": 57772,
62+
"username": "_SYSTEM",
63+
"password": "SYS",
64+
"path": "/api/atelier/",
65+
"version": "v1",
66+
"ns": "SAMPLES"
67+
}
68+
}
69+
}
2370
}
24-
}
71+
},
72+
"devDependencies": {
73+
"vscode": "^1.0.3"
74+
},
75+
"dependencies": {
76+
"cos-api4node": "^1.1.0"
77+
}
78+
}

0 commit comments

Comments
 (0)