Skip to content

Commit 1f31493

Browse files
fix Modification of newly created FM #214
1 parent e33a15a commit 1f31493

File tree

13 files changed

+58
-30
lines changed

13 files changed

+58
-30
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [1.7.7] 2024-04-20
4+
5+
### Fixed
6+
7+
- editing newly created FM
8+
39
## [1.7.6] 2024-04-13
410

511
### Added

abap remote fs.code-workspace

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"**/.project": true,
3535
"**/.settings": true,
3636
"**/.factorypath": true,
37-
"**/node_modules/**": true,
38-
"**/tmp/**": true
37+
"**/node_modules/**": true
3938
},
4039
"prettier.arrowParens": "avoid",
4140
"prettier.proseWrap": "never",
@@ -48,7 +47,9 @@
4847
"wiki",
4948
"sharedapi"
5049
],
51-
"tslint.exclude": ["**/node_modules/**"],
50+
"tslint.exclude": [
51+
"**/node_modules/**"
52+
],
5253
"githubIssues.queries": [
5354
{
5455
"label": "My Issues",
@@ -95,4 +96,4 @@
9596
"typescript.format.placeOpenBraceOnNewLineForFunctions": false,
9697
"typescript.preferences.quoteStyle": "auto"
9798
}
98-
}
99+
}

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"@abaplint/core": "^2.102.65",
6262
"@types/tmp": "0.2.3",
6363
"abap_cloud_platform": "^1.1.3",
64-
"abap-adt-api": "^5.2.6",
64+
"abap-adt-api": "^5.2.7",
6565
"abapfs": "file:../modules/abapfs",
6666
"abapobject": "file:../modules/abapObject",
6767
"client-oauth2": "^4.3.3",

client/src/adt/operations/AdtObjectCreator.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
createUri
3232
} from "./AdtObjectFinder"
3333
import { getClient, getRoot } from "../conections"
34-
import { isAbapStat, isFolder } from "abapfs"
34+
import { isAbapFolder, isAbapStat, isFolder } from "abapfs"
3535
import { fromNode } from "abapobject"
3636
import { pipe } from "fp-ts/lib/pipeable"
3737
import { bind, chain, map } from "fp-ts/lib/TaskEither"
@@ -75,7 +75,13 @@ export class AdtObjectCreator {
7575
if (otype === PACKAGE) otype = ""
7676
return this.types!.filter(x => x.PARENT_OBJECT_TYPE === otype)
7777
}
78-
78+
private async getAndRefreshParent(options: NewObjectOptions) {
79+
if (options.objtype !== "FUGR/FF") return
80+
const finder = new AdtObjectFinder(this.connId)
81+
const { file, uri } = await finder.vscodeUriWithFile(options.parentPath, false)
82+
if (isAbapFolder(file)) await file.refresh()
83+
if (isAbapStat(file)) return file.object
84+
}
7985
/**
8086
* Creates an ABAP object asking the user for unknown details
8187
* Tries to guess object type and parent/package from URI
@@ -99,7 +105,7 @@ export class AdtObjectCreator {
99105
if (transport.cancelled) return
100106
options.transport = transport.transport
101107
await getClient(this.connId).createObject(options)
102-
108+
const parent = await this.getAndRefreshParent(objDetails.options)
103109
const obj = fromNode(
104110
{
105111
EXPANDABLE: "",
@@ -109,12 +115,13 @@ export class AdtObjectCreator {
109115
OBJECT_VIT_URI: "",
110116
TECH_NAME: options.name
111117
},
112-
undefined,
118+
parent,
113119
getRoot(this.connId).service
114120
)
115121
if (options.objtype !== PACKAGE) await obj.loadStructure()
116122
return obj
117123
}
124+
118125
public guessParentByType(hierarchy: FileStat[], type: ParentTypeIds): string {
119126
return (
120127
hierarchy.filter(isAbapStat).find(n => n.object.type === type)?.object

client/src/adt/operations/AdtObjectFinder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ export class AdtObjectFinder {
103103
return uf.uri
104104
}
105105

106+
public async vscodeObject(uri: string, main = true) {
107+
const { file } = await this.vscodeUriWithFile(uri, main)
108+
if (isAbapStat(file)) return file.object
109+
}
110+
106111
public clearCaches() {
107112
this.fragCache = promCache()
108113
}

client/src/commands/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export class AdtCommands {
222222
const obj = await new AdtObjectCreator(connId).createObject(uri)
223223
if (!obj) return // user aborted
224224
log(`Created object ${obj.type} ${obj.name}`)
225+
await obj.loadStructure()
225226

226227
if (obj.type === PACKAGE) {
227228
commands.executeCommand("workbench.files.action.refreshFilesExplorer")

modules/abapObject/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"typescript": "^4.9.4"
2121
},
2222
"dependencies": {
23-
"abap-adt-api": "^5.2.6"
23+
"abap-adt-api": "^5.2.7"
2424
}
2525
}

modules/abapObject/src/AOService.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import {
33
AbapObjectStructure,
44
NodeStructure,
55
ADTClient,
6-
NodeParents
6+
NodeParents,
7+
ObjectVersion
78
} from "abap-adt-api"
89

910
export interface AbapObjectService {
1011
mainPrograms: (path: string) => Promise<MainInclude[]>
1112
/** Loads the object metadata
1213
* As will be called way too often, we will cache it for a second
1314
*/
14-
objectStructure: (path: string) => Promise<AbapObjectStructure>
15+
objectStructure: (path: string, refresh?: boolean, version?: ObjectVersion) => Promise<AbapObjectStructure>
1516
/** invalidate structure cache
1617
* to be invoked after changing operations.
1718
* will happen automatically on write
@@ -31,28 +32,30 @@ export interface AbapObjectService {
3132
export class AOService implements AbapObjectService {
3233
constructor(protected client: ADTClient) { }
3334

34-
private structCache = new Map<string, Promise<AbapObjectStructure>>()
35+
private activeStructCache = new Map<string, Promise<AbapObjectStructure>>()
3536

3637
delete(path: string, lockId: string, transport: string) {
3738
return this.client.deleteObject(path, lockId, transport)
3839
}
3940

4041
invalidateStructCache(uri: string) {
41-
this.structCache.delete(uri)
42+
this.activeStructCache.delete(uri)
4243
}
4344

4445
mainPrograms(path: string) {
4546
return this.client.statelessClone.mainPrograms(path)
4647
}
4748

48-
objectStructure(path: string) {
49-
let structure = this.structCache.get(path)
49+
objectStructure(path: string, refresh = false, version?: ObjectVersion) {
50+
if (refresh) this.activeStructCache.delete(path)
51+
let structure = this.activeStructCache.get(path)
5052
if (!structure) {
51-
structure = this.client.statelessClone.objectStructure(path)
52-
this.structCache.set(path, structure)
53-
structure.finally(() =>
54-
setTimeout(() => this.invalidateStructCache(path), 800)
55-
)
53+
structure = this.client.statelessClone.objectStructure(path, version)
54+
this.activeStructCache.set(path, structure)
55+
if (!version || version === "active")
56+
structure.finally(() =>
57+
setTimeout(() => this.invalidateStructCache(path), 800)
58+
)
5659
}
5760
return structure
5861
}

modules/abapObject/src/AbapObject.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AbapObjectStructure,
33
MainInclude,
44
NodeStructure,
5+
ObjectVersion,
56
isNodeParent
67
} from "abap-adt-api"
78
import { AbapObjectService } from "./AOService"
@@ -47,6 +48,7 @@ export interface AbapObject {
4748
readonly changedAt: Date | undefined
4849
/** reads the main objects available for this object */
4950
mainPrograms: () => Promise<MainInclude[]>
51+
readonly parent: AbapObject | undefined,
5052
/** whether we are able to write it */
5153
readonly canBeWritten: boolean
5254
/** objcect namespace
@@ -64,13 +66,15 @@ export interface AbapObject {
6466
readonly owner?: string
6567

6668
/** loads/updates the object metadata */
67-
loadStructure: () => Promise<AbapObjectStructure>
69+
loadStructure: (refresh?: boolean, version?: ObjectVersion) => Promise<AbapObjectStructure>
6870
delete: (lockId: string, transport: string) => Promise<void>
6971
write: (contents: string, lockId: string, transport: string) => Promise<void>
7072
read: () => Promise<string>
7173
childComponents: () => Promise<NodeStructure>
7274
}
7375

