Skip to content

Commit d5cd65c

Browse files
committed
some bugfix new commands and prepare to close
1 parent 7512d8b commit d5cd65c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+338
-137
lines changed

client/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.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
"electron": "11.2.3",
5555
"electron-builder": "22.10.5"
5656
}
57-
}
57+
}

client/src/__tests__/spoken-interface.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/* PLAYGROUND REGION - THIS REGION OF THE FILE WILL
2-
BE ALTERED BY THE THIS TEST.
31

42

53

64

7-
*/
5+
6+
87

98
import Spoken, { SpokenCommand } from 'spoken'
109
import { IpcMainEvent } from 'electron'
@@ -34,7 +33,7 @@ async function Main() {
3433
await conditionTest()
3534
await repetitionTest()
3635
await newFunctionTest()
37-
} catch(err) {
36+
} catch (err) {
3837
console.log(err.toString())
3938
} finally {
4039
EditorService.stop()
@@ -82,7 +81,7 @@ async function conditionTest() {
8281
await execute('new line')
8382
}
8483

85-
async function executeFunctionTest() {
84+
async function executeFunctionTest() {
8685
await wait(1000)
8786
await execute('go to line 4')
8887
await execute('execute a função bola da string hello string com 3 argumentos', 'pt-BR')

client/src/editors/vscode/index.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ async function main() {
1010

1111
const info = await Editor.fileInfo()
1212

13-
await Editor.write('hello doc')
14-
await Editor.indentSelection()
13+
await Editor.remove(4)
1514

1615
// await Editor.writeOnTerminal('node "' + info.fileName + '"')
1716
// await Editor.newLine(1)

client/src/editors/vscode/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ class VSCodeEditor extends Editor {
190190
})
191191
}
192192

193+
remove(selection: number | [[number, number], [number, number]]) {
194+
console.log('[client.VSCodeRobot.getLine]: Sending request to execute remove(...)')
195+
196+
return this.runTask({
197+
type: 'remove',
198+
context: {},
199+
extra: { args: [selection] }
200+
})
201+
}
202+
193203
indentSelection(p1: [string, string], p2: [string, string]): Promise<void | Error> {
194204
console.log('[client.VSCodeRobot.indentSelection]: Sending request to execute indentSelection(...)')
195205
const task = {
-460 Bytes
Binary file not shown.
-494 Bytes
Binary file not shown.

spoken-vscode-driver/src/extension.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,7 @@ export function activate(context: vscode.ExtensionContext) {
88
Log('Spoken VSCode driver is ready!')
99

1010
let disposable = vscode.commands.registerCommand('spoken.helloWorld', async () => {
11-
vscode.window.showInformationMessage('Hello World from VSCode Spoken!')
12-
13-
// editor.selection = new vscode.Selection(14, 0, 14, 52)
14-
// vscode.commands.executeCommand('editor.action.reindentselectedlines', {})
15-
16-
// vscode.commands.executeCommand('editor.action.insertLineBefore', {})
17-
/*const destLine = 55
18-
19-
const line = (editor?.selection?.active?.line || 0) + 1
20-
const to = destLine > line ? 'down' : 'up'
21-
const value = to === 'down' ? destLine - line : line - destLine
22-
23-
vscode.commands.executeCommand('cursorMove', { to, value, by: 'line' }).then(() => {
24-
vscode.commands.executeCommand('revealLine', { lineNumber: destLine, at: 'center' }).then(() => {
25-
vscode.commands.executeCommand('cursorMove', { to: 'wrappedLineFirstNonWhitespaceCharacter' })
26-
})
27-
})*/
28-
29-
// vscode.commands.executeCommand('cursorMove', { to, value, by: 'line' })
30-
31-
/*vscode.commands.executeCommand('cursorMove', {
32-
to: 'viewPortTop',
33-
by: 'line',
34-
value: 3
35-
})*/
36-
// vscode.commands.executeCommand('revealLine', { lineNumber: 2 })
37-
// let a = await vscode.commands.getCommands()
38-
// Log(a)
39-
// const editor = vscode.window.activeTextEditor
40-
41-
// editor?.edit((editBuilder) => {
42-
// editBuilder.insert(editor.selection.active, 'hello42')
43-
// })\
11+
vscode.window.showInformationMessage('Hello World from VSCode!')
4412
})
4513

4614
context.subscriptions.push(disposable)

spoken-vscode-driver/src/index.d.ts

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,87 @@ export type TaskRequest = {
1212
}
1313

1414
export interface Robot {
15+
/**
16+
* Writes something in the current text input (editor).
17+
*
18+
* @param text The text to be written
19+
*/
1520
write(text: string): Promise<void | Error>
16-
removeSelection(): Promise<string | Error>
17-
newLine(pos: 0 | 1): Promise<void | Error>
18-
removeLine(): Promise<string | Error>
19-
selectLines(from: number | undefined, to: number | undefined): Promise<string | Error>
20-
goToLine(number: string): Promise<string | Error>
21-
hotKey(...keys: string[]): Promise<void | Error>
21+
22+
/**
23+
* Creates a new line above or below the current line.
24+
*
25+
* @returns undefined if evrything went well, error otherwise
26+
*/
27+
newLine(pos: 0 | 1): Promise<void | Error>
28+
29+
/**
30+
* Moves the cursor to a different line.
31+
*
32+
* @param number Line number
33+
* @param string Line position (END, BEGIN)
34+
*/
35+
goToLine(number: string, cursorPosition: 'END' | 'BEGIN'): Promise<string | Error>
36+
37+
/**
38+
* Finds the position of a given token in the current line.
39+
*
40+
* @param to {string} Where the cursor should move to
41+
* @param symbol {string} If `to` is SYMBOL, which symbol are we looking for
42+
* @param leapSize {number} How many matches should be skiped
43+
*/
44+
moveCursorTo(
45+
to: 'END_LINE' | 'BEGIN_LINE' | 'SYMBOL' | null,
46+
symbol: string | undefined,
47+
leapSize: number | undefined
48+
): Promise<void | Error>
49+
50+
/**
51+
* Finds the range of a term in a given line
52+
*
53+
* @param term {RegExp | string} What we are looking for
54+
* @param line {number} Which line to look for
55+
*/
56+
findPositionOf(term: RegExp | string, line?: number, pad?: number): Promise<number[][] | Error>
57+
58+
/**
59+
* Selects a piece of text in the editor.
60+
*
61+
* @param from Where to start the selection
62+
* @param to Where to stop the selection
63+
* @param line If its a line selection or a word selection
64+
* @returns The text selection
65+
*/
66+
select(from: number, to: number, line: boolean): Promise<string | Error>
67+
68+
/**
69+
* Retrieves the content of the provided line.
70+
*
71+
* @param number | undefined line number
72+
*/
73+
getLine(number?: number): Promise<{ lineNumber: number, text: string, _text: string, _line: number, character: number } | Error>
74+
75+
/**
76+
* Indents the provided selection or the whole file if no selection is provided.
77+
*
78+
* @param p1 Start string[] (line, cursor)
79+
* @param p2 Finish string[] (line, cursor)
80+
*/
81+
indentSelection(p1?: [string, string], p2?: [string, string]): Promise<void | Error>
82+
83+
/**
84+
* Writes something in the terminal and press enter.
85+
*
86+
* @param text Text to be written in the terminal
87+
* @returns void
88+
*/
89+
writeOnTerminal(text: string): Promise<void | Error>
90+
91+
/**
92+
* Retrieves information about a file
93+
*
94+
* @param text Which file we are looking for information about, if undefined current file.
95+
* @returns
96+
*/
97+
fileInfo(text?: string): Promise<Record<string, any> | Error>
2298
}

spoken-vscode-driver/src/robot-vscode.ts

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as vscode from './vscode'
22
import { Robot } from './index'
33
import Log from './logger'
44

5-
// @TODO: Replace everything 'robot' for editor
65
class RobotVscode implements Robot {
76

87
private getEditor(): [vscode.TextEditor | null, Error | null] {
@@ -33,12 +32,23 @@ class RobotVscode implements Robot {
3332
})
3433
})
3534

36-
removeSelection(): Promise<string | Error> {
37-
throw new Error('Method not implemented.')
38-
}
35+
/**
36+
* Removes the provided selection/line
37+
*
38+
* @param The line to be removed
39+
*/
40+
remove = (selection: number | [[number, number], [number, number]]) => new Promise<void | Error>((res, rej) => {
41+
Log('[vscode-driver.robot-vscode.write]: Executing remove(' + selection + ')')
42+
43+
const [editor, e] = this.getEditor()
44+
45+
if (editor == null) return rej(e)
46+
47+
vscode.commands.executeCommand('editor.action.deleteLines').then(() => res())
48+
})
3949

4050
/**
41-
* Creates a new line above the current line.
51+
* Creates a new line above or below the current line.
4252
*
4353
* @returns undefined if evrything went well, error otherwise
4454
*/
@@ -61,17 +71,11 @@ class RobotVscode implements Robot {
6171
})
6272
})
6373

64-
removeLine(): Promise<string | Error> {
65-
throw new Error('Method not implemented.')
66-
}
67-
68-
selectLines(from: number | undefined, to: number | undefined): Promise<string | Error> {
69-
throw new Error('Method not implemented.')
70-
}
71-
7274
/**
7375
* Moves the cursor to a different line
76+
*
7477
* @param number Line number
78+
* @param string Line position (END, BEGIN)
7579
*/
7680
goToLine = (
7781
number: string,
@@ -95,25 +99,21 @@ class RobotVscode implements Robot {
9599

96100
vscode.commands.executeCommand('cursorMove', { to, value, by: 'line' }).then(() => {
97101
vscode.commands.executeCommand('revealLine', { lineNumber: destLine, at: 'center' }).then(() => {
98-
// const t = `wrappedLine${cursorPosition === 'BEGIN' ? 'First' : 'Last'}NonWhitespaceCharacter`
99102
const text = editor.document.lineAt(destLine - 1).text
103+
104+
if (cursorPosition === 'END') {
105+
return vscode.commands.executeCommand('cursorMove', { to: 'wrappedLineEnd'}).then(() => res(text))
106+
}
107+
100108
const index = text.length - text.trimLeft().length
109+
101110
vscode.commands.executeCommand('cursorMove', { to: 'wrappedLineStart'}).then(() => {
102-
if (index <= 0) {
103-
res(text)
104-
} else {
105-
vscode.commands.executeCommand('cursorMove', { to: 'right', value: index, by: 'character' }).then(() => {
106-
res(text)
107-
})
108-
}
111+
if (index <= 0) return res(text)
112+
113+
vscode.commands.executeCommand('cursorMove', { to: 'right', value: index, by: 'character' }).then(() => res(text))
109114
})
110115
})
111116
})
112-
113-
// const { range, text } = editor.document.lineAt(parseInt(number) - 1)
114-
// editor.selection = new vscode.Selection(range.start, range.end)
115-
116-
// editor.revealRange(range)
117117
} catch(err) {
118118
rej(err)
119119
}
@@ -262,10 +262,6 @@ class RobotVscode implements Robot {
262262
}
263263
})
264264

265-
hotKey(...keys: string[]): Promise<void | Error> {
266-
throw new Error('Method not implemented.')
267-
}
268-
269265
/**
270266
* Retrieves the content of the provided line
271267
*
@@ -278,7 +274,7 @@ class RobotVscode implements Robot {
278274

279275
if (editor == null) throw e
280276

281-
number = number != null ? number : editor.selection.active.line + 1
277+
number = number != null ? number : editor.selection.active.line
282278

283279
const d = editor.document.lineAt(number)
284280
return {

0 commit comments

Comments
 (0)