1
- import vscode = require( " vscode" ) ;
1
+ import vscode = require( ' vscode' ) ;
2
2
const { workspace, window } = vscode ;
3
- import http = require( " http" ) ;
3
+ import http = require( ' http' ) ;
4
4
5
- const API = require ( " cos-api4node" ) ;
6
- const LOG = require ( " ./log" ) ;
7
- const panel = require ( " ./status-bar-panel" ) ;
8
- const CmdExport = require ( " ./commands/export" ) ;
9
- const { CurrentDoc } = require ( " ./commands/currentdoc" ) ;
10
- const IsApiError = require ( " ./is-api-error" ) ;
5
+ const API = require ( ' cos-api4node' ) ;
6
+ const LOG = require ( ' ./log' ) ;
7
+ const panel = require ( ' ./status-bar-panel' ) ;
8
+ const CmdExport = require ( ' ./commands/export' ) ;
9
+ const { CurrentDoc } = require ( ' ./commands/currentdoc' ) ;
10
+ const IsApiError = require ( ' ./is-api-error' ) ;
11
11
12
- import { COSExplorerProvider } from "./explorer/explorer" ;
12
+ import { AtelierAPI } from './api' ;
13
+
14
+ import { COSExplorerProvider } from './explorer/explorer' ;
13
15
export var cosExplorerProvider : COSExplorerProvider ;
14
16
15
17
export async function activate ( context : vscode . ExtensionContext ) : Promise < void > {
16
- const languages = require ( context . asAbsolutePath ( " ./package.json" ) ) [ " contributes" ] [ " languages" ] . map ( lang => lang . id ) ;
18
+ const languages = require ( context . asAbsolutePath ( ' ./package.json' ) ) [ ' contributes' ] [ ' languages' ] . map ( lang => lang . id ) ;
17
19
18
20
const log = LOG ( window ) ;
19
21
20
22
cosExplorerProvider = new COSExplorerProvider ( ) ;
21
- vscode . window . registerTreeDataProvider ( " cosExplorer" , cosExplorerProvider ) ;
23
+ vscode . window . registerTreeDataProvider ( ' cosExplorer' , cosExplorerProvider ) ;
22
24
23
25
const Config = workspace => {
24
26
let options = null ;
25
27
const init = ( ) => {
26
- options = workspace . getConfiguration ( " cos" ) ;
28
+ options = workspace . getConfiguration ( ' cos' ) ;
27
29
} ;
28
30
init ( ) ;
29
31
30
32
return {
31
33
init,
32
34
get : option => options . get ( option ) ,
33
35
conn : ( ) => {
34
- const _conn = options . get ( " conn" ) ;
35
- _conn . toString = ( ) => JSON . stringify ( Object . assign ( { } , _conn , { password : " ***" } ) , null , 4 ) ;
36
+ const _conn = options . get ( ' conn' ) ;
37
+ _conn . toString = ( ) => JSON . stringify ( Object . assign ( { } , _conn , { password : ' ***' } ) , null , 4 ) ;
36
38
return _conn ;
37
39
} ,
38
40
export : ( ) => {
39
41
const root = workspace . rootPath ;
40
- return Object . assign ( { } , options . get ( " export" ) , { root } ) ;
42
+ return Object . assign ( { } , options . get ( ' export' ) , { root } ) ;
41
43
}
42
44
} ;
43
45
} ;
44
46
45
47
let api ;
48
+ let atelierApi : AtelierAPI ;
46
49
const Connect = conn => {
47
50
api = API ( conn ) ;
51
+ atelierApi = new AtelierAPI ( conn . host , conn . port , conn . username , conn . password , conn . ns , conn . https ) ;
52
+ atelierApi
53
+ . serverInfo ( )
54
+ . then ( info => { } )
55
+ . catch ( err => { } ) ;
48
56
api . headServer ( err => {
49
57
const conn = config . conn ( ) ;
50
- if ( err ) return log ( " Connection FAILED: " + conn , err ) ;
51
- log ( " Connected " + conn ) ;
58
+ if ( err ) return log ( ' Connection FAILED: ' + conn , err ) ;
59
+ log ( ' Connected ' + conn ) ;
52
60
panel . set ( conn ) ;
53
61
} ) ;
54
62
cosExplorerProvider . setAPI ( api , conn . ns ) ;
@@ -77,7 +85,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
77
85
) ; //reload config on event
78
86
79
87
workspace . onDidSaveTextDocument ( file => {
80
- if ( ! config . get ( " autoCompile" ) ) {
88
+ if ( ! config . get ( ' autoCompile' ) ) {
81
89
return ;
82
90
}
83
91
if ( languages . includes ( file . languageId ) ) {
@@ -89,18 +97,18 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
89
97
90
98
const Save = ( { name, log, fileName } ) => ( err , data ) => {
91
99
// IsApiError, ExportDoc - global
92
- const isGetDocError = IsApiError ( name , " getDoc" , log , window ) ;
100
+ const isGetDocError = IsApiError ( name , ' getDoc' , log , window ) ;
93
101
if ( isGetDocError ( { err, data } ) ) return ;
94
102
95
- const completed = ( ) => log ( " Completed." ) ;
103
+ const completed = ( ) => log ( ' Completed.' ) ;
96
104
const exportDoc = ExportDoc ( { name, cat : data . result . cat , fileName } , completed ) ;
97
105
98
106
exportDoc ( { err, data } ) ;
99
107
} ;
100
108
101
109
const Export = ( { api, name, log, fileName } ) => ( err , data ) => {
102
110
// IsApiError, Save - from upper scope
103
- const isCompileError = IsApiError ( name , " compile" , log , window ) ;
111
+ const isCompileError = IsApiError ( name , ' compile' , log , window ) ;
104
112
if ( isCompileError ( { err, data } ) ) return ;
105
113
// after compilation API returns updated storage definition
106
114
// but, currently, we don`t have any AST implementation
@@ -113,7 +121,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
113
121
114
122
const Compile = ( { api, name, log, fileName } ) => ( err , data ) => {
115
123
// IsApiError, Export
116
- const isImportError = IsApiError ( name , " import" , log , window ) ;
124
+ const isImportError = IsApiError ( name , ' import' , log , window ) ;
117
125
if ( isImportError ( { err, data } ) ) return ;
118
126
119
127
const exportCurrent = Export ( { api, name, log, fileName } ) ;
@@ -134,22 +142,51 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
134
142
api . putDoc ( name , { enc : false , content } , { ignoreConflict : true } , compile ) ;
135
143
} ;
136
144
145
+ const viewOther = ( ) => {
146
+ const { name, error } = currentDoc ( ) ;
147
+ if ( error ) return log ( error ) ;
148
+
149
+ const getOthers = info => {
150
+ return info . result . content [ 0 ] . others ;
151
+ } ;
152
+
153
+ atelierApi
154
+ . actionIndex ( [ name ] )
155
+ . then ( info => {
156
+ const listOthers = getOthers ( info ) || [ ] ;
157
+ if ( ! listOthers . length ) {
158
+ return ;
159
+ }
160
+ if ( listOthers . length === 1 ) {
161
+ window . showTextDocument ( vscode . Uri . parse ( encodeURI ( `cos:///${ listOthers [ 0 ] } ` ) ) ) ;
162
+ } else {
163
+ window . showQuickPick ( listOthers ) . then ( item => {
164
+ window . showTextDocument ( vscode . Uri . parse ( encodeURI ( `cos:///${ item } ` ) ) ) ;
165
+ } ) ;
166
+ }
167
+ } )
168
+ . catch ( err => {
169
+ log ( 'error' + err ) ;
170
+ } ) ;
171
+ } ;
172
+
137
173
context . subscriptions . push (
138
- vscode . commands . registerCommand ( "cos.compile" , importCompileExport ) ,
139
- vscode . commands . registerCommand ( "cos.export" , exportAll ) ,
140
- vscode . commands . registerCommand ( "vscode-cos.explorer.refresh" , ( ) => cosExplorerProvider . refresh ( ) ) ,
141
- vscode . commands . registerCommand ( "vscode-cos.explorer.openClass" , vscode . window . showTextDocument ) ,
142
- vscode . commands . registerCommand ( "vscode-cos.explorer.openRoutine" , vscode . window . showTextDocument ) ,
143
- vscode . commands . registerCommand ( "vscode-cos.explorer.showSystem" , ( ) => {
144
- vscode . commands . executeCommand ( "setContext" , "vscode-cos.explorer.showSystem" , true ) ;
174
+ vscode . commands . registerCommand ( 'cos.compile' , importCompileExport ) ,
175
+ vscode . commands . registerCommand ( 'cos.export' , exportAll ) ,
176
+ vscode . commands . registerCommand ( 'vscode-cos.viewother' , viewOther ) ,
177
+ vscode . commands . registerCommand ( 'vscode-cos.explorer.refresh' , ( ) => cosExplorerProvider . refresh ( ) ) ,
178
+ vscode . commands . registerCommand ( 'vscode-cos.explorer.openClass' , vscode . window . showTextDocument ) ,
179
+ vscode . commands . registerCommand ( 'vscode-cos.explorer.openRoutine' , vscode . window . showTextDocument ) ,
180
+ vscode . commands . registerCommand ( 'vscode-cos.explorer.showSystem' , ( ) => {
181
+ vscode . commands . executeCommand ( 'setContext' , 'vscode-cos.explorer.showSystem' , true ) ;
145
182
cosExplorerProvider . showSystem = true ;
146
183
} ) ,
147
- vscode . commands . registerCommand ( " vscode-cos.explorer.hideSystem" , ( ) => {
148
- vscode . commands . executeCommand ( " setContext" , " vscode-cos.explorer.showSystem" , false ) ;
184
+ vscode . commands . registerCommand ( ' vscode-cos.explorer.hideSystem' , ( ) => {
185
+ vscode . commands . executeCommand ( ' setContext' , ' vscode-cos.explorer.showSystem' , false ) ;
149
186
cosExplorerProvider . showSystem = false ;
150
187
} ) ,
151
188
152
- vscode . workspace . registerTextDocumentContentProvider ( " cos" , cosExplorerProvider )
189
+ vscode . workspace . registerTextDocumentContentProvider ( ' cos' , cosExplorerProvider )
153
190
) ;
154
191
}
155
192
0 commit comments