76+
const ignoreErr = () => { }
77+
7478
export type AbapObjectConstructor = new (
7579
type: string,
7680
name: string,
@@ -180,11 +184,10 @@ export class AbapObjectBase implements AbapObject {
180184
return this.service.mainPrograms(this.path)
181185
}
182186

183-
async loadStructure(): Promise<AbapObjectStructure> {
187+
async loadStructure(refresh = false, version?: ObjectVersion): Promise<AbapObjectStructure> {
184188
if (!this.name) throw ObjectErrors.noStructure(this)
185-
this.structure = await this.service.objectStructure(
186-
this.path.replace(/\/source\/main$/, "")
187-
)
189+
const base = this.path.replace(/\/source\/main$/, "")
190+
this.structure = await this.service.objectStructure(base, refresh, version)
188191
return this.structure
189192
}
190193
async delete(lockId: string, transport = "") {
@@ -203,6 +206,8 @@ export class AbapObjectBase implements AbapObject {
203206
this.service.invalidateStructCache(this.path)
204207
if (this.lockObject !== this)
205208
this.service.invalidateStructCache(this.lockObject.path)
209+
if (this.parent && this.parent.type !== PACKAGE)
210+
await this.parent.loadStructure()
206211
}
207212

208213
async read() {

modules/abapObject/src/objectTypes/AbapFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class AbapFunction extends AbapObjectBase {
2525
this,
2626
"Parent function group is required for function modules"
2727
)
28-
if (!this.path.startsWith(parent.path))
28+
if (!this.path.toLowerCase().startsWith(parent.path.toLowerCase()))
2929
throw ObjectErrors.Invalid(
3030
this,
3131
`Function ${name} doesn't belong to group ${parent.name}`

0 commit comments

Comments
 (0)