Skip to content

Commit 592e5c2

Browse files
extract method (#228)
1 parent e329de9 commit 592e5c2

File tree

18 files changed

+92
-56
lines changed

18 files changed

+92
-56
lines changed

.vscode/launch.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
"address": "localhost",
3131
"smartStep": true,
3232
"showAsyncStacks": true,
33-
"restart": true,
33+
"restart": {
34+
"delay": 2000,
35+
"maxAttempts": 100
36+
},
3437
"skipFiles": [
3538
"<node_internals>/**"
3639
],

client/package-lock.json

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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": "^6.1.0",
64+
"abap-adt-api": "^6.2.0",
6565
"abapfs": "file:../modules/abapfs",
6666
"abapobject": "file:../modules/abapObject",
6767
"client-oauth2": "^4.3.3",

client/src/commands/commands.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
window,
66
commands,
77
ProgressLocation,
8-
Position,
9-
Range
8+
Range,
9+
FileChangeType
1010
} from "vscode"
1111
import { pickAdtRoot, RemoteManager } from "../config"
12-
import { caughtToString, lineRange, log, splitAdtUri } from "../lib"
12+
import { caughtToString, inputBox, lineRange, log, rangeVscToApi, splitAdtUri } from "../lib"
1313
import { FavouritesProvider, FavItem } from "../views/favourites"
1414
import { findEditor, vsCodeUri } from "../langClient"
1515
import { showHideActivate } from "../listeners"
@@ -87,6 +87,27 @@ interface ShowObjectArgument {
8787
uri: string
8888
}
8989
export class AdtCommands {
90+
@command(AbapFsCommands.extractMethod)
91+
private static async extractMethod(url: string, range: Range) {
92+
const uri = Uri.parse(url)
93+
const client = getClient(uri.authority)
94+
const root = getRoot(uri.authority)
95+
const file = await root.getNodeAsync(uri.path)
96+
if (isAbapFile(file)) {
97+
const o = file.object
98+
const proposal = await client.extractMethodEvaluate(o.path, rangeVscToApi(range))
99+
const methodName = await window.showInputBox({ prompt: "Method name" })
100+
if (!methodName) return
101+
const transport = await selectTransport(o.path, "", client)
102+
if (transport.cancelled) return
103+
proposal.genericRefactoring.transport = transport.transport
104+
proposal.name = methodName
105+
const preview = await client.extractMethodPreview(proposal)
106+
await client.extractMethodExecute(preview)
107+
FsProvider.get().notifyChanges([{ type: FileChangeType.Changed, uri }])
108+
}
109+
110+
}
90111
@command(AbapFsCommands.showDocumentation)
91112
private static async showAbapDoc() {
92113
return showAbapDoc()

client/src/commands/registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const AbapFsCommands = {
2020
refreshDumps: "abapfs.refreshDumps",
2121
tableContents: "abapfs.tableContents",
2222
exportToJson: "abapfs.exportToJson",
23+
extractMethod: "abapfs.extractMethod",
2324
// atc
2425
atcChecks: "abapfs.atcChecks",
2526
atcIgnore: "abapfs.atcIgnore",

client/src/lib/vscodefunctions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ export const lineRange = (line: number) => new Range(
169169
vscPosition(line, 1)
170170
)
171171

172+
export const rangeVscToApi = (r: Range): ApiRange => ({ start: { line: r.start.line + 1, column: r.start.character }, end: { line: r.end.line + 1, column: r.end.character } })
173+
172174
export const splitAdtUri = (uri: string | UriParts): AdtUriParts => {
173175
if (isString(uri)) {
174176
const { start, end, ...rest } = splitAdtUriInternal(uri)

client/src/views/traces/convertProfile.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TraceHitList, TraceRun, TraceStatementResponse } from "abap-adt-api/build/api/tracetypes"
22
import { Profile, ProfileNode } from "v8-inspect-profiler"
3+
import { log } from "../../lib"
34
// import { splitAdtUri } from "../../lib"
45

56
const objectLink = (connId: string, uri: string, id: number) => `command:abapfs.showObject?${encodeURIComponent(JSON.stringify({ connId, uri }))}`
@@ -36,11 +37,11 @@ export const convertStatements = (run: TraceRun, resp: TraceStatementResponse, c
3637
const maxnodeId = nodes[nodes.length - 1]?.id || 0
3738
const samples = [1, ...nodes.map(n => n.id < maxnodeId ? n.id + 1 : n.id)]
3839
const timeDeltas = [0, ...resp.statements.map(n => n.traceEventNetTime.time)]
39-
// const samples = nodes.map(n => n.id)
40+
// const samples = nodes.map(n => n.id)
4041
// const timeDeltas = resp.statements.map(n => n.traceEventNetTime.time)
4142
const selfTime = total(timeDeltas)
4243
const endTime = startTime + selfTime
43-
for (const n of nodes) if (n.children?.find(c => c < n.id)) console.log("boo")
44+
for (const n of nodes) if (n.children?.find(c => c < n.id)) log(`Unexpected child ID in profile`)
4445
return { startTime, endTime, nodes, samples, timeDeltas }
4546
}
4647

modules/abapObject/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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": "^6.1.0"
23+
"abap-adt-api": "^6.2.0"
2424
}
2525
}

modules/abapfs/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)