@@ -2,14 +2,16 @@ import { AdtConnection } from "./AdtConnection"
22import { Uri , FileSystemError , FileType , commands } from "vscode"
33import { MetaFolder } from "../fs/MetaFolder"
44import { AbapObjectNode , AbapNode , isAbapNode } from "../fs/AbapNode"
5- import { AbapObject , TransportStatus , isAbapObject } from ".. /abap/AbapObject"
5+ import { AbapObject , TransportStatus , isAbapObject } from "./abap/AbapObject"
66import { getRemoteList } from "../config"
77import { selectTransport } from "./AdtTransports"
8- import { AdtObjectActivator } from "./AdtObjectActivator"
8+ import { AdtObjectActivator } from "./operations/ AdtObjectActivator"
99import { pick } from "../functions"
10- import { AdtObjectFinder } from "./AdtObjectFinder"
11- import { AdtObjectCreator } from "./create/AdtObjectCreator"
12- import { PACKAGE } from "./create/AdtObjectTypes"
10+ import { AdtObjectFinder } from "./operations/AdtObjectFinder"
11+ import { AdtObjectCreator } from "./operations/AdtObjectCreator"
12+ import { PACKAGE } from "./operations/AdtObjectTypes"
13+ import { LockManager } from "./operations/LockManager"
14+ import { AdtException } from "./AdtExceptions"
1315export const ADTBASEURL = "/sap/bc/adt/repository/nodestructure"
1416
1517/**
@@ -20,7 +22,7 @@ export const ADTBASEURL = "/sap/bc/adt/repository/nodestructure"
2022const uriParts = ( uri : Uri ) : string [ ] =>
2123 uri . path
2224 . split ( "/" )
23- . filter ( ( v , idx , arr ) => ( idx > 0 && idx < arr . length - 1 ) || v ) //ignore empty at begginning or end
25+ . filter ( ( v , idx , arr ) => ( idx > 0 && idx < arr . length - 1 ) || v ) //ignore empty at beginning or end
2426/**
2527 * centralizes most API accesses
2628 * some will be delegated/provided from members or ABAP object nodes
@@ -30,7 +32,8 @@ export class AdtServer {
3032 private readonly activator : AdtObjectActivator
3133 readonly root : MetaFolder
3234 readonly objectFinder : AdtObjectFinder
33- creator : AdtObjectCreator
35+ readonly creator : AdtObjectCreator
36+ readonly lockManager : LockManager
3437 private lastRefreshed ?: string
3538
3639 /**
@@ -50,6 +53,7 @@ export class AdtServer {
5053 this . creator = new AdtObjectCreator ( this )
5154 this . activator = new AdtObjectActivator ( this . connection )
5255 this . objectFinder = new AdtObjectFinder ( this . connection )
56+ this . lockManager = new LockManager ( this . connection )
5357 this . connection
5458 . connect ( )
5559 . then ( pick ( "body" ) )
@@ -109,32 +113,40 @@ export class AdtServer {
109113 if ( ! isAbapNode ( file ) )
110114 throw FileSystemError . NoPermissions ( "Can only save source code" )
111115
112- await file . abapObject . lock ( this . connection )
113- if ( file . abapObject . transport === TransportStatus . REQUIRED ) {
116+ const obj = file . abapObject
117+ //check file is locked
118+ if ( ! this . lockManager . isLocked ( obj ) )
119+ throw new AdtException (
120+ "lockNotFound" ,
121+ `Object not locked ${ obj . type } ${ obj . name } `
122+ )
123+
124+ if ( obj . transport === TransportStatus . REQUIRED ) {
114125 const transport = await selectTransport (
115- file . abapObject . getContentsUri ( this . connection ) ,
126+ obj . getContentsUri ( this . connection ) ,
116127 "" ,
117128 this . connection
118129 )
119130 if ( transport ) file . abapObject . transport = transport
120131 }
121132
122- await file . abapObject . setContents ( this . connection , content )
133+ const lockId = this . lockManager . getLockId ( obj )
134+ await obj . setContents ( this . connection , content , lockId )
123135
124- await file . abapObject . unlock ( this . connection )
125136 await file . stat ( this . connection )
137+ await this . lockManager . unlock ( obj )
126138 //might have a race condition with user changing editor...
127139 commands . executeCommand ( "setContext" , "abapfs:objectInactive" , true )
128140 }
129141
130142 /**
131143 * converts vscode URI to ADT URI
132- * @see findNodeHierarcy for more details
144+ * @see findNodeHierarchy for more details
133145 *
134146 * @param uri vscode URI
135147 */
136148 findNode ( uri : Uri ) : AbapNode {
137- return this . findNodeHierarcy ( uri ) [ 0 ]
149+ return this . findNodeHierarchy ( uri ) [ 0 ]
138150 }
139151
140152 /**
@@ -145,7 +157,7 @@ export class AdtServer {
145157 * @abstract visual studio paths are hierarchic, adt ones aren't
146158 * so we need a way to translate the hierarchic ones to the original ones
147159 * this file is concerned with telling whether a path is a real ADT one or one from vscode
148- * /sap/bc/adt/repository/nodestructure (with ampty query) is the root of both
160+ * /sap/bc/adt/repository/nodestructure (with empty query) is the root of both
149161 * also, several objects have namespaces.
150162 * Class /foo/bar of package /foo/baz in code will have a path like
151163 * /sap/bc/adt/repository/nodestructure/foo/baz/foo/bar
@@ -155,7 +167,7 @@ export class AdtServer {
155167 *
156168 * @param uri VSCode URI
157169 */
158- findNodeHierarcy ( uri : Uri ) : AbapNode [ ] {
170+ findNodeHierarchy ( uri : Uri ) : AbapNode [ ] {
159171 const parts = uriParts ( uri )
160172 return parts . reduce (
161173 ( current : AbapNode [ ] , name ) => {
@@ -185,7 +197,7 @@ export class AdtServer {
185197 for ( const part of parts ) {
186198 let next : AbapNode | undefined = node . getChild ( part )
187199 if ( ! next && refreshable ) {
188- //refreshable will tipically be the current node or its first abap parent (usually a package)
200+ //refreshable will typically be the current node or its first abap parent (usually a package)
189201 await refreshable . refresh ( this . connection )
190202 next = node . getChild ( part )
191203 }
@@ -259,3 +271,10 @@ export const fromUri = (uri: Uri) => {
259271 if ( uri . scheme === "adt" ) return getServer ( uri . authority )
260272 throw FileSystemError . FileNotFound ( uri )
261273}
274+ export async function disconnect ( ) {
275+ const promises : Promise < any > [ ] = [ ]
276+ for ( const server of servers ) {
277+ promises . push ( server [ 1 ] . connection . dropSession ( ) )
278+ }
279+ await Promise . all ( promises )
280+ }
0 commit comments