Skip to content

Commit

Permalink
Verbose configuration (#202)
Browse files Browse the repository at this point in the history
* Adding verbose config

* Testing verbosed commands

* 📝 Update contributors list

---------

Co-authored-by: Publishing Bot <[email protected]>
  • Loading branch information
PalumboN and actions-user authored Jan 16, 2025
1 parent 844d043 commit f868711
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- DO NOT REMOVE - contributor_list:data:start:["ivojawer", "fdodino", "PalumboN", "npasserini", "Miranda-03", "dependabot[bot]", "FerRomMu"]:end -->
<!-- DO NOT REMOVE - contributor_list:data:start:["ivojawer", "fdodino", "PalumboN", "npasserini", "dependabot[bot]", "Miranda-03", "FerRomMu"]:end -->


# Wollok IDE
Expand Down Expand Up @@ -40,6 +40,6 @@ Do you want to contribute? Great, you are always welcome!
<!-- DO NOT REMOVE - contributor_list:start -->
## 👥 Contributors

<img src="https://avatars.githubusercontent.com/u/18614957?v=4" height="40" width="40" alt="ivojawer" title="ivojawer" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4549002?v=4" height="40" width="40" alt="fdodino" title="fdodino" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4098184?v=4" height="40" width="40" alt="PalumboN" title="PalumboN" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4633913?v=4" height="40" width="40" alt="npasserini" title="npasserini" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/72475370?v=4" height="40" width="40" alt="Miranda-03" title="Miranda-03" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/in/29110?v=4" height="40" width="40" alt="dependabot[bot]" title="dependabot[bot]" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/70177008?v=4" height="40" width="40" alt="FerRomMu" title="FerRomMu" class="avatar circle"/>&nbsp;
<img src="https://avatars.githubusercontent.com/u/18614957?v=4" height="40" width="40" alt="ivojawer" title="ivojawer" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4549002?v=4" height="40" width="40" alt="fdodino" title="fdodino" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4098184?v=4" height="40" width="40" alt="PalumboN" title="PalumboN" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4633913?v=4" height="40" width="40" alt="npasserini" title="npasserini" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/in/29110?v=4" height="40" width="40" alt="dependabot[bot]" title="dependabot[bot]" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/72475370?v=4" height="40" width="40" alt="Miranda-03" title="Miranda-03" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/70177008?v=4" height="40" width="40" alt="FerRomMu" title="FerRomMu" class="avatar circle"/>&nbsp;
<!-- DO NOT REMOVE - contributor_list:end -->
<!-- prettier-ignore-end -->
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@
"description": "Maximum threshold in milliseconds: if an operation takes longer, it will be saved in the log file.",
"order": 40
},
"wollokLSP.verbose": {
"scope": "resource",
"type": "boolean",
"default": false,
"description": "Launch CLI commands using --verbose option.",
"order": 41
},
"wollokLSP.typeSystem.enabled": {
"scope": "resource",
"type": "boolean",
Expand Down
12 changes: 7 additions & 5 deletions packages/client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const subscribeWollokCommands = (context: ExtensionContext): void => {
* CLI Commands
*/

export const runProgram = (isGame = false) => ([fqn]: [string]): Task => {
export const runProgram = (isGame = false) => (fqn: string): Task => {
const wollokLSPConfiguration = workspace.getConfiguration(wollokLSPExtensionCode)
const portNumber = wollokLSPConfiguration.get('gamePortNumber') as number ?? DEFAULT_GAME_PORT

Expand All @@ -52,7 +52,7 @@ export const runProgram = (isGame = false) => ([fqn]: [string]): Task => {
])
}

export const runTest = ([filter, file, describe, test]: [string|null, string|null, string|null, string|null]): Task =>
export const runTest = ([filter, file, describe, test]: [string | null, string | null, string | null, string | null]): Task =>
wollokCLITask('run tests', `Wollok ${getLSPMessage(COMMAND_RUN_TEST)}`, [
'test',
...filter ? [asShellString(filter)] : [],
Expand All @@ -76,7 +76,7 @@ export const initProject = (): Task =>
const getCurrentFileName = (document: vscode.TextDocument | undefined) =>
document ? path.basename(document.uri.path) : 'Synthetic File'

const getFiles = (document: vscode.TextDocument | undefined): [ReturnType<typeof fsToShell>] | [] =>
const getFiles = (document: vscode.TextDocument | undefined): [ReturnType<typeof fsToShell>] | [] =>
document ? [fsToShell(document.uri.fsPath)] : []

export const startRepl = (): Task => {
Expand All @@ -88,7 +88,7 @@ export const startRepl = (): Task => {
const portNumber = wollokLSPConfiguration.get('replPortNumber') as number ?? DEFAULT_REPL_PORT
const DYNAMIC_DIAGRAM_URI = `http://localhost:${portNumber}/`

const cliCommands = [`repl`, ...getFiles(currentDocument), '--skipValidations', '--port', portNumber.toString(), dynamicDiagramDarkMode ? '--darkMode' : '', openDynamicDiagram ? '': '--skipDiagram']
const cliCommands = [`repl`, ...getFiles(currentDocument), '--skipValidations', '--port', portNumber.toString(), dynamicDiagramDarkMode ? '--darkMode' : '', openDynamicDiagram ? '' : '--skipDiagram']
// Terminate previous tasks
vscode.commands.executeCommand('workbench.action.terminal.killAll')
const replTask = wollokCLITask('repl', `Wollok Repl: ${getCurrentFileName(currentDocument)}`, cliCommands)
Expand Down Expand Up @@ -120,15 +120,17 @@ const registerCLICommand = (

const wollokCLITask = (task: string, name: string, cliCommands: Array<string | vscode.ShellQuotedString>) => {
const wollokLSPConfiguration = workspace.getConfiguration(wollokLSPExtensionCode)
const wollokCliPath: string = wollokLSPConfiguration.get('cli-path')
const wollokCliPath = wollokLSPConfiguration.get<string>('cli-path')
if (!wollokCliPath) {
vscode.commands.executeCommand('workbench.action.openSettings', wollokLSPExtensionCode)
throw new Error(getLSPMessage('missingWollokCliPath'))
}

const verbose = wollokLSPConfiguration.get<boolean>('verbose')
const folder = workspace.workspaceFolders[0]
const shellCommandArgs: Array<string | vscode.ShellQuotedString> = [
...cliCommands,
...verbose ? ['--verbose'] : [],
'-p',
fsToShell(folder.uri.fsPath),
]
Expand Down
85 changes: 50 additions & 35 deletions packages/client/src/test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ suite('Should run commands', () => {
sinon.restore()
})

test('run program', () => {
return testCommand(
test('run program', () =>
testCommand(
pepitaURI,
() => runProgram()(['file.program']),
() => runProgram()('file.program'),
[
'run',
quoted('file.program'),
Expand All @@ -40,12 +40,12 @@ suite('Should run commands', () => {
quoted(folderURI.fsPath),
],
)
})
)

test('run game', () => {
return testCommand(
test('run game', () =>
testCommand(
pepitaURI,
() => runProgram(true)(['file.program']),
() => runProgram(true)('file.program'),
[
'run',
'-g',
Expand All @@ -57,11 +57,10 @@ suite('Should run commands', () => {
quoted(folderURI.fsPath),
],
)
})
)

test('runs tests', () => {

const testArgs: [string, string, string, string] = [null, 'tests.wtest', 'tests de pepita', 'something']
const testArgs: [null, string, string, string] = [null, 'tests.wtest', 'tests de pepita', 'something']

return testCommand(
pepitaURI,
Expand All @@ -76,13 +75,13 @@ suite('Should run commands', () => {
quoted('something'),
'--skipValidations',
'-p',
{ quoting: ShellQuoting.Strong, value:folderURI.fsPath },
quoted(folderURI.fsPath),
],
)
})

test('run all tests', () => {
return testCommand(
test('run all tests', () =>
testCommand(
pepitaURI,
runAllTests,
[
Expand All @@ -92,28 +91,28 @@ suite('Should run commands', () => {
quoted(folderURI.fsPath),
],
)
})
)

test('repl on current file', () => {
return testCommand(
pepitaURI,
startRepl,
[
'repl',
quoted(pepitaURI.fsPath),
'--skipValidations',
'--port',
DEFAULT_REPL_PORT.toString(),
'--darkMode',
'', // do not open dynamic diagram
'-p',
quoted(folderURI.fsPath),
],
)
})
test('repl on current file', () =>
testCommand(
pepitaURI,
startRepl,
[
'repl',
quoted(pepitaURI.fsPath),
'--skipValidations',
'--port',
DEFAULT_REPL_PORT.toString(),
'--darkMode',
'', // do not open dynamic diagram
'-p',
quoted(folderURI.fsPath),
],
)
)

test('create a new project in the workspace directory', () => {
return testCommand(
test('create a new project in the workspace directory', () =>
testCommand(
pepitaURI,
initProject,
[
Expand All @@ -122,6 +121,22 @@ suite('Should run commands', () => {
quoted(folderURI.fsPath),
],
)
)

test('run verbose', () => {
configuration['verbose'] = true
return testCommand(
pepitaURI,
() => runProgram()('file.program'),
[
'run',
quoted('file.program'),
'--skipValidations',
'--verbose',
'-p',
quoted(folderURI.fsPath),
],
)
})
})

Expand All @@ -134,15 +149,15 @@ async function testCommand(
const task = command()
const execution = task.execution as ShellExecution
assert.equal(execution.args.length, expectedArgs.length, `Execution should have ${expectedArgs.length} arguments, but has ${execution.args.length}`)
for(let i = 0; i < execution.args.length; i++){
for (let i = 0; i < execution.args.length; i++) {
assertCommandSegmentMatches(execution.args[i], expectedArgs[i])
}
}


function assertCommandSegmentMatches(actual: string | ShellQuotedString, expected: string | ShellQuotedString) {
assert.equal(typeof actual, typeof expected)
if(typeof actual === 'string'){
if (typeof actual === 'string') {
assert.equal(actual, expected)
} else {
assert.equal(actual.value, (expected as ShellQuotedString).value)
Expand Down

0 comments on commit f868711

Please sign in to comment.