/
AdtObjectActivator.ts
42 lines (40 loc) · 1.36 KB
/
AdtObjectActivator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { ADTClient, isAdtError, inactiveObjectsInResults } from "abap-adt-api"
import { AbapObject } from "../abap/AbapObject"
import { IncludeLensP } from "./IncludeLens"
import { Uri } from "vscode"
export class AdtObjectActivator {
constructor(private client: ADTClient) {}
public async activate(object: AbapObject, uri: Uri) {
// TODO: handle multiple inactive components
const inactive = object.getActivationSubject()
let result
let message
try {
result = await this.client.activate(inactive.name, inactive.path)
if (result.inactive.length > 0) {
const inactives = inactiveObjectsInResults(result)
result = await this.client.activate(inactives)
}
} catch (e) {
if (isAdtError(e) && e.type === "invalidMainProgram") {
const provider = IncludeLensP.get()
const mainProg = await provider.selectIncludeIfNeeded(uri)
if (mainProg)
result = await this.client.activate(
inactive.name,
inactive.path,
mainProg
)
} else message = e.toString()
}
if (result && result.success) {
await inactive.loadMetadata(this.client)
} else {
message =
(result && result.messages[0] && result.messages[0].shortText) ||
message ||
`Error activating ${object.name}`
throw new Error(message)
}
}
}